Repository navigation
[IcebergIO] Fix CDC reads on date, time, timestamp and fixed primary keys - #41583
ahmedabu98 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
📋 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
InternalRecordWrapperinOverlapRangecleanly bridges the gap betweenGenericRecordfield values (LocalDate,LocalTime,LocalDateTime,OffsetDateTime,byte[]) and Iceberg'sStructLikecomparators/hashes (Integer,Long,ByteBuffer) across bothReadFromChangelogsandLocalResolveDoFn. - Eagerly copying the wrapped bounds via
StructLikeUtil.copy(recordId.copyFor(...))intoStructLikeavoids repeated conversions per record during range checks. - The added test coverage in
IncrementalChangelogSourceTesteffectively exercises all affected key types across both the distributedCoGroupByKeypath and the in-memoryLocalResolveDoFnpath.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @chamikaramj for label iceberg. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
chamikaramj
left a comment
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Change to recordId() since this seems to be returning recordId now not projection ?
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.