dbt model 对象简单说明

dbt model 属于graph 对象,实际上就是一个node 节点,包含了当前模型的一些信息

主要场景

  • 访问config 设置
  • 访问模型的路径

参考使用

  • 查看模型内容
    可以通过log macro
{{ log(model, info=True) }}

内部实现

实际上就是context 属性信息

@contextproperty("model")
def ctx_model(self) -> Dict[str, Any]:
    model_dct = self.model.to_dict(omit_none=True)
    # Maintain direct use of compiled_sql
    # TODO add depreciation logic[CT-934]
    if "compiled_code" in model_dct:
        model_dct["compiled_sql"] = model_dct["compiled_code"]
 
    if (
        hasattr(self.model, "contract")
        and self.model.contract.alias_types is True
        and "columns" in model_dct
    ):
        for column in model_dct["columns"].values():
            if "data_type" in column:
                orig_data_type = column["data_type"]
                # translate data_type to value in Column.TYPE_LABELS
                new_data_type = self.adapter.Column.translate_type(orig_data_type)
                column["data_type"] = new_data_type
    return model_dct

说明

再一些场景中我们可能需要访问model 的一些信息,比如物化处理上,获取配置信息的,了解一些功能还是很有用的

参考资料

core/dbt/context/providers.py
https://docs.getdbt.com/reference/dbt-jinja-functions/model
https://docs.getdbt.com/docs/build/incremental-models
https://schemas.getdbt.com/dbt/manifest/v11/index.html#tab-pane_nodes_additionalProperties_anyOf_i3

posted on   荣锋亮  阅读(20)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-05-17 nginx ngx_http_realip 的功能以及使用
2020-05-17 promcat.io 由sysdig 托管的企业级prometheus监控网站
2020-05-17 c 语言使用lttng
2020-05-17 lttng简单试用
2020-05-17 dotnetcore 性能分析一些文章
2019-05-17 edgedb-js 来自官方的js 驱动
2019-05-17 edgedb 开发环境运行

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示