Scenario G: Applying CDC changes with versioned upserts¶
Part of Streaming Transformations › Scenarios.
Goal¶
Apply captured order changes for a single market.
Transformations used¶
- Versioned upserts: apply captured changes, that is
INSERT,UPDATEand softDELETE, where aDELETErow supersedes earlier versions and is filtered out at query time. - Stream filtering: ingest only records of a particular market.
Source data¶
Records are streamed in as follows, intentionally out of order:
Note
The records above show only the first changes for orders 9000–9002. Keep streaming order changes after these records rather than stopping. Background merge passes depend on ongoing ingestion, so LAST_DEDUP reaches the “After merge” state only while the stream continues. LATEST_DEDUP returns the current state of orders 9001 and 9002 right away.
Target table¶
The PIPE lands filtered orders in the Interactive target table:
Transformation¶
The PIPE filters the records by market.
Result¶
Before merge¶
Directly after ingestion and before the first merge the following results are returned.
LAST_DEDUP
No result. LAST_DEDUP shows the latest version only after a merge pass.
LATEST_ALL
| ORDER_ID | ITEM_COUNT | MARKET | STATUS | RECORD_VERSION |
|---|---|---|---|---|
| 9001 | 0 | de | INSERT | 1 |
| 9001 | 1 | de | UPDATE | 2 |
| 9001 | 2 | de | UPDATE | 3 |
| 9002 | 0 | de | INSERT | 1 |
| 9002 | 3 | de | UPDATE | 2 |
Note
The order of results shown is not guaranteed because the example query has no ORDER BY.
LATEST_DEDUP
| ORDER_ID | ITEM_COUNT | MARKET | STATUS | RECORD_VERSION |
|---|---|---|---|---|
| 9002 | 3 | de | UPDATE | 2 |
After merge¶
After a merge all three queries, that is LAST_DEDUP, LATEST_ALL and LATEST_DEDUP, return the same result, as long as no additional rows have been ingested since the last merge pass.
| ORDER_ID | ITEM_COUNT | MARKET | STATUS | RECORD_VERSION |
|---|---|---|---|---|
| 9002 | 3 | de | UPDATE | 2 |
Soft-deletes¶
Versioned upserts don’t physically delete rows. A delete arrives as a new row version with status = 'DELETE', and it supersedes earlier versions like any other change. Each query therefore filters out DELETE rows with WHERE status <> 'DELETE'. This is why order 9001, whose highest version is the DELETE, doesn’t appear in the deduplicated results.
Considerations¶
- Standard Snowflake tables and managed Iceberg tables are not currently supported.
- A table with versioned upserts can’t be the source of an insert-triggered materialized view, a dynamic table, or a table stream.
- Merge passes run as ingestion continues. If streaming stops, the most recent commits might stay invisible to
LAST_DEDUP; useLATEST_DEDUPto read them.
See also¶
See Versioned upserts and Stream filtering for more information on the transformations used in this scenario.
Previous: Scenario F: Privacy-safe ingestion · Next: Monitoring & Troubleshooting