wwj6591812 commented on code in PR #5715: URL: https://github.com/apache/paimon/pull/5715#discussion_r2137004291
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/operator/BatchReadSource.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.paimon.flink.source.operator; + +import org.apache.paimon.flink.NestedProjectedRowData; +import org.apache.paimon.flink.source.AbstractNonCoordinatedSource; +import org.apache.paimon.flink.source.AbstractNonCoordinatedSourceReader; +import org.apache.paimon.flink.source.SimpleSourceSplit; +import org.apache.paimon.flink.utils.JavaTypeInfo; +import org.apache.paimon.table.source.DataSplit; +import org.apache.paimon.table.source.ReadBuilder; +import org.apache.paimon.table.source.Split; +import org.apache.paimon.table.source.TableScan; + +import org.apache.flink.api.common.eventtime.WatermarkStrategy; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.connector.source.Boundedness; +import org.apache.flink.api.connector.source.ReaderOutput; +import org.apache.flink.api.connector.source.SourceReader; +import org.apache.flink.api.connector.source.SourceReaderContext; +import org.apache.flink.core.io.InputStatus; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.data.RowData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +import static org.apache.paimon.flink.source.operator.MonitorSource.shuffleNonUnawareBucket; +import static org.apache.paimon.flink.source.operator.MonitorSource.shuffleUnawareBucket; + +/** + * This is the single (non-parallel) batch task, it is responsible for: + * + * <ol> + * <li>Read the latest snapshot of the Paimon table. + * <li>Creating the {@link Split splits} corresponding to the DataFiles + * <li>Assigning them to downstream tasks for further processing. + * </ol> + * + * <p>The splits to be read are forwarded to the downstream {@link ReadOperator} which can have + * parallelism greater than one. + */ +public class BatchReadSource extends AbstractNonCoordinatedSource<Split> { + + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(BatchReadSource.class); + + private final ReadBuilder readBuilder; + + private final String tableName; + + public BatchReadSource(ReadBuilder readBuilder) { + this.readBuilder = readBuilder; + this.tableName = readBuilder.tableName(); + } + + @Override + public Boundedness getBoundedness() { + return Boundedness.BOUNDED; + } + + @Override + public SourceReader<Split, SimpleSourceSplit> createReader( + SourceReaderContext sourceReaderContext) throws Exception { + return new Reader(); + } + + private class Reader extends AbstractNonCoordinatedSourceReader<Split> { + + private final TableScan scan = readBuilder.newScan(); + + @Override + public InputStatus pollNext(ReaderOutput<Split> readerOutput) throws Exception { + List<Split> splits = scan.plan().splits(); + + if (splits.size() == 0) { + LOG.info("In BatchSource the table {} plan split is empty.", tableName); + } else { + DataSplit dataSplit = (DataSplit) splits.get(0); + LOG.info( + "Read the snapshot-{} of table {} in BatchSource.", + dataSplit.snapshotId(), + tableName); + } + + splits.forEach(readerOutput::collect); + + return InputStatus.END_OF_INPUT; Review Comment: I don't want to reusing MonitorSource instead of BatchReadSource, because: 1、MonitorSource is a periodic check for new snapshots, which semantically means streaming processing, not batch processing. 2、There is lots of checkpoint states logic in MonitorSource, thus not used in batch mode. 3、It will add some if...else... in MonitorSource, for example in MonitorSource#getBoundedness、MonitorSource#Reader#pollNext. -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org