LoginSignup
0
0

dbtの細かいところ覚え書き

Last updated at Posted at 2024-05-20

Variableの参照の優先順位ってどうなっているの?

dbtを開発していれば自然とVariableを使うと思います。
しかしこのVariable、便利なのですがdbt_project.ymlで定義したり、コマンドラインの引数として渡せたりで、もし複数の方法で定義して競合したときどうなるのでしょうか?

まあ、公式ドキュメントに書いてあると言われればその通りなのですが、初見ではどこにあるのか見つけるのに少し手間取ったのでこの備忘録を書いた次第です。

上のLinkに以下のようにあります:

The order of precedence for variable declaration is as follows (highest priority first):

  1. The variables defined on the command line with --vars.
  2. The package-scoped variable declaration in the root dbt_project.yml file
  3. The global variable declaration in the root dbt_project.yml file
  4. If this node is defined in a package: variable declarations in that package's dbt_project.yml file
  5. The variable's default argument (if one is provided)

profiles.ymlの参照の優先順位ってどうなっているの?

上のLinkに以下のようにあります:

The parent directory for profiles.yml is determined using the following precedence:

  1. --profiles-dir option
  2. DBT_PROFILES_DIR environment variable
  3. current working directory
  4. ~/.dbt/ directory

model間でref()で参照していないけれど、強制的に依存関係を定義したい

よかろう:

To address this, you can use a SQL comment along with the ref function — dbt will understand the dependency, and the compiled query will still be valid:

-- depends_on: {{ ref('upstream_parent_model') }}

{{ your_macro('variable') }}

なんとコメントでdepends_on: {{ ref('upstream_parent_model') }}と書いておけば勝手に認識してくれるみたいです、便利!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0