yanghua commented on a change in pull request #2056:
URL: https://github.com/apache/hudi/pull/2056#discussion_r482897786
##########
File path:
hudi-common/src/main/java/org/apache/hudi/common/model/OverwriteWithLatestAvroPayload.java
##########
@@ -79,8 +79,18 @@ public OverwriteWithLatestAvroPayload
preCombine(OverwriteWithLatestAvroPayload
* @param genericRecord instance of {@link GenericRecord} of interest.
* @returns {@code true} if record represents a delete record. {@code false}
otherwise.
*/
- private boolean isDeleteRecord(GenericRecord genericRecord) {
+ protected boolean isDeleteRecord(GenericRecord genericRecord) {
Object deleteMarker = genericRecord.get("_hoodie_is_deleted");
return (deleteMarker instanceof Boolean && (boolean) deleteMarker);
}
+
+ /**
+ *
+ * @param value value in Insert Value
Review comment:
ditto
##########
File path:
hudi-common/src/main/java/org/apache/hudi/common/model/OverwriteNonDefaultsWithLatestAvroPayload.java
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.model;
+
+import org.apache.hudi.common.util.Option;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.IndexedRecord;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * subclass of OverwriteWithLatestAvroPayload used for delta streamer.
+ * <p>
+ * 1. preCombine - Picks the latest delta record for a key, based on an
ordering field.
+ * 2. combineAndGetUpdateValue/getInsertValue - overwrite storage for
specified fields
+ * that doesn't equal defaultValue.
+ */
+public class OverwriteNonDefaultsWithLatestAvroPayload extends
OverwriteWithLatestAvroPayload {
+
+ /**
+ * @param record Generic record for the payload.
Review comment:
If you want to add java doc, it would be better to add a description for
the method?
##########
File path:
hudi-common/src/main/java/org/apache/hudi/common/model/OverwriteWithLatestAvroPayload.java
##########
@@ -79,8 +79,18 @@ public OverwriteWithLatestAvroPayload
preCombine(OverwriteWithLatestAvroPayload
* @param genericRecord instance of {@link GenericRecord} of interest.
* @returns {@code true} if record represents a delete record. {@code false}
otherwise.
*/
- private boolean isDeleteRecord(GenericRecord genericRecord) {
+ protected boolean isDeleteRecord(GenericRecord genericRecord) {
Object deleteMarker = genericRecord.get("_hoodie_is_deleted");
return (deleteMarker instanceof Boolean && (boolean) deleteMarker);
}
+
+ /**
+ *
+ * @param value value in Insert Value
+ * @param defaultValue defaultValue of the field
+ * @return {@code true} if value equals defaultValue {@code false} otherwise.
+ */
+ public Boolean ovewriteField(Object value, Object defaultValue) {
Review comment:
`overwriteField`?
##########
File path:
hudi-common/src/test/java/org/apache/hudi/common/model/TestOverwriteNonDefaultsWithLatestAvroPayload.java
##########
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.model;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+/**
+ * Unit tests {@link TestOverwriteNonDefaultsWithLatestAvroPayload}.
+ */
+public class TestOverwriteNonDefaultsWithLatestAvroPayload {
+ private Schema schema;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ schema = Schema.createRecord(Arrays.asList(
+ new Schema.Field("id", Schema.create(Schema.Type.STRING), "",
null),
+ new Schema.Field("partition", Schema.create(Schema.Type.STRING),
"", ""),
+ new Schema.Field("ts", Schema.create(Schema.Type.LONG), "", null),
+ new Schema.Field("_hoodie_is_deleted",
Schema.create(Schema.Type.BOOLEAN), "", false)
Review comment:
Can we add a use case for default value which neither `null` nor `''`?
##########
File path:
hudi-common/src/main/java/org/apache/hudi/common/model/OverwriteWithLatestAvroPayload.java
##########
@@ -79,8 +79,18 @@ public OverwriteWithLatestAvroPayload
preCombine(OverwriteWithLatestAvroPayload
* @param genericRecord instance of {@link GenericRecord} of interest.
* @returns {@code true} if record represents a delete record. {@code false}
otherwise.
*/
- private boolean isDeleteRecord(GenericRecord genericRecord) {
+ protected boolean isDeleteRecord(GenericRecord genericRecord) {
Object deleteMarker = genericRecord.get("_hoodie_is_deleted");
return (deleteMarker instanceof Boolean && (boolean) deleteMarker);
}
+
+ /**
+ *
+ * @param value value in Insert Value
+ * @param defaultValue defaultValue of the field
+ * @return {@code true} if value equals defaultValue {@code false} otherwise.
+ */
+ public Boolean ovewriteField(Object value, Object defaultValue) {
+ return defaultValue == null ? value == defaultValue :
defaultValue.toString().equals(value.toString());
Review comment:
change to : `return defaultValue == null ? value == null :
defaultValue.toString().equals(value.toString());`?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]