AnishMahto opened a new pull request, #56456:
URL: https://github.com/apache/spark/pull/56456

   Approved AutoCDC SPIP: 
https://lists.apache.org/thread/j6sj9wo9odgdpgzlxtvhoy7szs0jplf7
   
   ------------
   
   This is a stacked PR. Review incremental diff here: 
https://github.com/AnishMahto/spark/compare/SPARK-57322-reconcile-start-end-at...SPARK-57356-cleanup-delete-encoded-rows-post-reconciliation
   
   ### What changes were proposed in this pull request?
   **Preamble:**
   
   The SCD type 2 flow is a foreachBatch streaming query on an input 
change-data-feed, and is responsible for reconciling the incoming change data 
onto some target table that follows SCD2 replication semantics.
   
   SCD2 flows also maintain an "auxiliary" table to keep track of 
early-arriving out-of-order received events state. Each microbatch will need to 
reconcile against this auxiliary table as well, and update the auxiliary 
table's state appropriately for future microbatches.
   
   **Cleanup Delete Encoding Rows Post-Reconciliation:**
   
   Reconciliation itself (re)assigns the start/end-ats of upsert representing 
columns in the microbatch-affected row set, using the next neighbor event 
(could be either another upsert that ends this upsert, or a delete event that 
ends this upsert).
   
   Once a delete event matches with an preceding row and reconciliation updates 
that row's end-at accordingly, that upsert row (now closed) fully encodes the 
delete event along with its upsert event. This means the delete event does not 
need to have its own row, and the tombstone/decomposition tail can be dropped. 
If a delete event does not match against a preceding upsert however, then it is 
necessary to bookkeep as a tombstone in the aux table.
   
   It is also possible that post-reconciliation, a decomposition tail survives 
as a non-redundant delete encoding event. This decomposition tail should be 
promoted to a tombstone and persisted in the aux to reconcile against future 
microbatches.
   
   As a trivial example image an existing closed upsert valid for start/end at 
[T=10, T=20) gets bisected by a delete event at T=15. Then the closed upsert 
gets decomposed into head and tail at [T=10, null) and (null, T=20], 
reconciliation creates a new closed upsert at [T=10, T=15), and the 
decomposition tail (null, T=20] should be promoted to a tombstone at instant 
T=20.
   
   ### Why are the changes needed?
   SD2 core algorithm implementation.
   
   
   ### Does this PR introduce _any_ user-facing change?
   No, SCD2 is an unreleased feature.
   
   
   ### How was this patch tested?
   Unit tested in `Scd2BatchProcessorSuite`
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Co-authored with Claude Opus 4.7
   


-- 
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