suhuruli commented on code in PR #57149:
URL: https://github.com/apache/spark/pull/57149#discussion_r3755382152


##########
docs/declarative-pipelines-programming-guide.md:
##########
@@ -517,6 +517,360 @@ AS INSERT INTO customers_us
 SELECT * FROM STREAM(customers_us_east);
 ```
 
+## Change Data Capture (CDC) with Auto CDC
+
+Many source systems emit a stream of *change events* rather than a snapshot of 
the current data: each record describes an insert, update, or delete to a row, 
identified by a key. Applying these events correctly to a target table by hand 
is tricky. You have to match events to existing rows, apply them in the right 
order, and handle out-of-order and duplicate events without corrupting the 
table.
+
+**Auto CDC** does this for you. You point it at a source of change events and 
tell it how to identify and order them, and SDP maintains a target streaming 
table that always reflects the latest state for each key.
+
+### Keys and sequencing
+
+Auto CDC needs two things from you to make sense of a change feed:
+
+- The **keys** are the columns that identify a row across events. Events 
sharing a key describe the same logical row over time. In a customer feed, that 
is usually the customer id.
+- The **sequencing expression** says what order the events for a key happened 
in. Its value for an event is that event's **sequence value**, and Auto CDC 
treats the highest sequence value it has seen for a key as the most recent 
state. Change feeds normally carry something suitable already: a monotonically 
increasing version or commit number, or a commit timestamp.
+
+Sequence values matter because a change feed does not have to arrive in order. 
Sequencing is what lets Auto CDC recognize that an event it just received is 
older than what it already applied, and place it correctly, rather than letting 
arrival order corrupt the table.
+
+### What Auto CDC does
+
+Given a stream of change events, Auto CDC keeps the target table in sync with 
the source:
+
+- **Inserts and updates** - For each key, the event with the highest sequence 
value wins. If no row exists for the key, it's inserted; if one exists, it's 
overwritten with the latest values.
+- **Deletes** - Events that match a delete condition you supply remove the 
corresponding row from the target.
+- **Out-of-order and duplicate events** - Events don't have to arrive in 
order, and you don't need to de-duplicate the source. An event whose sequence 
value is older than the state already applied for its key is discarded, and a 
re-delivered event converges to the same result.
+
+This behavior implements **Slowly Changing Dimensions (SCD) Type 1**: the 
target keeps only the current version of each row, with no history of prior 
values. SCD Type 1 is the only mode currently supported.

Review Comment:
   Updated per your suggestion. All three spots now scope rather than deny:
   
   - Concept: "This section covers SCD Type 1... SCD Type 2 is also supported; 
SPARK-58570 tracks documenting it."
   - `stored_as_scd_type` row: "Pass `1` for the Type 1 behavior described 
here. Type 2 is also accepted; see SPARK-58570."
   - `STORED AS SCD TYPE 1`: "use `1` for the Type 1 behavior described here."
   
   This keeps the PR scoped to Type 1 without the guide claiming Type 2 does 
not exist. Thanks for pushing on it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to