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_r349982946
 
 

 ##########
 File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/filesystem/FileSystemUtils.java
 ##########
 @@ -0,0 +1,165 @@
+/*
+ * 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.core.fs.Path;
+import org.apache.flink.table.api.TableException;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Utils for file system.
+ */
+public class FileSystemUtils {
+
+       private static final Pattern PARTITION_NAME_PATTERN = 
Pattern.compile("([^/]+)=([^/]+)");
+
+       private static final BitSet CHAR_TO_ESCAPE = new BitSet(128);
+       static {
+               for (char c = 0; c < ' '; c++) {
+                       CHAR_TO_ESCAPE.set(c);
+               }
+
+               /*
+                * ASCII 01-1F are HTTP control characters that need to be 
escaped.
+                * \u000A and \u000D are \n and \r, respectively.
+                */
+               char[] clist = new char[] {'\u0001', '\u0002', '\u0003', 
'\u0004',
+                               '\u0005', '\u0006', '\u0007', '\u0008', 
'\u0009', '\n', '\u000B',
+                               '\u000C', '\r', '\u000E', '\u000F', '\u0010', 
'\u0011', '\u0012',
+                               '\u0013', '\u0014', '\u0015', '\u0016', 
'\u0017', '\u0018', '\u0019',
+                               '\u001A', '\u001B', '\u001C', '\u001D', 
'\u001E', '\u001F',
+                               '"', '#', '%', '\'', '*', '/', ':', '=', '?', 
'\\', '\u007F', '{',
+                               '[', ']', '^'};
+
+               for (char c : clist) {
+                       CHAR_TO_ESCAPE.set(c);
+               }
+       }
+
+       private static boolean needsEscaping(char c) {
+               return c < CHAR_TO_ESCAPE.size() && CHAR_TO_ESCAPE.get(c);
+       }
+
+       /**
+        * Make partition path from partition spec.
+        *
+        * @param partitionSpec The partition spec.
+        * @return An escaped, valid partition name.
+        */
+       public static String generatePartName(LinkedHashMap<String, String> 
partitionSpec) {
+               StringBuilder suffixBuf = new StringBuilder();
+               int i = 0;
+               for (Map.Entry<String, String> e : partitionSpec.entrySet()) {
+                       if (i > 0) {
+                               suffixBuf.append(Path.SEPARATOR);
+                       }
+                       suffixBuf.append(escapePathName(e.getKey()));
+                       suffixBuf.append('=');
+                       suffixBuf.append(escapePathName(e.getValue()));
+                       i++;
+               }
+               suffixBuf.append(Path.SEPARATOR);
+               return suffixBuf.toString();
+       }
+
+       /**
+        * Escapes a path name.
+        * @param path The path to escape.
+        * @return An escaped path name.
+        */
+       private static String escapePathName(String path) {
+
+               // __DEFAULT_NULL__ is the system default value for null and 
empty string.
 
 Review comment:
   Wrong comment, I will remove it.

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