cshuo commented on code in PR #17773:
URL: https://github.com/apache/hudi/pull/17773#discussion_r2663365730
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/mor/MergeOnReadInputSplit.java:
##########
@@ -68,12 +70,53 @@ public MergeOnReadInputSplit(
this.logPaths = logPaths;
this.latestCommit = latestCommit;
this.tablePath = tablePath;
+ this.partitionPath = partitionPath;
this.maxCompactionMemoryInBytes = maxCompactionMemoryInBytes;
this.mergeType = mergeType;
this.instantRange = Option.ofNullable(instantRange);
this.fileId = fileId;
}
+ public String getFileId() {
Review Comment:
Unnecessary changes. We use lombok annotations now.
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/reader/function/MergeOnReadSplitReaderFunction.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.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.reader.SplitReaderFunction;
+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 String mergeType;
Review Comment:
field not used.
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/mor/MergeOnReadInputSplit.java:
##########
@@ -68,12 +70,53 @@ public MergeOnReadInputSplit(
this.logPaths = logPaths;
this.latestCommit = latestCommit;
this.tablePath = tablePath;
+ this.partitionPath = partitionPath;
Review Comment:
`partitionPath` seems not needed.
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/reader/function/MergeOnReadSplitReaderFunction.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.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.reader.SplitReaderFunction;
+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 String mergeType;
+ private final Option<InternalSchema> internalSchemaOption;
+ private final TypedProperties props;
+
+ 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) {
+ this.hoodieTable = hoodieTable;
+ this.readerContext = readerContext;
+ this.tableSchema = tableSchema;
+ this.requiredSchema = requiredSchema;
+ this.mergeType = mergeType;
+ this.internalSchemaOption = internalSchemaOption;
+ this.props = new TypedProperties();
+ this.props.put(HoodieReaderConfig.MERGE_TYPE.key(), mergeType);
+ }
+
+ @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.getRecordOffset());
+ records.seek(split.getRecordOffset());
+ return records;
+ } catch (IOException e) {
+ throw new HoodieIOException("Failed to read from file group: " +
split.getFileId(), e);
+ }
+ }
+
+ /**
+ * Creates a {@link HoodieFileGroupReader} for the given split.
+ *
+ * @param split The source split to read
+ * @return A {@link HoodieFileGroupReader} instance
+ */
+ private HoodieFileGroupReader<RowData>
createFileGroupReader(HoodieSourceSplit split) {
+ // Create FileSlice from split information
+ FileSlice fileSlice = new FileSlice(
+ new HoodieFileGroupId(split.getPartitionPath(), split.getFileId()),
+ "",
+ split.getBasePath().map(HoodieBaseFile::new).orElse(null),
+ split.getLogPaths().map(logFiles ->
+
logFiles.stream().map(HoodieLogFile::new).collect(Collectors.toList())
+ ).orElse(Collections.emptyList())
+ );
+
+ // Build the file group reader
+ HoodieFileGroupReader.Builder<RowData> builder =
HoodieFileGroupReader.<RowData>newBuilder()
+ .withReaderContext(readerContext)
+ .withHoodieTableMetaClient(hoodieTable.getMetaClient())
+ .withFileSlice(fileSlice)
+ .withProps(props)
+ .withShouldUseRecordPosition(true);
+
+ // Add schemas if provided
+ if (tableSchema != null) {
Review Comment:
`dataSchema` annd `requestedSchema` cannot be null for file group reader.
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/reader/BatchRecords.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+
+/**
+ * Implementation of RecordsWithSplitIds with a list record inside.
+ *
+ * Type parameters: <T> – record type
+ */
+public class BatchRecords<T> implements
RecordsWithSplitIds<HoodieRecordWithPosition<T>> {
+ private String splitId;
+ private final ClosableIterator<T> recordIterator;
+ private final Set<String> finishedSplits;
+ private final HoodieRecordWithPosition<T> recordAndPosition;
+
+ // point to current read position within the records list
+ private int position;
+
+ BatchRecords(
+ String splitId,
+ ClosableIterator<T> recordIterator,
+ int fileOffset,
+ long startingRecordOffset,
+ Set<String> finishedSplits) {
+ ValidationUtils.checkArgument(
+ finishedSplits != null, "finishedSplits can be empty but not null");
+ ValidationUtils.checkArgument(
+ recordIterator != null, "recordIterator can be empty but not null");
+
+ this.splitId = splitId;
+ this.recordIterator = recordIterator;
+ this.finishedSplits = finishedSplits;
+ this.recordAndPosition = new HoodieRecordWithPosition<>();
+ this.recordAndPosition.set(null, fileOffset, startingRecordOffset);
+ this.position = 0;
+ }
+
+ @Nullable
+ @Override
+ public String nextSplit() {
+ String nextSplit = this.splitId;
+ // set the splitId to null to indicate no more splits
+ // this class only contains record for one split
+ this.splitId = null;
+ return nextSplit;
+ }
+
+ @Nullable
+ @Override
+ public HoodieRecordWithPosition<T> nextRecordFromSplit() {
+ if (recordIterator.hasNext()) {
+ recordAndPosition.record(recordIterator.next());
+ position++;
+ return recordAndPosition;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Set<String> finishedSplits() {
+ return finishedSplits;
+ }
+
+ public void seek(long startingRecordOffset) {
+ for (long i = 0; i < startingRecordOffset; ++i) {
+ if (recordIterator.hasNext()) {
Review Comment:
if `position` is necessary, it should be also increased here?
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/reader/BatchRecords.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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;
+
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.flink.connector.base.source.reader.RecordsWithSplitIds;
+
+/**
+ * Implementation of RecordsWithSplitIds with a list record inside.
+ *
+ * Type parameters: <T> – record type
+ */
+public class BatchRecords<T> implements
RecordsWithSplitIds<HoodieRecordWithPosition<T>> {
+ private String splitId;
+ private final ClosableIterator<T> recordIterator;
+ private final Set<String> finishedSplits;
+ private final HoodieRecordWithPosition<T> recordAndPosition;
+
+ // point to current read position within the records list
+ private int position;
Review Comment:
`position` value is increased but never accessed.
--
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]