HuangZhenQiu commented on code in PR #17773:
URL: https://github.com/apache/hudi/pull/17773#discussion_r2679128497


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/reader/function/MergeOnReadSplitReaderFunction.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.source.reader.function;
+
+import org.apache.hudi.common.config.HoodieReaderConfig;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.model.FileSlice;
+import org.apache.hudi.common.model.HoodieBaseFile;
+import org.apache.hudi.common.model.HoodieFileGroupId;
+import org.apache.hudi.common.model.HoodieLogFile;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.table.read.HoodieFileGroupReader;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.configuration.FlinkOptions;
+import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.internal.schema.InternalSchema;
+import org.apache.hudi.source.reader.BatchRecords;
+import org.apache.hudi.source.reader.HoodieRecordWithPosition;
+import org.apache.hudi.source.split.HoodieSourceSplit;
+import org.apache.hudi.table.HoodieTable;
+
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+import org.apache.flink.table.data.RowData;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.stream.Collectors;
+
+/**
+ * Reader function implementation for Merge On Read table.
+ */
+public class MergeOnReadSplitReaderFunction<I, K, O> implements 
SplitReaderFunction<RowData> {
+  private final HoodieTable<RowData, I, K, O> hoodieTable;
+  private final HoodieReaderContext<RowData> readerContext;
+  private final HoodieSchema tableSchema;
+  private final HoodieSchema requiredSchema;
+  private final Option<InternalSchema> internalSchemaOption;
+  private final TypedProperties props;
+  private HoodieFileGroupReader<RowData> fileGroupReader;
+
+  public MergeOnReadSplitReaderFunction(HoodieTable<RowData, I, K, O> 
hoodieTable, HoodieReaderContext<RowData> readerContext) {
+    this(hoodieTable, readerContext, null, null, 
FlinkOptions.REALTIME_PAYLOAD_COMBINE, Option.empty());
+  }
+
+  public MergeOnReadSplitReaderFunction(
+      HoodieTable<RowData, I, K, O> hoodieTable,
+      HoodieReaderContext<RowData> readerContext,
+      HoodieSchema tableSchema,
+      HoodieSchema requiredSchema,
+      String mergeType,
+      Option<InternalSchema> internalSchemaOption) {
+
+    ValidationUtils.checkArgument(tableSchema != null, "tableSchema can't be 
null");
+    ValidationUtils.checkArgument(requiredSchema != null, "requiredSchema 
can't be null");
+
+    this.hoodieTable = hoodieTable;
+    this.readerContext = readerContext;
+    this.tableSchema = tableSchema;
+    this.requiredSchema = requiredSchema;
+    this.internalSchemaOption = internalSchemaOption;
+    this.props = new TypedProperties();
+    this.props.put(HoodieReaderConfig.MERGE_TYPE.key(), mergeType);
+    this.fileGroupReader = null;
+  }
+
+  @Override
+  public RecordsWithSplitIds<HoodieRecordWithPosition<RowData>> 
read(HoodieSourceSplit split) {
+    final String splitId = split.splitId();
+    try {
+      HoodieFileGroupReader<RowData> fileGroupReader = 
createFileGroupReader(split);
+      final ClosableIterator<RowData> recordIterator = 
fileGroupReader.getClosableIterator();
+      BatchRecords<RowData> records = BatchRecords.forRecords(splitId, 
recordIterator, split.getFileOffset(), split.getConsumed());
+      records.seek(split.getConsumed());
+      return records;
+    } catch (IOException e) {
+      throw new HoodieIOException("Failed to read from file group: " + 
split.getFileId(), e);
+    }
+  }
+
+  @Override
+  public void close() throws Exception {
+    if (fileGroupReader != null) {

Review Comment:
   Mistake. It should be covered by test case. added tests.



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