如何使用 yaml 选择器? 上下文Jaffle Shop 示例具体案例

问题描述

我正在尝试使用 yaml 选择器,但没有成功。我的选择器.yml:

selectors:
  - name: daily
    description: selects models for daily run
    deFinition:
      exclude:
        - union:
            - "tag:pp_backfill"
            - "tag:inc_transactions_raw_data"
            - "tag:hourly"

当我尝试使用它时出现错误

$ dbt ls --selector daily
* Deprecation Warning: dbt v0.17.0 introduces a new config format for the
dbt_project.yml file. Support for the existing version 1 format will be removed
in a future release of dbt. The following packages are currently configured with
config version 1:
 - honey_dbt
 - dbt_utils
 - audit_helper
 - codegen

For upgrading instructions,consult the documentation:
  https://docs.getdbt.com/docs/guides/migration-guide/upgrading-to-0-17-0

* Deprecation Warning: The "adapter_macro" macro has been deprecated. Instead,use the `adapter.dispatch` method to find a macro and call the result.
adapter_macro was called for: dbt_utils.intersect
Encountered an error:
Runtime Error
  Could not find selector named daily,expected one of []

我在 0.18.1 和 0.19.0 中都尝试过,有和没有 config-version: 2。有什么想法吗?

解决方法

我认为这里的障碍可能是您目前没有选择任何内容,然后从使用标记方法中排除特定模型。这是我项目中的解决方案,然后采用可能适用于您的情况。

上下文

我在 dbt Cloud 上运行 dbt 版本 0.19.0。这两个编译并成功运行dbt run --selector daily

Jaffle Shop 示例

stg_customers 被标记为 dont_run_mestg_orders 被标记为 also_dont_run_me

selector.yml 是 dbt 项目根目录下的内容

selectors:
  - name: daily
    description: selects models for daily run
    definition:
      union:
        - method: path
          value: models
        - exclude:
            - method: tag
              value: dont_run_me
            - method: tag
              value: also_dont_run_me

这里的逻辑是我首先选择所有模型,然后排除具有标签 dont_run_mealso_dont_run_me 的模型的联合。

dbt run --selector daily 最终运行了我项目中的所有内容 stg_customersstg_orders

具体案例

如果您尝试选择除标记为 pp_backfillinc_transactions_raw_datahourly 的模型之外的所有模型,我认为以下方法可以解决问题:

selectors:
  - name: daily
    description: selects models for daily run
    definition:
      union: 
        - method: path
          value: models
        - exclude:
            - union:
               - method: tag
                 value: pp_backfill
               - method: tag
                 value: inc_transactions_raw_data
               - method: tag
                 value: hourly