JingsongLi commented on code in PR #1347: URL: https://github.com/apache/incubator-paimon/pull/1347#discussion_r1226396361
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/UnawareBucketSourceFunction.java: ########## @@ -0,0 +1,110 @@ +/* + * 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; + +import org.apache.paimon.append.AppendOnlyCompactionTask; +import org.apache.paimon.append.AppendOnlyTableCompactionCoordinator; +import org.apache.paimon.flink.sink.CompactionTaskTypeInfo; +import org.apache.paimon.predicate.Predicate; +import org.apache.paimon.table.AppendOnlyFileStoreTable; +import org.apache.paimon.table.source.EndOfScanException; + +import org.apache.flink.api.connector.source.Boundedness; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.datastream.DataStreamSource; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.operators.StreamSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; + +import java.util.List; + +/** Source Function for unaware-bucket Compaction. */ +public class UnawareBucketSourceFunction extends RichSourceFunction<AppendOnlyCompactionTask> { + + private static final Logger LOG = LoggerFactory.getLogger(UnawareBucketSourceFunction.class); + private static final String COMPACTION_COORDINATOR_NAME = "Compaction Coordinator"; + + private final AppendOnlyFileStoreTable table; + private transient AppendOnlyTableCompactionCoordinator compactionCoordinator; + private volatile boolean isRunning = true; + private final boolean streaming; + private final long scanInterval; + private final Predicate filter; + + public UnawareBucketSourceFunction( + AppendOnlyFileStoreTable table, + boolean isStreaming, + long scanInterval, + @Nullable Predicate filter) { + this.table = table; + this.streaming = isStreaming; + this.scanInterval = scanInterval; + this.filter = filter; + } + + @Override + public void open(Configuration parameters) throws Exception { + compactionCoordinator = new AppendOnlyTableCompactionCoordinator(table, streaming, filter); + } + + @Override + public void run(SourceContext<AppendOnlyCompactionTask> sourceContext) throws Exception { + while (isRunning) { + boolean isEmpty; + try { + // do scan and plan action, emit append-only compaction tasks. + List<AppendOnlyCompactionTask> tasks = compactionCoordinator.run(); Review Comment: need a lock here. ########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/UnawareBucketCompactionSink.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.sink; + +import org.apache.paimon.append.AppendOnlyCompactionTask; +import org.apache.paimon.manifest.ManifestCommittable; +import org.apache.paimon.table.AppendOnlyFileStoreTable; +import org.apache.paimon.utils.SerializableFunction; + +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.datastream.DataStreamSink; +import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; + +/** Compaction Sink for unaware-bucket table. */ +public class UnawareBucketCompactionSink extends FlinkSink<AppendOnlyCompactionTask> { + + private static final String COMPACTION_WORKER_NAME = "Compaction Worker"; + + private AppendOnlyFileStoreTable table; + private Integer compactionWorkerParallelism; + + public UnawareBucketCompactionSink( + AppendOnlyFileStoreTable table, Integer compactionWorkerParallelism) { + super(table, true); + this.table = table; + this.compactionWorkerParallelism = compactionWorkerParallelism; + } + + @Override + protected SingleOutputStreamOperator<Committable> handleInput( + DataStream<AppendOnlyCompactionTask> input, boolean isStreaming, String commitUser) { + CommittableTypeInfo committableTypeInfo = new CommittableTypeInfo(); + SingleOutputStreamOperator<Committable> compacted = + input.transform( + COMPACTION_WORKER_NAME + " -> " + table.name(), + committableTypeInfo, + new AppendOnlyTableCompactionWorkerOperator(table, commitUser)); + + if (compactionWorkerParallelism != null) { + compacted.setParallelism(compactionWorkerParallelism); + } + + return compacted; + } + + public static DataStreamSink<?> sink( + AppendOnlyFileStoreTable table, + Integer compactionWorkerParallelism, + DataStream<AppendOnlyCompactionTask> input) { + return new UnawareBucketCompactionSink(table, compactionWorkerParallelism).sinkFrom(input); + } + + @Override + protected OneInputStreamOperator<AppendOnlyCompactionTask, Committable> createWriteOperator( + StoreSinkWrite.Provider writeProvider, boolean isStreaming, String commitUser) { + return null; Review Comment: Can we also implements this? Just ignore `writeProvider` -- 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]
