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 a17034b7ff [fix](planner) do not support UDF without paramter (#24730)
a17034b7ff is described below

commit a17034b7ff42591ca59a649a69c7d59fc7e63097
Author: morrySnow <101034200+morrys...@users.noreply.github.com>
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 bd7800196d..15626ed00e 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -740,7 +740,7 @@ nonterminal ArrayList<LiteralExpr> literal_values, 
args_list;
 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;
@@ -1835,7 +1835,7 @@ create_stmt ::=
         RESULT = new CreateFunctionStmt(type, ifNotExists, isAggregate, 
functionName, args, returnType, intermediateType, properties);
     :}
     | KW_CREATE opt_var_type:type 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(type, ifNotExists, functionName, args, 
parameters, func);
     :}
@@ -6046,6 +6046,16 @@ ident_list ::=
     :}
     ;
 
+opt_ident_list ::=
+    {:
+        RESULT = Lists.newArrayList();
+    :}
+    | ident_list:list
+    {:
+        RESULT = list;
+    :}
+    ;
+
 with_analysis_properties ::=
     KW_SYNC
     {:
@@ -6440,7 +6450,11 @@ type_def_nullable_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 008f913196..f7ace7ce4e 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
@@ -77,6 +77,9 @@ public enum ExpressionFunctions {
                 || constExpr instanceof FunctionCallExpr
                 || constExpr instanceof TimestampArithmeticExpr) {
             Function fn = constExpr.getFn();
+            if (fn == null) {
+                return constExpr;
+            }
             if (ConnectContext.get() != null
                     && ConnectContext.get().getSessionVariable() != null
                     && 
!ConnectContext.get().getSessionVariable().isEnableFoldNondeterministicFn()
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 5cd25fd694..c53e2e89b5 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: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to