dbt docs block 简单说明

dbt docs block 是一个jinja2 bblock 的扩展,以下是一个简单的说明

参考使用

  • 定义
{% docs table_events %}
 
This table contains clickstream events from the marketing website.
 
The events in this table are recorded by Snowplow and piped into the warehouse on an hourly basis. The following pages of the marketing site are tracked:
 - /
 - /about
 - /team
 - /contact-us
 
{% enddocs %}
  • 使用

通过类似ref 模式引用

version: 2
models:
  - name: events
    description: '{{ doc("table_events") }}'
    columns:
      - name: event_id
        description: This is a unique identifier for the event
        tests:
            - unique
            - not_null

参考处理

  • DocumentationExtension 扩展

处理上与MaterializationExtension 类似

class DocumentationExtension(jinja2.ext.Extension):
    tags = ["docs"]
 
    def parse(self, parser):
        node = jinja2.nodes.Macro(lineno=next(parser.stream).lineno)
        docs_name = parser.parse_assign_target(name_only=True).name
 
        node.args = []
        node.defaults = []
        node.name = get_docs_macro_name(docs_name)
        node.body = parser.parse_statements(("name:enddocs",), drop_needle=True)
        return node
  • get_docs_macro_name

工具类进行docs macro 的前缀

def get_dbt_docs_name(name):
    if name is None:
        raise dbt.exceptions.DbtInternalError("Got None for a doc name!")
    # 前缀 dbt_docs__
    return f"{DOCS_PREFIX}{name}"

说明

dbt docs block 的处理实际上就是一个标准jinja2 block 扩展,只是方便使用

参考资料

https://docs.getdbt.com/docs/collaborate/documentation
https://docs.getdbt.com/reference/project-configs/docs-paths
https://docs.getdbt.com/reference/dbt-jinja-functions/doc

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

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-04-21 kconfig-hardened-check linux 内核安全选项检查工具
2023-04-21 osboxes 方便的主机镜像服务
2020-04-21 earthly 使用中碰到的一些问题说明
2020-04-21 查看docker的manifest
2020-04-21 earthly特性说明
2020-04-21 earthly 简单试用
2020-04-21 buildkit 并发高效缓存Dockerfile 无关的构建器工具包

导航

< 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
点击右上角即可分享
微信分享提示