danny0405 commented on code in PR #20734:
URL: https://github.com/apache/hudi/pull/20734#discussion_r4624010146


##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieMergedLogRecordScanner.java:
##########
@@ -100,6 +100,8 @@ public class HoodieMergedLogRecordScanner extends 
AbstractHoodieLogRecordScanner
   private long totalTimeTakenToReadAndMergeBlocks;
   private final String[] orderingFields;
   private final DeleteContext deleteContext;
+  // Merging registers schema IDs, so the context and its local cache must 
belong to this scanner.
+  private final RecordContext recordContext = new AvroRecordContext();

Review Comment:
   Fixed in 69d33eedbc5. `RealtimeCompactedRecordReader` now owns a final 
`AvroRecordContext` and reuses it for buffering, merging, and constructing the 
result. The remaining production Avro singleton callers only use 
`isDeleteRecord`. All 36 `TestHoodieRealtimeRecordReader` cases passed on JDK 
17, along with the 7 focused common-module tests and the reactor's 
Checkstyle/RAT checks.



##########
hudi-common/src/test/java/org/apache/hudi/common/table/log/TestHoodieMergedLogRecordScanner.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.log;
+
+import org.apache.hudi.common.engine.RecordContext;
+import org.apache.hudi.common.model.HoodieAvroIndexedRecord;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.read.BufferedRecord;
+
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TestHoodieMergedLogRecordScanner {
+  @TempDir
+  Path tempDir;
+
+  @Test
+  void testSchemaCacheIsOwnedByEachScanner() throws Exception {
+    HoodieSchema firstSchema = schema("first");
+    HoodieSchema secondSchema = schema("second");
+    List<RecordContext<IndexedRecord>> contexts = new ArrayList<>();
+    HoodieRecordMerger merger = mock(HoodieRecordMerger.class);
+    
when(merger.getRecordType()).thenReturn(HoodieRecord.HoodieRecordType.AVRO);
+    when(merger.merge(any(), any(), any(), any())).thenAnswer(invocation -> {
+      BufferedRecord<IndexedRecord> older = invocation.getArgument(0);
+      BufferedRecord<IndexedRecord> newer = invocation.getArgument(1);
+      RecordContext<IndexedRecord> context = invocation.getArgument(2);
+      contexts.add(context);
+      assertEquals(older.getRecord().getSchema(), 
context.getSchemaFromBufferRecord(older).toAvroSchema());
+      assertEquals(newer.getRecord().getSchema(), 
context.getSchemaFromBufferRecord(newer).toAvroSchema());
+      return newer;
+    });
+
+    try (HoodieMergedLogRecordScanner first = scanner(firstSchema, merger);
+         HoodieMergedLogRecordScanner second = scanner(secondSchema, merger)) {
+      first.processNextRecord(record(firstSchema, "first-insert"));
+      first.processNextRecord(record(firstSchema, "first-update"));
+      second.processNextRecord(record(secondSchema, "second-insert"));
+      second.processNextRecord(record(secondSchema, "second-update"));
+      first.processNextRecord(record(firstSchema, "first-update-again"));
+
+      assertEquals(3, contexts.size());
+      RecordContext<IndexedRecord> firstContext = contexts.get(0);
+      RecordContext<IndexedRecord> secondContext = contexts.get(1);
+      assertNotSame(firstContext, secondContext, "Scanners must not share 
their schema cache");
+      assertSame(firstContext, contexts.get(2), "A scanner must reuse its 
context across merges");
+      // Both scanners start their own ID space, and each ID still resolves to 
its own schema.
+      Integer firstId = firstContext.encodeSchema(firstSchema);
+      Integer secondId = secondContext.encodeSchema(secondSchema);
+      assertEquals(firstId, secondId);
+      assertEquals(firstSchema, firstContext.decodeAvroSchema(firstId));
+      assertEquals(secondSchema, secondContext.decodeAvroSchema(secondId));

Review Comment:
   Removed in 69d33eedbc5. The test retains the cross-scanner `assertNotSame` 
and within-scanner `assertSame` checks; schema-ID namespace coverage stays in 
`TestLocalHoodieSchemaCache`.



##########
hudi-common/src/test/java/org/apache/hudi/common/table/log/TestHoodieMergedLogRecordScanner.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.log;
+
+import org.apache.hudi.common.engine.RecordContext;
+import org.apache.hudi.common.model.HoodieAvroIndexedRecord;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.read.BufferedRecord;
+
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.IndexedRecord;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class TestHoodieMergedLogRecordScanner {
+  @TempDir
+  Path tempDir;
+
+  @Test
+  void testSchemaCacheIsOwnedByEachScanner() throws Exception {
+    HoodieSchema firstSchema = schema("first");
+    HoodieSchema secondSchema = schema("second");
+    List<RecordContext<IndexedRecord>> contexts = new ArrayList<>();
+    HoodieRecordMerger merger = mock(HoodieRecordMerger.class);
+    
when(merger.getRecordType()).thenReturn(HoodieRecord.HoodieRecordType.AVRO);
+    when(merger.merge(any(), any(), any(), any())).thenAnswer(invocation -> {
+      BufferedRecord<IndexedRecord> older = invocation.getArgument(0);
+      BufferedRecord<IndexedRecord> newer = invocation.getArgument(1);
+      RecordContext<IndexedRecord> context = invocation.getArgument(2);
+      contexts.add(context);
+      assertEquals(older.getRecord().getSchema(), 
context.getSchemaFromBufferRecord(older).toAvroSchema());
+      assertEquals(newer.getRecord().getSchema(), 
context.getSchemaFromBufferRecord(newer).toAvroSchema());
+      return newer;

Review Comment:
   Updated in 69d33eedbc5. The inputs are now payload-wrapped 
`HoodieAvroRecord<OverwriteWithLatestAvroPayload>` instances. The mock records 
the context, verifies schema resolution, and delegates to 
`HoodiePreCombineAvroRecordMerger.merge(...)`, while the final assertions check 
the merged values. The revised test passes on JDK 17.



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