【dbt】dbt ~ + prefix ~

◾️はじめに

小ネタ。

前から気になっていた dbt の「+ prefix (e.g. +materialized)」
について、メモっておく

目次

【1】+ prefix
【2】目的1:設定とリソースパスを明確するため
 1)補足:必須ではなく推奨レベル
【3】目的2:辞書型入力時
 例1: persist_docs

【1】+ prefix

https://docs.getdbt.com/reference/resource-configs/plus-prefix

# より抜粋
...

models:
  +persist_docs: # this config is a dictionary, so needs a + prefix ★ここ★
    relation: true
    ...

  jaffle_shop:
    schema: my_schema # a plus prefix is optional here
    +tags: # this is the tag config ★ここ★
      - "hello"
    tags: # whereas this is the tag resource path
      # The below config applies to models in the
      # models/tags/ directory.
      # Note: you don't _need_ a leading + here,
      # but it wouldn't hurt.
      materialized: view

目的

[1] 設定とリソースパスを明確に区別する時に使用
[2] 辞書型の入力を設定をする時に使用

【2】目的1:設定とリソースパスを明確するため

* 設定とリソースパスを明確に区別する時に使用
項目 +有無
設定 +付ける
リソースパス +付けない

https://docs.getdbt.com/reference/resource-configs/plus-prefix

models:
  jaffle_shop:
    schema: my_schema
    +tags: # 設定のため+付与
      - "hello"
    tags: # タグリソースパス(models/tags/)
      materialized: view

補足:リソースパス
https://docs.getdbt.com/reference/resource-configs/resource-path

1)補足:必須ではなく推奨レベル

https://docs.getdbt.com/reference/resource-configs/plus-prefix

より抜粋
~~~~
When adding configs in dbt_project.yml, it doesn't hurt to use the + prefix,
 so we recommend you use it always.

dbt_project.yml に設定を追加する際、+ プレフィックスを使っても問題はないため、
常に使用することをおすすめします。
~~~~

【3】目的2:辞書型入力時

* 辞書型の入力を設定をする時に使用

例1: persist_docs

models:
  +persist_docs: # 辞書型のため + prefix が必要
    relation: true
    columns: true

補足:persist_docs
https://docs.getdbt.com/reference/resource-configs/persist_docs

* モデルやシードといった各種リソースに対し、
 yamlファイルに記載したテーブルやカラムのdescriptionの内容を
 データベースに永続化する

参考文献

https://dev.classmethod.jp/articles/plus-prefix-in-dbt_project-yml/

関連記事

dbt ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2023/06/30/000000
dbt ~ 環境設定編 ~
https://dk521123.hatenablog.com/entry/2023/12/16/152147
dbt ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/05/30/151003
dbt ~ DB/Schema/Table の指定方法 ~
https://dk521123.hatenablog.com/entry/2024/09/29/185918
dbt ~ 変数 var / env_var ~
https://dk521123.hatenablog.com/entry/2025/05/03/140109
dbt ~ config ~
https://dk521123.hatenablog.com/entry/2025/05/11/024449
dbt ~ target ~
https://dk521123.hatenablog.com/entry/2025/05/10/232636
dbt CLI ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/07/21/234811