Final lab: join sales to the correct historical city
A temporal dimension join chooses the version valid at the fact’s event time. Its correctness is measured by both matching rows and preserved business totals.
Understand the idea
A C1 sale on January 15 belongs to Pune; February 15 belongs to Nashik; exactly March 1 belongs to Mumbai. A C2 sale in April belongs to Jaipur. This is why retaining effective history matters for reports.
| Concept | What it means |
|---|---|
| Fact timestamp | When the sale happened. |
| Validity interval | Inclusive start, exclusive end. |
| Unmatched fact | Missing or too-early dimension history. |
| Reconciliation | Every fact matches exactly once and totals agree. |
A concrete example
A C1 sale on January 15 belongs to Pune; February 15 belongs to Nashik; exactly March 1 belongs to Mumbai. A C2 sale in April belongs to Jaipur. This is why retaining effective history matters for reports.
Remember: Reconcile unmatched and multiply matched facts as well as totals; a plausible aggregate can hide broken relationships.
Explain it step by step · full theory
Understand the concept
A C1 sale on January 15 belongs to Pune; February 15 belongs to Nashik; exactly March 1 belongs to Mumbai. A C2 sale in April belongs to Jaipur. This is why retaining effective history matters for reports.
Use a LEFT JOIN for the manual reconciliation so missing dimension matches remain visible. A plain INNER JOIN could silently drop a sale before the customer’s first known history. Decide whether to use an unknown-member key or quarantine such records; do not invent a historical city.
Apply it in practice
The lab resolves the version at query time. A physical fact table storing CUSTOMER_SK must re-resolve affected date ranges after late history arrives. Choose whether historical reporting restates corrections or preserves an as-known-at-the-time view; the latter needs additional system-time history beyond this Type 2 model.
Finally compare source delivery count, accepted event count, dimension versions, audit position and failure evidence. Leave the lab objects for manual inspection; no automated task was created. For production, document and implement concurrency controls, source closure guarantees, alerts, row quarantine and authorization in the actual deployment.
Words used in this lesson
- Fact timestamp
- When the sale happened.
- Validity interval
- Inclusive start, exclusive end.
- Unmatched fact
- Missing or too-early dimension history.
- Reconciliation
- Every fact matches exactly once and totals agree.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Final lab: join sales to the correct historical city
Understand the flow
A temporal dimension join chooses the version valid at the fact’s event time. Its correctness is measured by both matching rows and preserved business totals.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Understand the flow
A temporal dimension join chooses the version valid at the fact’s event time. Its correctness is measured by both matching rows and preserved business totals.
- Apply the contract
Reconcile unmatched and multiply matched facts as well as totals; a plausible aggregate can hide broken relationships.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual learning exercise. Production deployment needs source-specific contracts, access controls, orchestration and operational monitoring.
Final lab: join sales to the correct historical city — SQL example
Definition: A temporal dimension join chooses the version valid at the fact’s event time. Its correctness is measured by both matching rows and preserved business totals.
When to use: Follow the isolated customer-history lab in lesson order.
Example: Sales 1–4 map to Pune, Nashik, Mumbai, Jaipur. VERSION_MATCHES is 1 for each; amounts total 100. Final counts: 7 deliveries, 5 accepted events, 5 versions, watermark 7.
WITH sales(SALE_ID,CUSTOMER_ID,SOLD_AT,AMOUNT) AS (
SELECT 1,'C1','2026-01-15'::TIMESTAMP_NTZ,10 UNION ALL
SELECT 2,'C1','2026-02-15'::TIMESTAMP_NTZ,20 UNION ALL
SELECT 3,'C1','2026-03-01'::TIMESTAMP_NTZ,30 UNION ALL
SELECT 4,'C2','2026-04-15'::TIMESTAMP_NTZ,40
)
SELECT s.SALE_ID,s.AMOUNT,d.CITY,d.CUSTOMER_SK,
COUNT(d.CUSTOMER_SK) OVER(PARTITION BY s.SALE_ID) AS VERSION_MATCHES
FROM sales s LEFT JOIN DIM_CUSTOMER d ON s.CUSTOMER_ID=d.CUSTOMER_ID
AND s.SOLD_AT>=d.VALID_FROM AND (d.VALID_TO IS NULL OR s.SOLD_AT<d.VALID_TO)
ORDER BY s.SALE_ID;
SELECT (SELECT COUNT(*) FROM INPUT_EVENTS) AS DELIVERIES,
(SELECT COUNT(*) FROM CUSTOMER_LEDGER) AS ACCEPTED_EVENTS,
(SELECT COUNT(*) FROM DIM_CUSTOMER) AS VERSIONS,
(SELECT LAST_DELIVERY FROM PIPELINE_STATE) AS WATERMARK;What to expect and why
Sales 1–4 map to Pune, Nashik, Mumbai, Jaipur. VERSION_MATCHES is 1 for each; amounts total 100. Final counts: 7 deliveries, 5 accepted events, 5 versions, watermark 7.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain with the example: Can an INNER JOIN alone prove no sales were lost?
Compare your reasoning
Reconcile unmatched and multiply matched facts as well as totals; a plausible aggregate can hide broken relationships.