JingsongLi commented on a change in pull request #9864: [FLINK-14254][table] 
Introduce FileSystemOutputFormat for batch
URL: https://github.com/apache/flink/pull/9864#discussion_r349978969
 
 

 ##########
 File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/filesystem/TempFileManager.java
 ##########
 @@ -0,0 +1,148 @@
+/*
+ * 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.table.filesystem;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.core.fs.FileStatus;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.flink.util.Preconditions.checkArgument;
+
+/**
+ * Manage temporary files for writing files. Use special rules to organize 
directories
+ * for temporary files.
+ *
+ * <p>Temporary file directory contains the following directory parts:
+ *  1.temporary base path directory.
+ *  2.checkpoint id directory.
+ *  3.task id directory.
+ *  4.directories to specify partitioning.
+ *  5.data files.
+ *  eg: /tmp/cp-1/task-0/p0=1/p1=2/fileName.
+ */
+@Internal
+public class TempFileManager {
+
+       private static final String CHECKPOINT_DIR_PREFIX = "cp-";
+       private static final String TASK_DIR_PREFIX = "task-";
+
+       private final int taskNumber;
+       private final long checkpointId;
+       private final Path taskTmpDir;
+
+       private transient int nameCounter = 0;
+
+       public TempFileManager(Path temporaryPath, int taskNumber, long 
checkpointId) {
+               checkArgument(checkpointId != -1, "checkpoint id start with 
0.");
+               this.taskNumber = taskNumber;
+               this.checkpointId = checkpointId;
+               this.taskTmpDir = new Path(
+                               new Path(temporaryPath, 
checkpointName(checkpointId)),
+                               TASK_DIR_PREFIX + taskNumber);
+       }
+
+       public Path getTaskTemporaryPath() {
+               return taskTmpDir;
+       }
+
+       /**
+        * Generate a new path with directories.
+        */
+       public Path generateTempFile(String... directories) throws Exception {
+               Path parentPath = taskTmpDir;
+               for (String dir : directories) {
+                       parentPath = new Path(parentPath, dir);
+               }
+               return new Path(parentPath, newFileName());
+       }
+
+       private String newFileName() {
+               return String.format(
+                               checkpointName(checkpointId) + "-" + 
taskName(taskNumber) + "-file-%d",
 
 Review comment:
   Finally, these files will be moved to final directory, so with these 
information, we can reduce name conflicts.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to