■ はじめに
https://dk521123.hatenablog.com/entry/2023/05/30/151003
でも少し触れたが、DBT の ドキュメント化について 徐々にまとめていく
目次
【1】公式ドキュメント 【2】dbt docs コマンド 0)dbt docs -h 1)dbt docs generate 2)dbt docs serve 【3】サンプル 0)前提条件 1)別ファイルに分ける 【4】補足1:データリネージ機能 1)データリネージ(Data Lineage) 2)表示の仕方
【1】公式ドキュメント
https://docs.getdbt.com/docs/collaborate/documentation
https://docs.getdbt.com/reference/commands/cmd-docs
【2】dbt docs コマンド
* DBT の ドキュメント関連のコマンド
0)dbt docs -h
dbt docs -h dbt docs generate -h dbt docs serve -h
1)dbt docs generate
* ドキュメントをJSON形式で生成する
https://dev.classmethod.jp/articles/dbt-documentation/
dbt docs generate 08:59:38 Running with dbt=1.5.0 ・・・略・・・ 08:59:39 Catalog written to C:\xxxx\hello_world\users\target\catalog.json
Options
# --profiles-dir="【profiles.ymlがあるPath】" # --project-dir="【dbt_project.ymlがあるPath】" dbt docs generate --profiles-dir="./" --project-dir="./sub_dir"
2)dbt docs serve
* ドキュメントを生成する
Options
# --profiles-dir="【profiles.ymlがあるPath】" # --project-dir="【dbt_project.ymlがあるPath】" # Port 28080 を指定 dbt docs serve --profiles-dir="./" --project-dir="./sub_dir" --port 28080
構文
dbt docs serve \ [--profiles-dir PROFILES_DIR] \ [--profile PROFILE] \ [--target TARGET] \ [--port PORT] \ [--no-browser]
【3】サンプル
0)前提条件
* dbt の環境がローカル上で設定されていること => 詳細は、以下の関連記事を参照のこと
dbt ~ 環境設定編 ~
https://dk521123.hatenablog.com/entry/2023/12/16/152147
1)別ファイルに分ける
models/customers.sql
{{
config(
alias='hello',
schema='demo_schema',
database='sample_db',
materialized='table'
)
}}
select
1 as id,
'Mike' as name,
'{{ var("remark", "hello_world") }}' as remark,
now() as insert_at
models/schema.yml
version: 2 models: - name: customers # description: This table contains customer data description: '{{ doc("table_customers") }}' columns: - name: id description: This is a unique identifier for the customers - name: name quote: true description: The customer name - name: remark quote: true description: Just remark - name: insert_at quote: true description: Registration date
models/customers.md
{% docs table_customers %}
The table of customers are recorded:
- /
- /id
- /name
- /remark
- /insert_at
{% enddocs %}
ドキュメント化
dbt docs generate # Port 28080 を指定 dbt docs serve --port 28080 # ブラウザで以下をアクセスするとドキュメントが表示される
【4】補足1:データリネージ機能
* dbt のドキュメント化は、データリネージ機能を備えていて 各テーブルをグラフ化して、どのように依存しているかを表示できる
1)データリネージ(Data Lineage)とは
* データ源泉(source)から現在地点までのデータ変遷のことで データ(テーブル)がどう結びついているを把握することができる cf. Lineage(リネージ) = 血統, 系統 => 言葉より、以下のサイトの画像を見ればどういったもの把握できると思う
https://dev.classmethod.jp/articles/dbt-athena-document-data-linage/
2)表示の仕方
[1] ブラウザで dbt ドキュメントを表示(e.g. http://localhost:28080/ ) [2] メイン画面の右下に映っているアイコンをクリックする => データリネージを開くことができる => 以下のサイトの「4. ドキュメントの確認(データリネージ)」を参照
https://dev.classmethod.jp/articles/dbt-athena-document-data-linage/
参考文献
https://dev.classmethod.jp/articles/dbt-athena-document-data-linage/
https://dev.classmethod.jp/articles/dbt-documentation/
関連記事
dbt ~ 環境設定編 ~
https://dk521123.hatenablog.com/entry/2023/12/16/152147
dbt ~ 環境設定 / Docker 編 ~
https://dk521123.hatenablog.com/entry/2024/10/11/230419
dbt ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2023/06/30/000000
dbt ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/05/30/151003
dbt ~ 基本編 / Model ~
https://dk521123.hatenablog.com/entry/2023/11/25/231128
dbt ~ 基本編 / Seed ~
https://dk521123.hatenablog.com/entry/2023/11/20/230946
dbt ~ 基本編 / Source ~
https://dk521123.hatenablog.com/entry/2023/12/08/111012
dbt CLI ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/07/21/234811
dbt CLI ~ テーブル一覧表示 / dbt list ~
https://dk521123.hatenablog.com/entry/2025/04/13/222612
Snowflake ~ GET_LINEAGE ~
https://dk521123.hatenablog.com/entry/2025/11/25/181745