Skip to content

[IcebergIO] Fix CDC reads on date, time, timestamp and fixed primary keys - #41583

Open
ahmedabu98 wants to merge 2 commits into
apache:masterfrom
ahmedabu98:iceberg-cdc-temporal-keys
Open

ahmedabu98 wants to merge 2 commits into
apache:masterfrom
ahmedabu98:iceberg-cdc-temporal-keys

Conversation

@ahmedabu98

Copy link
Copy Markdown
Contributor

Fixes CDC reads on tables whose primary key has a date, time, timestamp or fixed column, which could crash or split an update into a DELETE and an INSERT.
Keys and overlap bounds now go through InternalRecordWrapper, so Iceberg's comparator gets the internal values it expects.

Iceberg's comparator reads a date key as an Integer, a time or
timestamp key as a Long and a fixed key as a ByteBuffer, but generic
records hold java.time values and byte arrays. So a CDC read on a date,
time, timestamp, timestamptz or fixed key crashed when a snapshot's
deletes and inserts overlapped. Without bounds, as with position
deletes or metrics turned off, the local resolve path didn't crash, but
its map couldn't match equal keys either, so an update came out as a
DELETE and an INSERT with no error.

Wrap the record's key and the overlap bounds in InternalRecordWrapper
before comparing them and before the key goes into the map.
@github-actions github-actions Bot added java io iceberg Iceberg IO connector size/s S: 10-49 lines changed labels Nov 23, 2026

@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 fixes CDC primary key comparison and overlap bound handling for Iceberg types whose in-memory Record representation differs from Iceberg's internal StructLike form (date, time, timestamp, timestamptz, and fixed). By wrapping projected record keys and converted Beam overlap bounds with InternalRecordWrapper in OverlapRange, both Comparators.forType and StructLikeMap receive the internal representations they expect.

🔍 General Feedback

  • The use of InternalRecordWrapper in OverlapRange cleanly bridges the gap between GenericRecord field values (LocalDate, LocalTime, LocalDateTime, OffsetDateTime, byte[]) and Iceberg's StructLike comparators/hashes (Integer, Long, ByteBuffer) across both ReadFromChangelogs and LocalResolveDoFn.
  • Eagerly copying the wrapped bounds via StructLikeUtil.copy(recordId.copyFor(...)) in toStructLike avoids repeated conversions per record during range checks.
  • The added test coverage in IncrementalChangelogSourceTest effectively exercises all affected key types across both the distributed CoGroupByKey path and the in-memory LocalResolveDoFn path.

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

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @chamikaramj for label iceberg.
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 Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.99%. Comparing base (fc21f2f) to head (d9fb12e).

Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41583   +/-   ##
=========================================
  Coverage     57.99%   57.99%           
  Complexity     2842     2842           
=========================================
  Files          1210     1210           
  Lines        173114   173114           
  Branches       2330     2330           
=========================================
  Hits         100402   100402           
  Misses        69999    69999           
  Partials       2713     2713           

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

@chamikaramj chamikaramj 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.

Probably also worth adding a CHANGES.md entry.

StructProjection recordIdProjection() {
return recordIdProjection;
/** The PK of the record last passed to {@link #contains}, in Iceberg's internal form. */
StructLike recordIdProjection() {

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.

Change to recordId() since this seems to be returning recordId now not projection ?

@github-actions github-actions Bot added size/m M: 50-249 lines changed and removed size/s S: 10-49 lines changed labels Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iceberg Iceberg IO connector io java Next Action: Reviewers size/m M: 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants