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

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new bc136727cdf [opt](Nereids) let behavior of function char same with 
legacy planner (#34415)
bc136727cdf is described below

commit bc136727cdf64aadd23f18d9e2cc23698b01f9bd
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
AuthorDate: Mon May 6 16:14:52 2024 +0800

    [opt](Nereids) let behavior of function char same with legacy planner 
(#34415)
    
    1. first argument must be string like literal
    2. only support utf-8 charset
---
 .../nereids/trees/expressions/functions/scalar/Char.java   | 14 ++++++++++++++
 .../string_functions/test_string_function.groovy           | 12 ++----------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Char.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Char.java
index 77b311835f6..0ea0ebe3668 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Char.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Char.java
@@ -18,9 +18,11 @@
 package org.apache.doris.nereids.trees.expressions.functions.scalar;
 
 import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.IntegerType;
 import org.apache.doris.nereids.types.StringType;
@@ -45,6 +47,18 @@ public class Char extends ScalarFunction
         super("char", varArgs);
     }
 
+    @Override
+    public void checkLegalityBeforeTypeCoercion() {
+        if (!(child(0) instanceof StringLikeLiteral)) {
+            throw new AnalysisException("char charset name must be a constant: 
" + child(0).toSql());
+        }
+        StringLikeLiteral stringLiteral = (StringLikeLiteral) child(0);
+        if (!"utf8".equalsIgnoreCase(stringLiteral.getStringValue())) {
+            throw new AnalysisException(
+                    "char function currently only support charset name 'utf8': 
" + child(0).toSql());
+        }
+    }
+
     /**
      * withChildren.
      */
diff --git 
a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy
index 2f5b49aa22d..64798978d3b 100644
--- 
a/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/string_functions/test_string_function.groovy
@@ -285,9 +285,6 @@ suite("test_string_function", "arrow_flight_sql") {
     qt_sql "select substring_index(\"prefix_string\", \"_\", null);"
     qt_sql "select substring_index(\"prefix_string\", \"__\", -1);"
 
-    sql 'set enable_nereids_planner=true'
-    sql 'set enable_fallback_to_original_planner=false'
-
     qt_sql "select elt(0, \"hello\", \"doris\");"
     qt_sql "select elt(1, \"hello\", \"doris\");"
     qt_sql "select elt(2, \"hello\", \"doris\");"
@@ -297,15 +294,10 @@ suite("test_string_function", "arrow_flight_sql") {
     qt_sql "select sub_replace(\"doris\",\"***\",1,2);"
 
     // test function char
-    sql 'set enable_nereids_planner=false'
-    def success = false
-    try {
+    test {
         sql """ select char(68 using abc); """
-        success = true
-    } catch (Exception e) {
-        assertTrue(e.getMessage().contains("only support charset name 
'utf8'"), e.getMessage())
+        exception "only support charset name 'utf8'"
     }
-    assertFalse(success)
 
     // const
     qt_sql_func_char_const1 """ select char(68); """


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to