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


##########
hudi-common/src/main/java/org/apache/hudi/common/table/log/HoodieMetadataMergedLogRecordScanner.java:
##########
@@ -0,0 +1,308 @@
+/*
+ * 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.config.HoodieCommonConfig;
+import org.apache.hudi.common.model.DeleteRecord;
+import org.apache.hudi.common.model.HoodieEmptyRecord;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieMetadataRecordMerger;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.common.table.cdc.HoodieCDCUtils;
+import org.apache.hudi.common.util.CollectionUtils;
+import org.apache.hudi.common.util.DefaultSizeEstimator;
+import org.apache.hudi.common.util.HoodieRecordSizeEstimator;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ReflectionUtils;
+import org.apache.hudi.common.util.SpillableMapUtils;
+import org.apache.hudi.common.util.collection.ExternalSpillableMap;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.internal.schema.InternalSchema;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.avro.Schema;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.fs.FSUtils.getRelativePartitionPath;
+import static org.apache.hudi.common.util.StringUtils.nonEmpty;
+import static org.apache.hudi.common.util.ValidationUtils.checkArgument;
+
+public class HoodieMetadataMergedLogRecordScanner extends 
HoodieMergedLogRecordScanner {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(HoodieMetadataMergedLogRecordScanner.class);
+  // Map of compacted/merged records
+  private final ExternalSpillableMap<Serializable, HoodieRecord> records;
+
+  private HoodieMetadataMergedLogRecordScanner(HoodieStorage storage, String 
basePath, List<String> logFilePaths, Schema readerSchema,
+                                               String latestInstantTime, Long 
maxMemorySizeInBytes,
+                                               boolean reverseReader, int 
bufferSize, String spillableMapBasePath,
+                                               Option<InstantRange> 
instantRange,
+                                               
ExternalSpillableMap.DiskMapType diskMapType,
+                                               boolean 
isBitCaskDiskMapCompressionEnabled,
+                                               boolean withOperationField, 
boolean forceFullScan,
+                                               Option<String> partitionName,
+                                               InternalSchema internalSchema,
+                                               Option<String> keyFieldOverride,
+                                               boolean 
enableOptimizedLogBlocksScan, HoodieRecordMerger recordMerger,
+                                               Option<HoodieTableMetaClient> 
hoodieTableMetaClientOption) {
+    super(storage, basePath, logFilePaths, readerSchema, latestInstantTime, 
maxMemorySizeInBytes, reverseReader, bufferSize, spillableMapBasePath, 
instantRange, diskMapType,
+        isBitCaskDiskMapCompressionEnabled, withOperationField, false, 
partitionName, internalSchema, keyFieldOverride, enableOptimizedLogBlocksScan, 
recordMerger,
+        hoodieTableMetaClientOption);
+    try {
+      // Store merged records for all versions for this log file, set the 
in-memory footprint to maxInMemoryMapSize
+      this.records = new ExternalSpillableMap<>(maxMemorySizeInBytes, 
spillableMapBasePath, new DefaultSizeEstimator(),
+          new HoodieRecordSizeEstimator(readerSchema), diskMapType, 
isBitCaskDiskMapCompressionEnabled);
+    } catch (IOException e) {
+      throw new HoodieIOException("IOException when creating 
ExternalSpillableMap at " + spillableMapBasePath, e);
+    }
+  }
+
+  @Override
+  public Map<String, HoodieRecord> getRecords() {
+    return records.entrySet().stream().collect(
+        Collectors.toMap(entry -> entry.getKey().toString(), 
Map.Entry::getValue));
+  }
+
+  @Override
+  public <T> void processNextRecord(HoodieRecord<T> newRecord) throws 
IOException {
+    // Merge the new record with the existing record in the map

Review Comment:
   Can overcome the duplicate code if we make the cache key as generic type.



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