dbt - 如何使用 yaml 选择器?

标签 dbt

我正在尝试使用 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 商店示例

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

关于dbt - 如何使用 yaml 选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65962285/

相关文章:

dbt - 如何在代理后面运行 dbt deps?

python - 使用 pip 安装名为 "dbt"的包时遇到问题

macros - dbt_project config-version :2 中宏的使用

jinja2 - 函数中的 Jinja 变量

sql - 通过 SSH 隧道和 Jump Box 运行 DBT

path - 学习 DBT 调试 dbt_project.yml 文件 [ERROR INVALID]

databricks - 无法将 dbt 连接到 Databricks

snowflake-cloud-data-platform - 在不同的仓库中运行增量刷新而不是完全刷新

sql - 使用 dbt for-loop 在 BigQuery 中创建多个表

dbt - 嗨,我们如何将 select 语句定义为 dbt 中的变量?