0
0
Snowflakecloud~20 mins

FLATTEN for nested data in Snowflake - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FLATTEN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding FLATTEN output structure

Given a Snowflake table orders with a column items containing a VARIANT array of objects, what will be the output of this query?

SELECT order_id, f.value AS item FROM orders, LATERAL FLATTEN(input => items) f;
AA table with columns order_id and item, where each item is a single element from the items array expanded into its own row.
BA table with columns order_id and item, where item contains the entire items array as a single JSON string.
CA table with columns order_id and item, where item contains only the first element of the items array repeated for all rows.
DA table with columns order_id and item, but item is NULL for all rows.
Attempts:
2 left
💡 Hint

Think about what FLATTEN does to arrays in Snowflake.

🧠 Conceptual
intermediate
1:30remaining
Behavior of FLATTEN with empty arrays

What happens when you use FLATTEN on a VARIANT column containing an empty array?

SELECT f.value FROM my_table, LATERAL FLATTEN(input => variant_col) f;
AThe query returns one row with an empty array as value.
BThe query returns one row with value NULL.
CThe query returns zero rows because there are no elements to flatten.
DThe query returns an error because the array is empty.
Attempts:
2 left
💡 Hint

Consider how flattening an empty list behaves in general.

Configuration
advanced
2:00remaining
Using FLATTEN with OUTER = TRUE

Consider this query:

SELECT id, f.value FROM my_table, LATERAL FLATTEN(input => nested_col, outer => true) f;

What is the effect of setting outer => true in FLATTEN?

AIt returns rows for all elements in the array, and also returns a row with NULL value if the array is empty or NULL.
BIt filters out NULL values inside the array and returns only non-null elements.
CIt causes FLATTEN to return only the first element of the array.
DIt causes an error if the array is NULL.
Attempts:
2 left
💡 Hint

Think about how to preserve rows when the nested array is empty or missing.

security
advanced
2:30remaining
Security implications of FLATTEN on sensitive nested data

You have a VARIANT column storing nested JSON with sensitive user data. What is a best practice when using FLATTEN to query this data?

AUse FLATTEN without restrictions since it only changes data shape, not data visibility.
BFlatten the data first, then apply masking in the SELECT clause.
CExport the flattened data to an external system without encryption for faster processing.
DApply column-level masking or restrict access before flattening to avoid exposing sensitive data.
Attempts:
2 left
💡 Hint

Think about when data masking should be applied in the query process.

Architecture
expert
3:00remaining
Optimizing performance when using FLATTEN on large nested datasets

You have a large Snowflake table with deeply nested JSON arrays. Which approach best improves query performance when using FLATTEN?

AUse FLATTEN with outer => true to ensure all rows are returned, improving performance.
BUse lateral flatten with a filter predicate on the nested array before flattening to reduce data scanned.
CAvoid using FLATTEN and instead extract nested data using multiple SELECT statements.
DFlatten the entire nested array without filters and then apply WHERE conditions on the flattened results.
Attempts:
2 left
💡 Hint

Filtering early reduces the amount of data processed.