the-other-tim-brown commented on code in PR #9774:
URL: https://github.com/apache/hudi/pull/9774#discussion_r1353194753


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/common/table/log/HoodieFileSliceReader.java:
##########
@@ -19,47 +19,80 @@
 
 package org.apache.hudi.common.table.log;
 
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.model.HoodiePayloadProps;
 import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordMerger;
 import org.apache.hudi.common.util.Option;
 import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.exception.HoodieClusteringException;
 import org.apache.hudi.io.storage.HoodieFileReader;
 
 import org.apache.avro.Schema;
 
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Properties;
 
-/**
- * Reads records from base file and merges any updates from log files and 
provides iterable over all records in the file slice.
- */
-public class HoodieFileSliceReader<T> implements Iterator<HoodieRecord<T>> {
+public class HoodieFileSliceReader<T> extends LogFileIterator<T> {
+  private Option<Iterator<HoodieRecord>> baseFileIterator;
+  private HoodieMergedLogRecordScanner scanner;
+  private Schema schema;
+  private Properties props;
 
-  private final Iterator<HoodieRecord<T>> recordsIterator;
+  private TypedProperties payloadProps = new TypedProperties();
+  private Option<Pair<String, String>> simpleKeyGenFieldsOpt;
+  Map<String, HoodieRecord> records;
+  HoodieRecordMerger merger;
 
-  public static HoodieFileSliceReader getFileSliceReader(
-      Option<HoodieFileReader> baseFileReader, HoodieMergedLogRecordScanner 
scanner, Schema schema, Properties props, Option<Pair<String, String>> 
simpleKeyGenFieldsOpt) throws IOException {
+  public HoodieFileSliceReader(Option<HoodieFileReader> baseFileReader,
+                                   HoodieMergedLogRecordScanner scanner, 
Schema schema, String preCombineField, HoodieRecordMerger merger,
+                               Properties props, Option<Pair<String, String>> 
simpleKeyGenFieldsOpt) throws IOException {
+    super(scanner);
     if (baseFileReader.isPresent()) {
-      Iterator<HoodieRecord> baseIterator = 
baseFileReader.get().getRecordIterator(schema);
-      while (baseIterator.hasNext()) {
-        
scanner.processNextRecord(baseIterator.next().wrapIntoHoodieRecordPayloadWithParams(schema,
 props,
-            simpleKeyGenFieldsOpt, scanner.isWithOperationField(), 
scanner.getPartitionNameOverride(), false, Option.empty()));
-      }
+      this.baseFileIterator = 
Option.of(baseFileReader.get().getRecordIterator(schema));
+    } else {
+      this.baseFileIterator = Option.empty();
     }
-    return new HoodieFileSliceReader(scanner.iterator());
+    this.scanner = scanner;
+    this.schema = schema;
+    this.merger = merger;
+    if (preCombineField != null) {
+      
payloadProps.setProperty(HoodiePayloadProps.PAYLOAD_ORDERING_FIELD_PROP_KEY, 
preCombineField);
+    }
+    this.props = props;
+    this.simpleKeyGenFieldsOpt = simpleKeyGenFieldsOpt;
+    this.records = scanner.getRecords();
   }
 
-  private HoodieFileSliceReader(Iterator<HoodieRecord<T>> recordsItr) {
-    this.recordsIterator = recordsItr;
+  private Boolean hasNextInternal() {

Review Comment:
   use primitive `boolean` here



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/common/table/log/LogFileIterator.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public class LogFileIterator<T> extends CachingIterator<HoodieRecord<T>> {
+  HoodieMergedLogRecordScanner scanner;
+  Map<String, HoodieRecord> records;
+  Iterator<HoodieRecord> iterator;
+
+  protected Option<HoodieRecord> removeLogRecord(String key) {
+    return Option.ofNullable(records.remove(key));
+  }
+
+  public LogFileIterator(HoodieMergedLogRecordScanner scanner) {
+    this.scanner = scanner;
+    this.records = scanner.getRecords();
+  }
+
+  private Boolean hasNextInternal() {

Review Comment:
   make this a primitive `boolean`



##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/common/table/log/LogFileIterator.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public class LogFileIterator<T> extends CachingIterator<HoodieRecord<T>> {
+  HoodieMergedLogRecordScanner scanner;
+  Map<String, HoodieRecord> records;
+  Iterator<HoodieRecord> iterator;
+
+  protected Option<HoodieRecord> removeLogRecord(String key) {
+    return Option.ofNullable(records.remove(key));
+  }
+
+  public LogFileIterator(HoodieMergedLogRecordScanner scanner) {
+    this.scanner = scanner;
+    this.records = scanner.getRecords();
+  }
+
+  private Boolean hasNextInternal() {
+    if (iterator == null) {
+      iterator = records.values().iterator();
+    }
+    if (iterator.hasNext()) {
+      nextRecord = iterator.next();
+      return true;
+    }
+    return false;
+  }
+
+  @Override
+  protected Boolean doHasNext() {

Review Comment:
   same here, use `boolean`



-- 
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: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to