linliu-code commented on code in PR #10324:
URL: https://github.com/apache/hudi/pull/10324#discussion_r1429614415
##########
hudi-common/src/main/java/org/apache/hudi/common/model/EmptyHoodieRecordPayload.java:
##########
@@ -18,35 +18,69 @@
package org.apache.hudi.common.model;
+import org.apache.hudi.avro.HoodieAvroUtils;
+import org.apache.hudi.common.util.ConfigUtils;
import org.apache.hudi.common.util.Option;
+import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.IndexedRecord;
+import java.io.IOException;
+import java.util.Properties;
+
/**
* Empty payload used for deletions.
*/
public class EmptyHoodieRecordPayload implements
HoodieRecordPayload<EmptyHoodieRecordPayload> {
+ private Comparable orderingVal;
public EmptyHoodieRecordPayload() {
}
- public EmptyHoodieRecordPayload(GenericRecord record, Comparable
orderingVal) {
+ public EmptyHoodieRecordPayload(GenericRecord record, Comparable<?>
orderingVal) {
+ this.orderingVal = orderingVal;
}
@Override
public EmptyHoodieRecordPayload preCombine(EmptyHoodieRecordPayload
oldValue) {
- return oldValue;
+ return this;
}
@Override
public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord
currentValue, Schema schema) {
return Option.empty();
}
+ @Override
+ public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord
currentValue, Schema schema, Properties properties) throws IOException {
+ String orderField = ConfigUtils.getOrderingField(properties);
+ if (orderField == null || orderingVal == null) {
+ return Option.empty();
+ }
+
+ boolean consistentLogicalTimestampEnabled =
Boolean.parseBoolean(properties.getProperty(
+
KeyGeneratorOptions.KEYGENERATOR_CONSISTENT_LOGICAL_TIMESTAMP_ENABLED.key(),
+
KeyGeneratorOptions.KEYGENERATOR_CONSISTENT_LOGICAL_TIMESTAMP_ENABLED.defaultValue()));
+ Object currentOrderingVal =
HoodieAvroUtils.getNestedFieldVal((GenericRecord) currentValue,
+ orderField, true, consistentLogicalTimestampEnabled);
+ if (this.orderingVal.compareTo(currentOrderingVal) >= 0) {
+ return Option.empty();
+ }
+ return Option.of(currentValue);
+ }
+
@Override
public Option<IndexedRecord> getInsertValue(Schema schema) {
return Option.empty();
}
+
+ @Override
+ public Comparable<?> getOrderingValue() {
+ if (orderingVal == null) {
+ return 0;
Review Comment:
So should we just throw?
--
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]