JingsongLi commented on code in PR #1366:
URL: https://github.com/apache/incubator-paimon/pull/1366#discussion_r1233939530


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/FlinkSink.java:
##########
@@ -126,33 +126,29 @@ public DataStreamSink<?> sinkFrom(DataStream<T> input) {
     }
 
     public DataStreamSink<?> sinkFrom(DataStream<T> input, String 
initialCommitUser) {
+        // do the actually writing action, no snapshot generated in this stage
+        SingleOutputStreamOperator<Committable> written = doWrite(input, 
initialCommitUser);
 
-        return sinkFrom(
-                input,
-                initialCommitUser,
-                
createWriteProvider(input.getExecutionEnvironment().getCheckpointConfig()));
+        // commit the committable to generate a new snapshot
+        return doCommit(written, initialCommitUser);
     }
 
-    public DataStreamSink<?> sinkFrom(
-            DataStream<T> input, String commitUser, StoreSinkWrite.Provider 
sinkProvider) {
-        StreamExecutionEnvironment env = input.getExecutionEnvironment();
-        ReadableConfig conf = 
StreamExecutionEnvironmentUtils.getConfiguration(env);
-        CheckpointConfig checkpointConfig = env.getCheckpointConfig();
-
+    public SingleOutputStreamOperator<Committable> doWrite(DataStream<T> 
input, String commitUser) {

Review Comment:
   `Integer parallelism` to set writer parallelism.



##########
paimon-core/src/main/java/org/apache/paimon/operation/AppendOnlyFileStoreWrite.java:
##########
@@ -159,7 +161,20 @@ public AppendOnlyCompactManager.CompactRewriter 
compactRewriter(
         };
     }
 
-    public void skipCompaction() {
-        skipCompaction = true;
+    public AppendOnlyFileStoreWrite withBucketMode(BucketMode bucketMode) {
+        // AppendOnlyFileStoreWrite is sensitive with bucket mode. It will act 
difference in
+        // unaware-bucket mode (no compaction and force empty-writer).
+        this.bucketMode = bucketMode;
+        if (bucketMode == BucketMode.UNAWARE) {
+            super.withIgnorePreviousFiles(true);
+            skipCompaction = true;
+        }
+        return this;
+    }
+
+    @Override
+    public void withIgnorePreviousFiles(boolean emptyWriter) {

Review Comment:
   Don't use emptyWriter



##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/UnawareBucketWriteSink.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.flink.compact.UnawareBucketCompactionTopoBuilder;
+import org.apache.paimon.operation.Lock;
+import org.apache.paimon.table.AppendOnlyFileStoreTable;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSink;
+import org.apache.flink.streaming.api.transformations.PartitionTransformation;
+import org.apache.flink.table.data.RowData;
+
+import java.util.Map;
+
+/**
+ * Build topology for unaware bucket table sink.
+ *
+ * <p>Note: in unaware-bucket mode, we don't shuffle by bucket in inserting. 
We can assign
+ * compaction to the inserting jobs aside.
+ */
+public class UnawareBucketWriteSink extends FileStoreSink {
+
+    private final boolean enableCompaction;
+    private final AppendOnlyFileStoreTable table;
+    private final Integer parallelism;
+
+    public UnawareBucketWriteSink(
+            AppendOnlyFileStoreTable table,
+            Lock.Factory lock,
+            Map<String, String> overwritePartitions,
+            LogSinkFunction logSinkFunction,
+            Integer parallelism) {
+        super(table, lock, overwritePartitions, logSinkFunction);
+        this.table = table;
+        this.enableCompaction = !table.coreOptions().writeOnly();
+        this.parallelism = parallelism;
+    }
+
+    @Override
+    public DataStreamSink<?> sinkFrom(DataStream<RowData> input, String 
initialCommitUser) {
+        // partition input to meet parallelism of 'sink.parallelism'
+        DataStream<RowData> partitioned = partition(input, parallelism);
+
+        // do the actually writing action, no snapshot generated in this stage
+        DataStream<Committable> written = doWrite(partitioned, 
initialCommitUser);
+
+        // if enable compaction, we need to add compaction topology to this job
+        if (enableCompaction) {
+            boolean isStreamingMode =
+                    input.getExecutionEnvironment()
+                                    .getConfiguration()
+                                    .get(ExecutionOptions.RUNTIME_MODE)
+                            == RuntimeExecutionMode.STREAMING;
+
+            UnawareBucketCompactionTopoBuilder builder =
+                    new UnawareBucketCompactionTopoBuilder(
+                            input.getExecutionEnvironment(), table.name(), 
table);
+            builder.withContinuousMode(isStreamingMode);
+            written = 
written.union(builder.fetchUncommitted(initialCommitUser));
+        }
+
+        // commit the committable to generate a new snapshot
+        return doCommit(written, initialCommitUser);
+    }
+
+    private DataStream<RowData> partition(DataStream<RowData> input, Integer 
parallelism) {
+        // we set partitioner equals null, if the parallelism we set equals to 
input, we could chain
+        // sink operator and input in one stage
+        PartitionTransformation<RowData> partitionTransformation =

Review Comment:
   You should remove this to set writer parallelism.



##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/UnawareBucketCompactorCoordinationSourceFunction.java:
##########
@@ -38,10 +38,20 @@
 
 import java.util.List;
 
-/** Source Function for unaware-bucket Compaction. */
-public class UnawareBucketSourceFunction extends 
RichSourceFunction<AppendOnlyCompactionTask> {
+/**
+ * Source Function for unaware-bucket Compaction.
+ *
+ * <p>Note: The function is the source function of unaware-bucket compactor 
coordinator. It will
+ * read the latest snapshot continuously by compactionCoordinator, and 
generate new compaction
+ * tasks. The source function is used in unaware-bucket compaction job (both 
stand-alone and
+ * write-combined). Besides, we don't need to save state in this function, it 
will invoke a full
+ * scan when starting up, and scan continuously for the following snapshot.
+ */
+public class UnawareBucketCompactorCoordinationSourceFunction

Review Comment:
   `BucketUnawareCompactSource`



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