Bird
0
0

You want to create a macro that returns a comma-separated list of columns from a list input. Which code correctly implements this in dbt?

hard📝 Application Q9 of 15
dbt - Jinja in dbt
You want to create a macro that returns a comma-separated list of columns from a list input. Which code correctly implements this in dbt?
A{% macro list_columns(cols) %} {{ cols | join(", ") }} {% endmacro %}
B{% macro list_columns(cols) %} SELECT {{ cols }} {% endmacro %}
C{% macro list_columns(cols) %} {{ cols | split(",") }} {% endmacro %}
D{% macro list_columns(cols) %} {{ cols | length }} {% endmacro %}
Step-by-Step Solution
Solution:
  1. Step 1: Understand Jinja filters for lists

    The 'join' filter combines list elements into a string separated by the given delimiter.
  2. Step 2: Match macro code to desired output

    {% macro list_columns(cols) %} {{ cols | join(", ") }} {% endmacro %} uses join(", ") to create a comma-separated string from the list, which is correct.
  3. Final Answer:

    {% macro list_columns(cols) %} {{ cols | join(", ") }} {% endmacro %} -> Option A
  4. Quick Check:

    Join list elements with join filter [OK]
Quick Trick: Use {{ list | join(", ") }} to make CSV strings [OK]
Common Mistakes:
MISTAKES
  • Using split instead of join
  • Trying to select list directly
  • Using length instead of join

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes