yihua commented on code in PR #10277:
URL: https://github.com/apache/hudi/pull/10277#discussion_r1430515864


##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestEventTimeMerging.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.table.read;
+
+import org.apache.hudi.common.testutils.HoodieTestTable;
+import 
org.apache.hudi.common.testutils.reader.HoodieFileGroupReaderTestHarness;
+import org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.AVRO_SCHEMA;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.DELETE;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.INSERT;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.UPDATE;
+import static 
org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils.ROW_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestEventTimeMerging extends HoodieFileGroupReaderTestHarness {
+  @BeforeAll
+  public static void setUp() throws IOException {
+    // Specify the key column values for each file.
+    keyRanges = Arrays.asList(
+        new HoodieFileSliceTestUtils.KeyRange(1, 10),
+        new HoodieFileSliceTestUtils.KeyRange(1, 5),
+        new HoodieFileSliceTestUtils.KeyRange(1, 3),
+        new HoodieFileSliceTestUtils.KeyRange(6, 8),
+        new HoodieFileSliceTestUtils.KeyRange(1, 2));

Review Comment:
   Add docs on the expected rows after each commit to easily understand the 
tests and what are validated against.



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestEventTimeMerging.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.table.read;
+
+import org.apache.hudi.common.testutils.HoodieTestTable;
+import 
org.apache.hudi.common.testutils.reader.HoodieFileGroupReaderTestHarness;
+import org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.AVRO_SCHEMA;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.DELETE;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.INSERT;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.UPDATE;
+import static 
org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils.ROW_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestEventTimeMerging extends HoodieFileGroupReaderTestHarness {

Review Comment:
   Can we make this a base test class that we can run the same set of tests for 
any engine with the `HoodieReaderContext` provided (similar to 
`TestHoodieReaderWriterBase` which can be used to test the reader and writer 
for any format)?  The core logic can be tested through 
`HoodieTestReaderContext`.



##########
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;

Review Comment:
   Let's keep this class unchanged.



##########
hudi-common/src/test/java/org/apache/hudi/common/table/read/TestEventTimeMerging.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.table.read;
+
+import org.apache.hudi.common.testutils.HoodieTestTable;
+import 
org.apache.hudi.common.testutils.reader.HoodieFileGroupReaderTestHarness;
+import org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.AVRO_SCHEMA;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.DELETE;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.INSERT;
+import static 
org.apache.hudi.common.testutils.reader.DataGenerationPlan.OperationType.UPDATE;
+import static 
org.apache.hudi.common.testutils.reader.HoodieFileSliceTestUtils.ROW_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestEventTimeMerging extends HoodieFileGroupReaderTestHarness {
+  @BeforeAll
+  public static void setUp() throws IOException {
+    // Specify the key column values for each file.
+    keyRanges = Arrays.asList(
+        new HoodieFileSliceTestUtils.KeyRange(1, 10),
+        new HoodieFileSliceTestUtils.KeyRange(1, 5),
+        new HoodieFileSliceTestUtils.KeyRange(1, 3),
+        new HoodieFileSliceTestUtils.KeyRange(6, 8),
+        new HoodieFileSliceTestUtils.KeyRange(1, 2));
+    // Specify the value of `timestamp` column for each file.
+    timestamps = Arrays.asList(
+        2L, 3L, 1L, 1L, 4L);
+    // Specify the operation type for each file.
+    operationTypes = Arrays.asList(
+        INSERT, DELETE, UPDATE, DELETE, UPDATE);
+    // Specify the instant time for each file.
+    instantTimes = Arrays.asList(
+        "001", "002", "003", "004", "005");
+  }
+
+  @BeforeEach
+  public void initialize() throws Exception {
+    setTableName(TestEventTimeMerging.class.getName());
+    initPath(tableName);
+    initMetaClient();
+    initTestDataGenerator(new String[]{PARTITION_PATH});
+    testTable = HoodieTestTable.of(metaClient);
+    setUpMockCommits();
+  }
+
+  @Test
+  public void testWithOneLogFile() throws IOException, InterruptedException {
+    // The FileSlice contains a base file and a log file.
+    ClosableIterator<IndexedRecord> iterator = getFileGroupIterator(2);
+    List<String> leftKeysExpected = Arrays.asList("6", "7", "8", "9", "10");
+    List<String> leftKeysActual = new ArrayList<>();
+    while (iterator.hasNext()) {
+      
leftKeysActual.add(iterator.next().get(AVRO_SCHEMA.getField(ROW_KEY).pos()).toString());
+    }
+    assertEquals(leftKeysExpected, leftKeysActual);
+  }
+
+  @Test
+  public void testWithTwoLogFiles() throws IOException, InterruptedException {
+    // The FileSlice contains a base file and two log files.
+    ClosableIterator<IndexedRecord> iterator = getFileGroupIterator(3);
+    List<String> leftKeysExpected = Arrays.asList("6", "7", "8", "9", "10");
+    List<String> leftKeysActual = new ArrayList<>();
+    while (iterator.hasNext()) {
+      
leftKeysActual.add(iterator.next().get(AVRO_SCHEMA.getField(ROW_KEY).pos()).toString());
+    }
+    assertEquals(leftKeysExpected, leftKeysActual);

Review Comment:
   Also validate non-key values to make sure the values are updated or kept the 
same based on the ordering field values?



##########
hudi-common/src/test/java/org/apache/hudi/common/testutils/reader/HoodieTestReaderContext.java:
##########
@@ -122,11 +138,9 @@ public HoodieRecord<IndexedRecord> constructHoodieRecord(
     if (!recordOpt.isPresent()) {
       HoodieKey key = new HoodieKey((String) 
metadataMap.get(INTERNAL_META_RECORD_KEY),
           (String) metadataMap.get(INTERNAL_META_PARTITION_PATH));
-      return new HoodieEmptyRecord<>(
-          key,
-          HoodieOperation.DELETE,
-          (Comparable<?>) metadataMap.get(INTERNAL_META_ORDERING_FIELD),
-          HoodieRecord.HoodieRecordType.AVRO);
+      return new HoodieAvroRecord(key, new EmptyHoodieRecordPayload(
+          null,
+          (Comparable<?>) metadataMap.get(INTERNAL_META_ORDERING_FIELD)));

Review Comment:
   After following the logic in 
`HoodieMergedLogRecordScanner#processNextDeletedRecord`, the delete in the log 
block leads to a payload of the configured payload class with null record and 
ordering value, not `EmptyHoodieRecordPayload`.  Let's follow that logic too.
   
   ```
   SpillableMapUtils
     /**
      * Utility method to convert bytes to HoodieRecord using schema and 
payload class.
      */
     public static <R> R generateEmptyPayload(String recKey, String 
partitionPath, Comparable orderingVal, String payloadClazz) {
       HoodieRecord<? extends HoodieRecordPayload> hoodieRecord = new 
HoodieAvroRecord<>(new HoodieKey(recKey, partitionPath),
           HoodieRecordUtils.loadPayload(payloadClazz, new Object[] {null, 
orderingVal}, GenericRecord.class, Comparable.class));
       return (R) hoodieRecord;
     }
   ```



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