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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用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 无关的构建器工具包