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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 9ef74b5f7ca7ed4b160ac32e3e175f5ac2e0fc10
Author: morrySnow <[email protected]>
AuthorDate: Thu Sep 21 22:23:21 2023 +0800

    [fix](planner) do not support UDF without paramter (#24730)
    
    for example:
    CREATE ALIAS FUNCTION f() WITH PARAMETERS() AS now();
---
 fe/fe-core/src/main/cup/sql_parser.cup             | 20 ++++++++++++++---
 .../apache/doris/analysis/ExpressionFunctions.java |  3 +++
 .../sql_functions/test_alias_function.groovy       | 25 +++++++++++++++++++++-
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index a15c09a0d06..dcf6fd394ab 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -683,7 +683,7 @@ nonterminal ArrayList<Expr> expr_list, values, row_value, 
opt_values;
 nonterminal ArrayList<Expr> func_arg_list;
 nonterminal ArrayList<Expr> expr_pipe_list;
 nonterminal String select_alias, opt_table_alias, lock_alias, opt_alias;
-nonterminal ArrayList<String> ident_list;
+nonterminal ArrayList<String> ident_list, opt_ident_list;
 nonterminal PartitionNames opt_partition_names, partition_names;
 nonterminal ArrayList<Long> opt_tablet_list, tablet_list;
 nonterminal TableSample opt_table_sample, table_sample;
@@ -1737,7 +1737,7 @@ create_stmt ::=
         RESULT = new CreateFunctionStmt(ifNotExists, isAggregate, 
functionName, args, returnType, intermediateType, properties);
     :}
     | KW_CREATE KW_ALIAS KW_FUNCTION opt_if_not_exists:ifNotExists 
function_name:functionName LPAREN func_args_def:args RPAREN
-            KW_WITH KW_PARAMETER LPAREN ident_list:parameters RPAREN KW_AS 
expr:func
+            KW_WITH KW_PARAMETER LPAREN opt_ident_list:parameters RPAREN KW_AS 
expr:func
     {:
         RESULT = new CreateFunctionStmt(ifNotExists, functionName, args, 
parameters, func);
     :}
@@ -5378,6 +5378,16 @@ ident_list ::=
     :}
     ;
 
+opt_ident_list ::=
+    {:
+        RESULT = Lists.newArrayList();
+    :}
+    | ident_list:list
+    {:
+        RESULT = list;
+    :}
+    ;
+
 expr_list ::=
   expr:e
   {:
@@ -5675,7 +5685,11 @@ type_def_list ::=
   ;
 
 func_args_def ::=
-  type_def_list:argTypes
+  /* empty */
+  {:
+    RESULT = new FunctionArgsDef(Lists.newArrayList(), false);
+  :}
+  | type_def_list:argTypes
   {:
     RESULT = new FunctionArgsDef(argTypes, false);
   :}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java
index 4357c35011b..826d3e7a7ae 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java
@@ -67,6 +67,9 @@ public enum ExpressionFunctions {
                 || constExpr instanceof FunctionCallExpr
                 || constExpr instanceof TimestampArithmeticExpr) {
             Function fn = constExpr.getFn();
+            if (fn == null) {
+                return constExpr;
+            }
 
             Preconditions.checkNotNull(fn, "Expr's fn can't be null.");
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/test_alias_function.groovy 
b/regression-test/suites/query_p0/sql_functions/test_alias_function.groovy
index 5cd25fd694d..c53e2e89b55 100644
--- a/regression-test/suites/query_p0/sql_functions/test_alias_function.groovy
+++ b/regression-test/suites/query_p0/sql_functions/test_alias_function.groovy
@@ -16,7 +16,6 @@
 // under the License.
 
 suite('test_alias_function') {
-    sql "use test_query_db"
     sql '''
         CREATE ALIAS FUNCTION IF NOT EXISTS f1(DATETIMEV2(3), INT)
             with PARAMETER (datetime1, int1) as date_trunc(days_sub(datetime1, 
int1), 'day')'''
@@ -31,4 +30,28 @@ suite('test_alias_function') {
         sql '''select f2(f1('2023-03-29', 2), 3)'''
         result([['20230327:01']])
     }
+
+    sql "set enable_nereids_planner=false"
+
+    sql '''
+        DROP FUNCTION IF EXISTS legacy_f4()
+    '''
+
+    sql '''
+        CREATE ALIAS FUNCTION legacy_f4() WITH PARAMETER() AS now()
+    '''
+
+    sql '''
+        SELECT legacy_f4(), now()
+    '''
+
+    sql "set enable_nereids_planner=true"
+
+    sql '''
+        SELECT legacy_f4(), now()
+    '''
+
+    sql '''
+        DROP FUNCTION IF EXISTS legacy_f4()
+    '''
 }


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

Reply via email to