This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 4e51eebcbb47123599d2d46d0a25060c3def7ffb
Author: lsy3993 <[email protected]>
AuthorDate: Fri Oct 20 19:56:55 2023 +0800

    [improvement](outfile)support underscore prefix when select outfile (#25395)
---
 .../java/org/apache/doris/analysis/OutFileClause.java    |  2 +-
 .../main/java/org/apache/doris/common/FeNameFormat.java  | 16 ++++++++++++++++
 .../java/org/apache/doris/common/FeNameFormatTest.java   |  3 +++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java
index 7d5c4433564..f0121b001e6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/OutFileClause.java
@@ -653,7 +653,7 @@ public class OutFileClause {
 
         if (properties.containsKey(PROP_SUCCESS_FILE_NAME)) {
             successFileName = properties.get(PROP_SUCCESS_FILE_NAME);
-            FeNameFormat.checkCommonName("file name", successFileName);
+            FeNameFormat.checkOutfileSuccessFileName("file name", 
successFileName);
             processedPropKeys.add(PROP_SUCCESS_FILE_NAME);
         }
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java
index f108dd782d1..3a77bde84b6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/FeNameFormat.java
@@ -30,12 +30,14 @@ import com.google.common.base.Strings;
 public class FeNameFormat {
     private static final String LABEL_REGEX = "^[-_A-Za-z0-9:]{1,128}$";
     private static final String COMMON_NAME_REGEX = 
"^[a-zA-Z][a-zA-Z0-9-_]{0,63}$";
+    private static final String UNDERSCORE_COMMON_NAME_REGEX = 
"^[_a-zA-Z][a-zA-Z0-9-_]{0,63}$";
     private static final String TABLE_NAME_REGEX = "^[a-zA-Z][a-zA-Z0-9-_]*$";
     private static final String USER_NAME_REGEX = "^[a-zA-Z][a-zA-Z0-9.-_]*$";
     private static final String COLUMN_NAME_REGEX = 
"^[_a-zA-Z@0-9\\s<>/][.a-zA-Z0-9_+-/><?@#$%^&*\"\\s,:]{0,255}$";
 
     private static final String UNICODE_LABEL_REGEX = 
"^[-_A-Za-z0-9:\\p{L}]{1,128}$";
     private static final String UNICODE_COMMON_NAME_REGEX = 
"^[a-zA-Z\\p{L}][a-zA-Z0-9-_\\p{L}]{0,63}$";
+    private static final String UNICODE_UNDERSCORE_COMMON_NAME_REGEX = 
"^[_a-zA-Z\\p{L}][a-zA-Z0-9-_\\p{L}]{0,63}$";
     private static final String UNICODE_TABLE_NAME_REGEX = 
"^[a-zA-Z\\p{L}][a-zA-Z0-9-_\\p{L}]*$";
     private static final String UNICODE_USER_NAME_REGEX = 
"^[a-zA-Z\\p{L}][a-zA-Z0-9.-_\\p{L}]*$";
     private static final String UNICODE_COLUMN_NAME_REGEX
@@ -138,6 +140,12 @@ public class FeNameFormat {
         }
     }
 
+    public static void checkOutfileSuccessFileName(String type, String name) 
throws AnalysisException {
+        if (Strings.isNullOrEmpty(name) || 
!name.matches(getOutfileSuccessFileNameRegex())) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_NAME_FORMAT, type, 
name);
+        }
+    }
+
     private static boolean isEnableUnicodeNameSupport() {
         boolean unicodeSupport;
         if (ConnectContext.get() != null) {
@@ -187,4 +195,12 @@ public class FeNameFormat {
             return COMMON_NAME_REGEX;
         }
     }
+
+    public static String getOutfileSuccessFileNameRegex() {
+        if (FeNameFormat.isEnableUnicodeNameSupport()) {
+            return UNICODE_UNDERSCORE_COMMON_NAME_REGEX;
+        } else {
+            return UNDERSCORE_COMMON_NAME_REGEX;
+        }
+    }
 }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/common/FeNameFormatTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/common/FeNameFormatTest.java
index 5d173172c0d..3edb6a33e96 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/common/FeNameFormatTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/common/FeNameFormatTest.java
@@ -55,6 +55,9 @@ public class FeNameFormatTest {
         ExceptionChecker.expectThrows(AnalysisException.class, () -> 
FeNameFormat.checkCommonName("fakeType", "_commonName"));
         ExceptionChecker.expectThrowsNoException(() -> 
FeNameFormat.checkCommonName("fakeType", "common-Name"));
         ExceptionChecker.expectThrowsNoException(() -> 
FeNameFormat.checkCommonName("fakeType", "commonName-"));
+
+        // check success file name prefix
+        ExceptionChecker.expectThrowsNoException(() -> 
FeNameFormat.checkOutfileSuccessFileName("fakeType", "_success"));
     }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to