What you will be able to do
- Choose AUTO CDC FROM SNAPSHOT when a source can only provide full snapshots
- Predict how successive snapshots become inserts, updates and deletes in the target
- Combine one snapshot flow with AUTO CDC flows on a single SCD Type 1 target, within its requirements
1.When the source only gives you snapshots
Many source systems can't emit a change feed. A nightly full export of a vendor's product table or a JDBC dump of a legacy database tells you the current state of every row, not what changed. AUTO CDC FROM SNAPSHOT is built for this. It finds the changes by comparing in-order snapshots and then applies them to a streaming table, a Delta table with extra support for streaming or incremental data processing. The target stores the result as SCD Type 1 or Type 2. Type 1 updates records directly and keeps no history for updated records; Type 2 keeps a history of records, either on all updates or on a chosen set of columns. A plain AUTO CDC flow produces the same SCD results when the source database has a CDC feed enabled, and reads that feed instead of comparing snapshots. Snapshots can come from a Delta table, cloud storage files, or JDBC directly.
You define it as a flow into a streaming table, in either language. In SQL, use the AUTO CDC ... FROM SNAPSHOT form of CREATE FLOW, or the embedded FLOW AUTO CDC clause of CREATE STREAMING TABLE. It takes a required FROM SNAPSHOT (snapshot_query) and an optional WITH VERSION (version_query) that picks the next snapshot version to process. In Python, create_auto_cdc_from_snapshot_flow() takes a source that is either the name of a table or view to snapshot periodically, or a lambda that returns the next snapshot DataFrame together with its version. Use the lambda when snapshots are stored as separate files or dated tables and you need to process them in order.
from pyspark import pipelines as dp
dp.create_auto_cdc_from_snapshot_flow(
target = "<target-table>",
source = Any,
keys = ["key1", "key2", "keyN"],
stored_as_scd_type = "1",
track_history_column_list = None,
track_history_except_column_list = None,
once = False
)Checkpoint 1 of 3· Check yourself
A legacy database has no CDC. Each night a JDBC job dumps the full current contents of its customers table. You need an SCD Type 2 customer table in a Lakeflow pipeline that records what changed between dumps. Which approach fits?
A full dump gives the current state, not a change feed. AUTO CDC FROM SNAPSHOT compares in-order snapshots to find what changed, then applies the changes as SCD Type 1 or Type 2. TRUNCATE works only with SCD Type 1 and clears the whole table. A plain streaming table only appends rows.
“AUTO CDC FROM SNAPSHOT: Use this when CDC is not enabled on the source database and only snapshots are available.”Source: docs.databricks.com
2.How successive snapshots become changes
Each snapshot is compared with the target by key, and that comparison takes the place of the clauses a feed-driven flow needs. A key that isn't in the target yet is inserted. A key that is there is updated only if at least one value in the row changed, so an unchanged row produces no write and no new SCD Type 2 version. A key that has disappeared is deleted. You don't write SEQUENCE BY or APPLY AS DELETE WHEN, because the snapshot version supplies the order and absence signals a delete. The flip side is that a snapshot which accidentally leaves rows out deletes those rows from the target.
Set once = True (or ONCE in SQL) to load a snapshot a single time, for example a backfill. After that load commits, incremental updates skip the flow, and only a full refresh of the target runs it again.
Checkpoint 2 of 3· Check yourself
Your team runs an AUTO CDC FROM SNAPSHOT flow over a nightly vendor export. They want an alert when an unusually large number of products drop out of a snapshot and get deleted. How should they approach this?
num_upserted_rows and num_deleted_rows are reported only by AUTO CDC queries, not by AUTO CDC FROM SNAPSHOT queries. Monitoring for a snapshot flow can't depend on them. A snapshot flow has no APPLY AS DELETE WHEN clause, and the SCD type doesn't change which metrics are reported.
“The following metrics are captured only by AUTO CDC queries and not by AUTO CDC FROM SNAPSHOT queries.”Source: docs.databricks.com
3.Combining a snapshot flow with AUTO CDC flows
Some sources send both kinds of data: a periodic authoritative snapshot and a lower-latency change feed between snapshots. An SCD Type 1 target can take one AUTO CDC FROM SNAPSHOT flow and one or more AUTO CDC flows. Ordering is what makes the mix coherent. Every change event in the feed carries a sequencing column, named in the AUTO CDC flow's SEQUENCE BY, that gives the event's logical order and lets the pipeline handle events that arrive out of order. Every snapshot carries a version. The snapshot version and the CDC sequencing column form one ordering domain, so the pipeline compares a snapshot's version directly against the sequencing values of change events.
A CDC event newer than the latest snapshot takes precedence over that snapshot. A newer snapshot takes precedence over older CDC events and treats keys it doesn't contain as deleted at the snapshot version. A later CDC event can still restore such a key.
Yes. The snapshot deletes customer 7 at version 100, but the CDC event at 105 is newer, so it takes precedence and restores the key.
A unified target fails to validate unless all of the following hold:
- The target is SCD Type 1. SCD Type 2 and bitemporal targets are not supported.
- There is exactly one snapshot flow, and every AUTO CDC flow has a unique name.
- All flows use the same number of keys in the same order. Snapshot key names are matched case-insensitively, but multiple AUTO CDC flows must use identical names and casing.
- The snapshot version and each sequencing column have exactly the same data type.
- The snapshot flow defines no expectations, and the AUTO CDC flows don't use IGNORE NULL UPDATES or its column-list variants.
- The pipeline runs in triggered mode.
A common setup is a ONCE snapshot flow that backfills history while the AUTO CDC flows keep processing new events. A full refresh runs the one-time snapshot again. If you add an AUTO CDC flow to an existing snapshot target, the target must not have user columns whose names clash with reserved AUTO CDC system columns. SQL and Python flows can share the same target.
Checkpoint 3 of 3· Check yourself
A source system sends a change feed, and the team also has a full historical snapshot it wants to load once as a backfill into the same target. Which design passes validation for a unified snapshot-plus-CDC target?
Sharing a target between a snapshot flow and AUTO CDC flows works only for SCD Type 1, in triggered mode, with exactly one snapshot flow and a snapshot version of the same data type as the sequencing column. SCD Type 2 targets, continuous pipelines and a second snapshot flow all fail validation.
“For SCD Type 1 targets in triggered pipelines, one or more create_auto_cdc_flow() flows can share a target with one AUTO CDC FROM SNAPSHOT flow”Source: docs.databricks.com
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/ldp/cdcOfficial docs
“Use this when CDC is not enabled on the source database and only snapshots are available.”
↩︎ When the source only gives you snapshots“AUTO CDC FROM SNAPSHOT determines changes in source data by comparing in-order snapshots.”
↩︎ When the source only gives you snapshots“You can read snapshots from a Delta table, cloud storage files, or JDBC directly.”
↩︎ When the source only gives you snapshots“The source is a required FROM SNAPSHOT (snapshot_query) clause and an optional WITH VERSION (version_query) clause that selects the next snapshot version to process.”
↩︎ When the source only gives you snapshots“Use SCD Type 1 to update records directly. History is not retained for updated records.”
↩︎ When the source only gives you snapshots“Use SCD Type 2 to retain a history of records, either on all updates or on updates to a specified set of columns.”
↩︎ When the source only gives you snapshots“Use this pattern when a source provides periodic authoritative snapshots and a lower-latency CDC feed between snapshots.”
↩︎ Combining a snapshot flow with AUTO CDC flows“The snapshot version and the CDC sequencing column form one ordering domain.”
↩︎ Combining a snapshot flow with AUTO CDC flows“A newer snapshot takes precedence over older CDC events and treats keys that are absent from the snapshot as deleted at the snapshot version.”
↩︎ Combining a snapshot flow with AUTO CDC flows“The pipeline uses triggered mode.”
↩︎ Combining a snapshot flow with AUTO CDC flows“A full refresh of the target re-runs the one-time snapshot flow.”
↩︎ Combining a snapshot flow with AUTO CDC flows“This pattern does not support SCD Type 2 or bitemporal targets.”
↩︎ Exam trap 1“AUTO CDC FROM SNAPSHOT: Use this when CDC is not enabled on the source database and only snapshots are available.”
↩︎ Checkpoint - 2.https://docs.databricks.com/aws/en/ldp/developer/ldp-python-ref-apply-changes-from-snapshotOfficial docs
“a Python lambda function that returns the snapshot DataFrame to be processed and the snapshot version”
↩︎ When the source only gives you snapshots“If a matching record does exist, it is updated only if any of the values in the row have changed.”
↩︎ How successive snapshots become changes“Rows with keys present in the target but no longer present in the source are deleted.”
↩︎ How successive snapshots become changes“When True, the flow is skipped during subsequent incremental updates after it commits successfully.”
↩︎ How successive snapshots become changes - 3.https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-streaming-tableOfficial docs
“Creates a streaming table, a Delta table with extra support for streaming or incremental data processing.”
↩︎ When the source only gives you snapshots - 4.https://docs.databricks.com/aws/en/ldp/cdc-advancedOfficial docs
“The following metrics are captured only by AUTO CDC queries and not by AUTO CDC FROM SNAPSHOT queries.”
↩︎ How successive snapshots become changes - 5.
“The column name specifying the logical order of CDC events in the source data.”
↩︎ Combining a snapshot flow with AUTO CDC flows
Also cited
“For SCD Type 1 targets in triggered pipelines, one or more create_auto_cdc_flow() flows can share a target with one AUTO CDC FROM SNAPSHOT flow”
↩︎ Checkpoint