UNNEST: Flattening Arrays to Rows

Concepts covered: sqlJsonExtract

Three design questions this lesson covers First: schema-on-read vs schema-on-write. Schema-on-read keeps the JSON in the bronze layer and extracts at query time; schema-on-write flattens to typed columns at ingestion. Each has a cost and a use case. Second: evolution handling. When the source schema changes, the pipeline either adapts automatically (schema-on-read absorbs the change) or breaks loudly (schema-on-write fails CI and forces a coordinated migration). Third: nested aggregation. Sometimes UNNEST is wrong; ARRAY_AGG, ARRAY_LENGTH, and per-array predicates without flattening are the right tool when the array structure is part of the query, not just data to aggregate.

About This Interactive Section

This section is part of the Semi-Structured Data: Intermediate lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.

How DataDriven Lessons Work

DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.