beyond1920 commented on code in PR #21257:
URL: https://github.com/apache/flink/pull/21257#discussion_r1057645105


##########
flink-connectors/flink-connector-files/src/main/java/org/apache/flink/connector/file/table/batch/compact/BatchFileWriter.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.flink.connector.file.table.batch.compact;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.file.table.OutputFormatFactory;
+import org.apache.flink.connector.file.table.PartitionComputer;
+import org.apache.flink.connector.file.table.PartitionTempFileManager;
+import org.apache.flink.connector.file.table.PartitionWriter;
+import org.apache.flink.connector.file.table.PartitionWriterFactory;
+import 
org.apache.flink.connector.file.table.stream.compact.CompactMessages.CoordinatorInput;
+import 
org.apache.flink.connector.file.table.stream.compact.CompactMessages.InputFile;
+import org.apache.flink.core.fs.Path;
+import 
org.apache.flink.streaming.api.functions.sink.filesystem.OutputFileConfig;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.table.api.TableException;
+
+import java.util.LinkedHashMap;
+
+/**
+ * An operator for writing files in batch mode. Once creating a new file to 
write, the writing
+ * operator will emit the written file to upstream.
+ */
+public class BatchFileWriter<T> extends 
AbstractStreamOperator<CoordinatorInput>
+        implements OneInputStreamOperator<T, CoordinatorInput>, 
BoundedOneInput {
+
+    private final Path tmpPath;
+    private final String[] partitionColumns;
+    private final boolean dynamicGrouped;
+    private final LinkedHashMap<String, String> staticPartitions;
+    private final PartitionComputer<T> computer;
+    private final OutputFormatFactory<T> formatFactory;
+    private final OutputFileConfig outputFileConfig;
+
+    private transient PartitionWriter<T> writer;
+
+    public BatchFileWriter(
+            Path tmpPath,
+            String[] partitionColumns,
+            boolean dynamicGrouped,
+            LinkedHashMap<String, String> staticPartitions,
+            OutputFormatFactory<T> formatFactory,
+            PartitionComputer<T> computer,
+            OutputFileConfig outputFileConfig) {
+        this.tmpPath = tmpPath;
+        this.partitionColumns = partitionColumns;
+        this.dynamicGrouped = dynamicGrouped;
+        this.staticPartitions = staticPartitions;
+        this.formatFactory = formatFactory;
+        this.computer = computer;
+        this.outputFileConfig = outputFileConfig;
+    }
+
+    @Override
+    public void open() throws Exception {
+        try {
+            PartitionTempFileManager fileManager =
+                    new PartitionTempFileManager(
+                            tmpPath,
+                            getRuntimeContext().getIndexOfThisSubtask(),
+                            getRuntimeContext().getAttemptNumber(),
+                            outputFileConfig);

Review Comment:
   It's not safe if the job enables speculative execution because multiple 
attempts would write to the same file.



-- 
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...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to