lokeshj1703 opened a new pull request, #19773:
URL: https://github.com/apache/hudi/pull/19773

   ### Describe the issue this Pull Request addresses
   
   `OrderingValues#create` can represent a null ordering-field value as 
`HoodieRecord.DEFAULT_ORDERING_VALUE`, which is an `int`, while its counterpart 
in the same file group holds the column's real value of another type (for 
example a `Long`). Several event-time merge paths compared the two ordering 
values directly through `Comparable#compareTo`, which throws 
`ClassCastException: java.lang.Integer cannot be cast to java.lang.Long`, 
surfaced as `HoodieUpsertException`, which aborts the merge. The comment above 
`BufferedRecordMergerFactory.shouldKeepNewerRecord` already noted the hazard, 
but the guard it annotated applied only to DELETE records, and the same 
unguarded comparison existed in the other event-time record mergers.
   
   ### Summary and Changelog
   
   Add `OrderingValues.isBaseOrderingHigher(base, incoming)`, which returns 
whether the base ordering value strictly outranks the incoming one and 
evaluates to false, deferring to natural order so the incoming record wins, 
when either value is a commit-time ordering value (a null or the default 
sentinel) or the two values are of different classes. This is the guard 
`deltaMergeDeleteRecord` and `HoodieMergedLogRecordScanner` already applied, 
now shared. The event-time record mergers and the delete and partial-update 
merge paths are routed through it: `BufferedRecordMergerFactory` 
(`shouldKeepNewerRecord`, the partial-update `finalMerge` branch, and 
`deltaMergeDeleteRecord`), `HoodieMergedLogRecordScanner`, 
`DefaultSparkRecordMerger`, `EventTimeFlinkRecordMerger`, 
`PartialUpdateFlinkRecordMerger`, and `DefaultHiveRecordMerger`. 
`HoodieRecordMerger.maxOrderingValue` is made null and mixed-class safe with 
magnitude semantics (a commit-time ordering value ranks lowest, so the 
counterpart 
 is the max). For same-class, non-default ordering values behavior is unchanged.
   
   ### Impact
   
   No public API, config, or default change. Tables whose ordering field is 
nullable no longer fail event-time merges with a ClassCastException.
   
   ### Risk Level
   
   low
   
   Added `TestOrderingValues` for the new helper (same-class, mixed-class in 
both directions, null, and default inputs) and two cases in 
`TestBufferedRecordMergerFactory` covering mixed-class `finalMerge` and 
`deltaMerge` and unchanged same-class event-time ordering. They fail with 
`ClassCastException` against the unfixed merge path and pass with the fix.
   
   ### Documentation Update
   
   none
   
   ### Contributor's checklist
   
   - [ ] Read through [contributor's 
guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [ ] Enough context is provided in the sections above
   - [ ] Adequate tests were added if applicable
   


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

Reply via email to