DBT Macros & Jinja Flashcards
6 cards from real DBT practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 DBT Macros & Jinja flashcards as text
Which dbt macro is used to generate a cross-database compatible date-trunc expression?
Answer: dbt.date_trunc()
`dbt.date_trunc(datepart, date)` is a built-in cross-database macro that adapts the date_trunc SQL function for each supported adapter.
What does the `var()` function do in a dbt model?
Answer: Reads a project variable defined in dbt_project.yml or passed via --vars
`{{ var('name', default) }}` reads variables from the `vars:` section of dbt_project.yml or those overridden at runtime with `--vars`.
How do you pass a runtime variable override when running dbt?
Answer: dbt run --vars '{key: value}'
The `--vars` flag accepts a YAML dictionary string that overrides project variables for the duration of the run.
What Jinja construct lets you loop over a list and generate repeated SQL fragments in dbt?
Answer: {% for item in list %} ... {% endfor %}
`{% for item in list %}...{% endfor %}` iterates over a list and renders the body for each element, enabling dynamic SQL generation.
What is the purpose of `adapter.dispatch()` in dbt macros?
Answer: Finds the correct macro implementation for the active database adapter
`adapter.dispatch()` enables polymorphism by resolving a macro to its adapter-specific implementation (e.g., Snowflake vs BigQuery).
Which built-in dbt macro returns a surrogate key hashed from one or more column expressions?
Answer: dbt_utils.generate_surrogate_key()
`dbt_utils.generate_surrogate_key([col1, col2])` concatenates and hashes the specified columns to produce a consistent surrogate key.
How this page was made: written with AI tools. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy