Skip to main content
PYSPARK โ€ข LESSON 195

Fact Table Enrichment with Broadcast Lookups

How do we enrich transaction facts by broadcasting product and store dimensions without incurring cluster shuffles?

Productionโฑ 3 Minutesโญ 1700 XP
๐Ÿค” THE QUESTION

How do we enrich transaction facts by broadcasting product and store dimensions without incurring cluster shuffles?

๐Ÿ’ก WHAT IS IT?

Joining fact transactions with broadcast product and store tables to compute line item revenue in a single pass.

๐ŸŽฏ WHAT IS IT USED FOR?

High-throughput sales enrichment in enterprise dimensional data warehouses.

๐Ÿ’ป EXAMPLE
from pyspark.sql.functions import broadcast, col

enriched_sales = fact_sales \
    .join(broadcast(dim_products), "product_id", "inner") \
    .join(broadcast(dim_stores), "store_id", "left") \
    .select(
        fact_sales.transaction_id,
        fact_sales.transaction_date,
        dim_products.product_name,
        dim_products.category,
        dim_stores.region,
        fact_sales.quantity,
        (fact_sales.quantity * dim_products.unit_price).alias("revenue")
    )

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Fact Table Enrichment with Broadcast Lookups.

  • โœ“ Broadcast product and store dimensions
  • โœ“ Calculate line-item revenue projection
  • โœ“ Produce enriched sales dataset without shuffle