dbt docs block 的一些技巧

dbt 的docs 实际上自定义上还是很强大的,可以灵活的docs block 解析,同时docs 定义也可以类似model 那样进行引用,当然也包含了一些内部固定模式可以灵活的进行文档的自定义

一些内置自定义玩法

  • 自定义文档路径
    类似dbt 其他资源一样docs 也是支持自定义的,否则默认会搜索model-paths, seed-paths, analysis-paths, macro-paths 以及 snapshot-paths
    配置(dbt_project.yml)
docs-paths: [directorypath]
  • overview
    可以用来定义website 的信息
    参考
{% docs __overview__ %}
# Monthly Recurring Revenue (MRR) playbook.
This dbt project is a worked example to demonstrate how to model subscription
revenue. **Check out the full write-up [here](https://blog.getdbt.com/modeling-subscription-revenue/),
as well as the repo for this project [here](https://github.com/dbt-labs/mrr-playbook/).**
...
{% enddocs %}
  • 项目级别的自定义
    参考格式__[project_name]__ 可以方便的自定义项目的描述信息
{% docs __dremio_demo_app__ %}
 
##  this is my pacakge demo
 
### contains 
 
- mymodel-v2
- mymodel-v3
 
{% enddocs %}
  • 类似模型的引用
    定义
{% 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 %}
  • 引用
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

说明

dbt 在分析工程上的实践好多地方还是值得学习的,docs 部分的设计就比较强大,对于数据系统的设计上很值得学习参考下

参考资料

https://docs.getdbt.com/docs/collaborate/documentation
https://docs.getdbt.com/reference/resource-properties/description#include-an-image-from-your-repo-in-your-descriptions
https://docs.getdbt.com/docs/collaborate/documentation
https://docs.getdbt.com/reference/dbt-jinja-functions/doc

posted on 2024-04-20 08:00  荣锋亮  阅读(10)  评论(0编辑  收藏  举报

导航