Solve two tricky modeling puzzles cleanly: grouping scattered boolean flags into Junk Dimensions, and modeling many-to-many relationships (e.g., user hobbies or multiple promo tags) with Bridge Tables + allocation weights.
In real data tables, beginners frequently hit two awkward puzzles that normal dimensions don't solve:
1. Puzzle 1 — 15 Tiny Checkbox Columns (`is_vip`, `likes_rock`, `likes_jazz`, `paperless_bill`, `email_opt_in`):
If you keep all 15 boolean flags straight on a 500M-row fact_sales table, your huge Fact gets bloated—yet creating 15 separate tiny 2-row Dimension tables forces 15 ugly joins!
Solution — Junk Dimension: Combine low-cardinality flags into 1 compact table holding all valid combinations (flag_sk = 1..N). Like wiring 15 loose wall switches into one tidy breaker panel!
2. Puzzle 2 — Many-to-Many Tags (1 User Has 3 Favorite Genres; 1 Song Has 2 Artists):
What if Alice likes *both* Rock AND Jazz, and spends $100 on concert tickets? If you join fact_sales straight to a user_interests table with 2 rows for Alice, `$100` becomes `$200` (Fan-Out Bug!).
Solution — Bridge Table: Put an explicit Bridge Table (bridge_user_interest) between User Group and Interest, paired with an optional Weighting Factor (`0.50` / `0.50`) so allocated totals still sum cleanly to $100.00!
| Pattern | Problem Solved | Cardinality | Key Columns |
|---|---|---|---|
| SCD Type 2 | Tracking how 1 attribute changes over time (e.g. moved cities). | 1-to-Many across time | surrogate_sk, effective_from, effective_to, is_current |
| Junk Dimension | Grouping stray boolean/enum flags off the Fact table. | Small finite combinations (2 x 2 x 3 = 12 rows) | junk_sk, is_mobile, payment_method, is_gift |
| Bridge Table | Connecting a Fact/Dimension to 0, 1, or N values simultaneously (skills, genres, diagnosis codes). | Many-to-Many | group_sk, category_sk, weighting_factor |
Suppose fact_orders originally carried 3 small flags: is_gift (Y/N), channel (WEB/APP), priority (STD/EXP). Only 2 x 2 x 2 = 8 total combinations can ever exist!
Instead of 3 columns per billion rows, create `dim_order_flags`:
| flags_sk | is_gift | channel | priority |
|---|---|---|---|
| 1 | false | WEB | STD |
| 2 | false | APP | STD |
| 3 | true | APP | EXP |
| ... | ... | ... | ... |
In SQL, generate your Junk Dimension deterministically using DISTINCT or CROSS JOIN + hash surrogate key:
CREATE OR REPLACE TABLE gold.dim_order_flags AS
SELECT
MD5(CONCAT_WS('|', is_gift, channel, priority)) AS flags_sk,
is_gift,
channel,
priority
FROM silver.raw_orders
GROUP BY is_gift, channel, priority;Now fact_orders stores just 1 tidy Foreign Key (`flags_sk`) instead of repeating wide strings 500 million times!
Suppose Alice bought `$100` in tickets (user_id = 101), and she follows Rock and Jazz (2 interests -> weighting_factor = 0.50 each):
| user_group_sk | interest_name | weighting_factor |
|---|---|---|
| GRP-101 | Rock | 0.50 |
| GRP-101 | Jazz | 0.50 |
| GRP-202 | Sports | 1.00 |
Watch how weighting factors let BI analysts slice by genre AND guarantee totals reconcile to `$100.00`:
SELECT
b.interest_name,
SUM(f.price_paid) AS unallocated_impact_usd,
SUM(f.price_paid * b.weighting_factor) AS allocated_revenue_usd
FROM gold.fact_sales f
JOIN gold.bridge_user_interest b
ON f.buyer_interest_group_sk = b.user_group_sk
GROUP BY b.interest_name;Output:
- Rock: unallocated_impact = $100, allocated_revenue = $50
- Jazz: unallocated_impact = $100, allocated_revenue = $50
- Grand Total of `allocated_revenue` = `$50 + $50 = $100.00` (Zero Inflation!)
Both metrics are super valuable—just label clearly whether a KPI measures "Total Reach / Impact" (unweighted) vs. "Reconciled Revenue Share" (weighted)!
0.90 or 1.20, financial totals drift! Add a pipeline quality test: GROUP BY user_group_sk HAVING ABS(SUM(weighting_factor) - 1.0) > 0.001.customer_zip_code (40,000 values) into a Junk Dimension with 5 booleans (40,000 x 32 = 1.28M rows)! Only group truly low-cardinality flags (< 20–100 combinations).0 listed interests drop completely unless you map them to an "Unspecified / None" group with weight = 1.0 or use LEFT JOIN.Many-to-Many traits (interests, tags, co-authors) cleanly.Test your understanding of the concepts covered in this lesson.
When a ticket seller moves to a new city, their commission rate and state change. If we overwrite their record, historical sales reports will misattribute past sales to the new location. We must apply an SCD Type 2 MERGE in Delta Lake to close out the old record and insert a new active record.