Bird
0
0

What happens if you use a dictionary comprehension in dbt Jinja to create a JSON object with duplicate keys from a list of key-value pairs?

hard🧠 Conceptual Q10 of 15
dbt - Advanced Patterns
What happens if you use a dictionary comprehension in dbt Jinja to create a JSON object with duplicate keys from a list of key-value pairs?
AOnly the first value for each key is kept
BAn error is raised due to duplicate keys
CAll values for duplicate keys are stored as a list
DThe last value for each duplicate key overwrites previous ones
Step-by-Step Solution
Solution:
  1. Step 1: Understand dictionary behavior in Python/Jinja

    When duplicate keys exist, the last assignment overwrites earlier ones.
  2. Step 2: Apply to dbt Jinja dictionary comprehension

    Creating JSON objects with duplicate keys results in last value winning, no error or list aggregation.
  3. Final Answer:

    The last value for each duplicate key overwrites previous ones -> Option D
  4. Quick Check:

    Duplicate keys overwrite previous values in dicts [OK]
Quick Trick: Duplicate keys in dicts overwrite earlier values [OK]
Common Mistakes:
MISTAKES
  • Expecting error on duplicates
  • Thinking duplicates become lists
  • Assuming first value is kept

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes