hudi-agent commented on code in PR #19769:
URL: https://github.com/apache/hudi/pull/19769#discussion_r3870971599
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/BufferedRecordMergerFactory.java:
##########
@@ -512,6 +512,16 @@ private static <T> boolean
shouldKeepNewerRecord(BufferedRecord<T> oldRecord, Bu
// The orderingVal is constant 0 (int) and not guaranteed to match the
type of the old or new record's ordering value.
return true;
}
- return
newRecord.getOrderingValue().compareTo(oldRecord.getOrderingValue()) >= 0;
+ Comparable oldOrderingVal = oldRecord.getOrderingValue();
+ Comparable newOrderingVal = newRecord.getOrderingValue();
+ // Checks the ordering value does not equal to 0
+ // because we use 0 as the default value which means natural order.
+ // OrderingValues#create coerces a null ordering field value to that
default, so its class need
+ // not match the counterpart's real value and comparing the two directly
would throw
+ // ClassCastException (e.g. Long.compareTo(Integer)).
+ boolean chooseOlder = !OrderingValues.isDefault(newOrderingVal)
+ && OrderingValues.isSameClass(oldOrderingVal, newOrderingVal)
+ && oldOrderingVal.compareTo(newOrderingVal) > 0;
+ return !chooseOlder;
Review Comment:
🤖 nit: `return !chooseOlder` reads as a double negative inside a method
already named `shouldKeepNewerRecord` — could you rename the variable to
`keepOlder` and return `!keepOlder`, or flip it to `keepNewer` and return that
directly? Either way reduces the mental flip.
<sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]