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;
Think about what FLATTEN does to arrays in Snowflake.
The FLATTEN function expands each element of the nested array into its own row, so each item appears separately with the corresponding order_id.
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;
Consider how flattening an empty list behaves in general.
FLATTEN produces no rows when the input array is empty, so the query returns zero rows.
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?
Think about how to preserve rows when the nested array is empty or missing.
Setting outer => true makes FLATTEN return a row with NULL value when the input is empty or NULL, preserving the original row.
You have a VARIANT column storing nested JSON with sensitive user data. What is a best practice when using FLATTEN to query this data?
Think about when data masking should be applied in the query process.
Masking or access control should be applied before flattening to prevent sensitive data exposure during query processing.
You have a large Snowflake table with deeply nested JSON arrays. Which approach best improves query performance when using FLATTEN?
Filtering early reduces the amount of data processed.
Applying filters inside the FLATTEN input expression reduces the data volume processed, improving performance.