By Rohit Ray · Independent educational lesson · Explore this visual lab

Module 13 · Lesson 7 of 11Detailed study · about 22 min

Create the customer-history lab

Separate delivery evidence, accepted events, dimension versions and run metadata so each processing decision can be explained.

Understand the idea

C1 starts in Pune on January 1 and moves to Mumbai on March 1. C2 starts in Delhi. We deliberately deliver E2 twice. Later a February move will arrive late and must split C1’s history without changing the later March boundary.

Key ideas in simple English
ConceptWhat it means
INPUT_EVENTSImmutable closed-batch deliveries for this exercise.
CUSTOMER_LEDGERUnique accepted business events with stable surrogate keys.
DIM_CUSTOMEREffective-time versions derived from the ledger.
RUN_AUDITCommitted batch position and processing counts.

A concrete example

C1 starts in Pune on January 1 and moves to Mumbai on March 1. C2 starts in Delhi. We deliberately deliver E2 twice. Later a February move will arrive late and must split C1’s history without changing the later March boundary.

Remember: Identical event replay must preserve one business version and its stable surrogate key.

Explain it step by step · full theory

Understand the concept

C1 starts in Pune on January 1 and moves to Mumbai on March 1. C2 starts in Delhi. We deliberately deliver E2 twice. Later a February move will arrive late and must split C1’s history without changing the later March boundary.

Create M13_LAB in the existing L2_OBJECTS_LAB database. Use an authorized warehouse and role with database usage, schema creation, and table/sequence/procedure creation privileges. The caller-rights procedure later needs the same object access.

Apply it in practice

The sequence provides warehouse surrogate keys. CUSTOMER_LEDGER preserves those keys across reprocessing, and DIM_CUSTOMER uses them for version identity. Sequence values need not be contiguous, including after rollback; never use them as a business count.

Run setup once. Keep this small lab single-writer: no parallel procedure calls or edits to INPUT_EVENTS during processing. Source records here always represent real attribute changes; unchanged repeated observations and deletion events require additional business rules outside this narrowly defined city-history contract.

Words used in this lesson
INPUT_EVENTS
Immutable closed-batch deliveries for this exercise.
CUSTOMER_LEDGER
Unique accepted business events with stable surrogate keys.
DIM_CUSTOMER
Effective-time versions derived from the ledger.
RUN_AUDIT
Committed batch position and processing counts.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 2

Create the customer-history lab

INPUT_EVENTS
CUSTOMER_LEDGER
RUN_AUDIT

Understand the flow

Separate delivery evidence, accepted events, dimension versions and run metadata so each processing decision can be explained.

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
  1. Understand the flow

    Separate delivery evidence, accepted events, dimension versions and run metadata so each processing decision can be explained.

  2. Apply the contract

    Identical event replay must preserve one business version and its stable surrogate key.

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.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. 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.
  3. 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.
  4. 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.

Create the customer-history lab — SQL example

Definition: Separate delivery evidence, accepted events, dimension versions and run metadata so each processing decision can be explained.

When to use: Follow the isolated customer-history lab in lesson order.

Example: 4 deliveries. Ledger, dimension and audit are empty; watermark is 0.

SQL · example
USE DATABASE L2_OBJECTS_LAB;
CREATE SCHEMA M13_LAB;
USE SCHEMA M13_LAB;
CREATE SEQUENCE CUSTOMER_SK_SEQ;
CREATE TABLE INPUT_EVENTS(DELIVERY_ID NUMBER,EVENT_ID VARCHAR,CUSTOMER_ID VARCHAR,CITY VARCHAR,EFFECTIVE_AT TIMESTAMP_NTZ);
CREATE TABLE CUSTOMER_LEDGER(EVENT_ID VARCHAR,CUSTOMER_ID VARCHAR,CITY VARCHAR,EFFECTIVE_AT TIMESTAMP_NTZ,CUSTOMER_SK NUMBER);
CREATE TABLE DIM_CUSTOMER(CUSTOMER_SK NUMBER,CUSTOMER_ID VARCHAR,CITY VARCHAR,VALID_FROM TIMESTAMP_NTZ,VALID_TO TIMESTAMP_NTZ,IS_CURRENT BOOLEAN);
CREATE TABLE PIPELINE_STATE(LAST_DELIVERY NUMBER);
INSERT INTO PIPELINE_STATE VALUES(0);
CREATE TABLE BATCH_EVENTS LIKE INPUT_EVENTS;
CREATE TABLE RUN_AUDIT(BATCH_END NUMBER,DELIVERIES NUMBER,COMMITTED_AT TIMESTAMP_LTZ);
CREATE TABLE REJECT_LOG(FAILED_AT TIMESTAMP_LTZ,ERROR_MESSAGE VARCHAR);
INSERT INTO INPUT_EVENTS VALUES
 (1,'E1','C1','Pune','2026-01-01'),
 (2,'E2','C1','Mumbai','2026-03-01'),
 (3,'E2','C1','Mumbai','2026-03-01'),
 (4,'E3','C2','Delhi','2026-01-01');
SELECT COUNT(*) AS DELIVERIES FROM INPUT_EVENTS;

What to expect and why

4 deliveries. Ledger, dimension and audit are empty; watermark is 0.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Should the duplicate E2 delivery create another dimension version?

Try it yourself

Explain with the example: Should the duplicate E2 delivery create another dimension version?

Compare your reasoning

Identical event replay must preserve one business version and its stable surrogate key.

Official sources and curriculum

Module 13 · See module scope