Problems / Normalize Denormalized Orders / Editorial
Denormalized data repeats entity attributes across rows. To produce a clean fact table, we derive per-entity metrics and join them back.
SELECT customer_email, COUNT(DISTINCT order_id)
SELECT product_name, ROUND(AVG(unit_price), 2)
quantity × unit_price
COUNT(DISTINCT ...) is not supported in window functions in most SQL dialects. The subquery-join approach cleanly separates aggregation from enrichment.
COUNT(DISTINCT ...)
The .select().distinct().groupBy().count() pattern emulates COUNT(DISTINCT ...) safely within the DataFrame API.
.select().distinct().groupBy().count()
Solve Normalize Denormalized Orders yourself →