Choose the grain of a transformation
Parse nested values, expand arrays and retain one ranked row per business key.
Choose the grain of a transformation
Work through the decision
An order contains two line items in a JSON array. Analysts want the latest order per customer and later a total per department. Which operations change the number of rows?
Check your reasoning
Read nested data from VARIANT paths, then use FLATTEN if one row per element is required. A grouped aggregate reduces rows to the grouping grain. A window function computes across a partition while retaining rows until a filter such as QUALIFY selects the desired ones.
Compare the choices
- FLATTEN
- Expand an array or object into rows and preserve a link to the parent record.
- VARIANT path expression
- Read a nested value from semi-structured data, then cast it to the required type for calculation.
- Grouped aggregate
- Produce a result at the grouping grain, such as one row per department and month.
- Window function with QUALIFY
- Compute rank or another window value and filter the result while retaining row-level columns.
- Staged file reference
- Represent unstructured files with governed staged locations or file references and handle their contents using suitable processing.
Test the decision
For customer C9 with orders at 09:00 and 11:00, rank by timestamp descending with order ID as a deterministic tie breaker. Keep the first ranked row. Expanding the items before ranking instead changes the grain and can select a single line when the requirement was the entire order.
Practice the guide skills
- Choose typed columns for consistent records and VARIANT path access or FLATTEN for nested values. Watch 2:50:43
- Represent an unstructured file with a governed path and decide which file metadata to query. Watch 2:54:16
- Aggregate sales at a declared reporting grain and verify output counts. Watch 2:57:17
- Rank rows within each business key with a deterministic tie breaker and keep the desired row. Watch 2:58:36
- Reduce scanned data and validate join keys while checking that output totals remain correct. Watch 3:00:39
Official objectives for this lesson
Related lesson · Rank rows within each team
Choose the grain of a transformation quiz
Answer 3 questions. Check each answer for an explanation.