Skip to content

Updates Delta CDC read to fail when schemas are different at... - #40868

Merged
chamikaramj merged 3 commits into
apache:masterfrom
chamikaramj:delta_fail_schema_change
Oct 28, 2026
Merged

chamikaramj merged 3 commits into
apache:masterfrom
chamikaramj:delta_fail_schema_change

Conversation

@chamikaramj

Copy link
Copy Markdown
Contributor

...start and end.

Only fails when schemas are actually different, trivial changes metadata only changes, that does not actually change the schema are ignored.

This fixes #40853.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR adds data-schema compatibility validation between the resolved start and end versions in Delta Lake CDC reads (DeltaIO.ReadChanges and CreateCDCReadTasksDoFn). The implementation properly distinguishes actual data and column-mapping changes from benign metadata-only updates (such as column comments), and includes thorough unit and integration tests.

🔍 General Feedback

  • The recursive comparison in DeltaIO.hasSameDataSchema and hasSameColumnMapping accurately accounts for field names, ordering, nullability, nested types (StructType, ArrayType, MapType), and Delta column mapping metadata (physicalName and id).
  • Performing the check during both pipeline expansion (DeltaIO.ReadChanges.expand) and task planning (CreateCDCReadTasksDoFn.processElement) ensures fast failure at graph construction time as well as runtime safety if the table evolves when the end boundary is open.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@ahmedabu98 ahmedabu98 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it fine to read a range where a nullable column was added? older snapshots should assign null values to missing columns

* example, column comments, column default values, or identity column high-water marks (which
* writers update whenever they insert rows into the table) may differ between the two schemas.
*/
static boolean hasSameDataSchema(DataType left, DataType right) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a separate util class for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (startSchema == null || endSchema == null) {
throw new IllegalStateException("Table schema is null.");
}
if (!DeltaIO.hasSameDataSchema(startSchema, endSchema)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for schema changes within the range? e.g. if a column was added then dropped, this comparison wouldn't catch that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also seems like this has negligible performance impact since there's no additional I/O operations needed to perform this check for the commit range.

@ahmedabu98

Copy link
Copy Markdown
Contributor

May also need to check that partition spec hasn't changed (can do in a future PR)

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @ahmedabu98 for label delta.
Backup reviewer: Abacn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (2213e54) to head (c20ada7).
⚠️ Report is 57 commits behind head on master.

Additional details and impacted files
@@       Coverage Diff       @@
##   master   #40868   +/-   ##
===============================
===============================

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added size/l L: 250-999 lines changed and removed size/m M: 50-249 lines changed labels Oct 28, 2026

@chamikaramj chamikaramj left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. PTAL.

Isn't it fine to read a range where a nullable column was added? older snapshots should assign null values to missing columns.

Yeah, updated to allow column additions for nullable fields.

May also need to check that partition spec hasn't changed (can do in a future PR)

Will do this in a future PR.

if (startSchema == null || endSchema == null) {
throw new IllegalStateException("Table schema is null.");
}
if (!DeltaIO.hasSameDataSchema(startSchema, endSchema)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also seems like this has negligible performance impact since there's no additional I/O operations needed to perform this check for the commit range.

* example, column comments, column default values, or identity column high-water marks (which
* writers update whenever they insert rows into the table) may differ between the two schemas.
*/
static boolean hasSameDataSchema(DataType left, DataType right) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ahmedabu98 ahmedabu98 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@chamikaramj
chamikaramj merged commit be3d44e into apache:master Oct 28, 2026
20 checks passed
@chamikaramj
chamikaramj deleted the delta_fail_schema_change branch October 28, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Delta Lake CDC should compare start and end schema during read and reject pipelines when schema doesn't match

2 participants