Bird
0
0

Given the following dbt SQL snippet using Snowflake syntax:

medium📝 Predict Output Q13 of 15
dbt - Advanced Patterns
Given the following dbt SQL snippet using Snowflake syntax:
SELECT
  data:id::string AS user_id,
  data:attributes:age::int AS age
FROM users

What will be the output columns for a row where data contains {"id": "U123", "attributes": {"age": 30}}?
Auser_id = 'U123', age = 30
Buser_id = 'id', age = 'attributes:age'
Cuser_id = NULL, age = NULL
Duser_id = 'U123', age = NULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand Snowflake JSON extraction

    Snowflake uses colon notation data:id to access JSON keys and casting (::string, ::int) to convert types.
  2. Step 2: Apply extraction to given JSON

    For {"id": "U123", "attributes": {"age": 30}}, data:id::string extracts 'U123', and data:attributes:age::int extracts 30.
  3. Final Answer:

    user_id = 'U123', age = 30 -> Option A
  4. Quick Check:

    Snowflake JSON path extraction = correct values [OK]
Quick Trick: Use colon paths and cast to get JSON values in Snowflake [OK]
Common Mistakes:
MISTAKES
  • Confusing JSON keys with strings
  • Not casting extracted values
  • Using wrong path syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes