Bird
0
0

How do you correctly define a macro called calculate_total in dbt?

easy📝 Syntax Q3 of 15
dbt - Jinja in dbt
How do you correctly define a macro called calculate_total in dbt?
Adef calculate_total(): SELECT SUM(amount) FROM sales
Bmacro calculate_total() { SELECT SUM(amount) FROM sales }
C{% macro calculate_total() %} SELECT SUM(amount) FROM sales {% endmacro %}
D<macro name="calculate_total"> SELECT SUM(amount) FROM sales </macro>
Step-by-Step Solution
Solution:
  1. Step 1: Identify dbt macro syntax

    dbt macros are defined using Jinja templating with {% macro macro_name() %} ... {% endmacro %} tags.
  2. Step 2: Check each option

    {% macro calculate_total() %} SELECT SUM(amount) FROM sales {% endmacro %} uses correct Jinja syntax for macros. Options B, C, and D use invalid syntax not supported by dbt.
  3. Final Answer:

    {% macro calculate_total() %} SELECT SUM(amount) FROM sales {% endmacro %} -> Option C
  4. Quick Check:

    Correct Jinja macro syntax uses {% macro %} and {% endmacro %} tags [OK]
Quick Trick: Use {% macro name() %} ... {% endmacro %} for macros [OK]
Common Mistakes:
MISTAKES
  • Using Python or other language syntax instead of Jinja
  • Omitting the {% endmacro %} tag
  • Using angle brackets or other XML-like tags

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes