How do you model nested and repeated data in BigQuery, and when do you UNNEST vs normalize into separate tables?

Quick Overview

Asks how to model nested and repeated data in BigQuery with STRUCT and ARRAY columns, and when to flatten with UNNEST or move child records into their own tables. Tests schema trade-offs, scan cost, update patterns and the common pitfalls of unnesting.

How do you model nested and repeated data in BigQuery, and when do you UNNEST vs normalize into separate tables?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you model nested and repeated data in BigQuery, and when do you `UNNEST` vs normalize into separate tables? ```hint Follow the child records Look at how the child records are read, how often they change on their own, and whether more than one parent refers to them. ``` ### What a Strong Answer Covers - How `STRUCT`, `ARRAY` and arrays of structs represent nested and one-to-many data - What `UNNEST` does to the row count, and how to keep parents whose arrays are empty - The join and scan-cost trade-off of keeping data nested - The conditions that favor separate, normalized tables ### Follow-up Questions - After unnesting line items, an analyst sums the order-level shipping fee and gets a number that is too high. Why, and how do you fix the query? - How would you change the quantity of one line item in a nested orders table, and what does that cost? - Product names change over time. Would you nest product attributes inside each order or join a product table, and does the answer depend on the reports?

Overview: Asks how to model nested and repeated data in BigQuery with STRUCT and ARRAY columns, and when to flatten with UNNEST or move child records into their own tables. Tests schema trade-offs, scan cost, update patterns and the common pitfalls of unnesting.

PracHub logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you model nested and repeated data in BigQuery, and when do you UNNEST vs normalize into separate tables?

What a Strong Answer Covers Guidance

  • How STRUCT , ARRAY and arrays of structs represent nested and one-to-many data
  • What UNNEST does to the row count, and how to keep parents whose arrays are empty
  • The join and scan-cost trade-off of keeping data nested
  • The conditions that favor separate, normalized tables

Follow-up Questions Guidance

  • After unnesting line items, an analyst sums the order-level shipping fee and gets a number that is too high. Why, and how do you fix the query?
  • How would you change the quantity of one line item in a nested orders table, and what does that cost?
  • Product names change over time. Would you nest product attributes inside each order or join a product table, and does the answer depend on the reports?