如何最好地实现动态DBT数据集

发布于 2025-02-07 14:42:13 字数 315 浏览 0 评论 0 原文

我正在清理DBT + BigQuery环境,并试图实现从分期数据集中拉出的登台环境。问题是当前 .yml 带有源信息的文件都明确指向生产数据集。

我正在考虑的一个选项是 source 包装器函数,它将用作适配器并根据某些传递的CLI var 或配置文件注入适当的数据集(这对分阶段与产品环境)。

但是,我是DBT的新手,因此不确定这是否是最好的方法。您会很感激您善良的人都有的任何见解::)

编辑:我意识到 source 包装器不是要走的方法,因为它会弄乱生成的dag

I'm cleaning up a dbt + BigQuery environment and trying to implement a staging environment that pulls from a staging dataset. Problem is that the current .yml files with source information all explicitly point to a production dataset.

One option that I am considering is a source wrapper function that will serve as an adapter and inject the proper dataset depending on some passed CLI var or profile target (which is different for the staging vs prod environments).

However, I'm fairly new to dbt so unsure if this is the best way to go about this. Would appreciate any insight you kind folks have :)

EDIT: I'm realizing that a source wrapper is not the way to go as it would mess with the generated DAG

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2025-02-14 14:42:13

您可以在a 环境变量,并在运行时设置该变量。

在您的 sources.yml 中:

version: 2

sources:
  - name: jaffle_shop
    schema: "{{ var('source_jaffle_shop_schema) }}"
    tables:
      - name: orders

在您的 dbt_project.yml 中:

vars:
  - source_jaffle_shop_schema: MY_DEFAULT_SCHEMA

然后在运行时覆盖:

dbt run --vars "{source_jaffle_shop_schema: my_other_schema}"

You can supply the name of the schema for a source in a variable or environment variable, and set that variable at runtime.

In your sources.yml:

version: 2

sources:
  - name: jaffle_shop
    schema: "{{ var('source_jaffle_shop_schema) }}"
    tables:
      - name: orders

In your dbt_project.yml:

vars:
  - source_jaffle_shop_schema: MY_DEFAULT_SCHEMA

And then to override at runtime:

dbt run --vars "{source_jaffle_shop_schema: my_other_schema}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文