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

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

commit 7f3a666facb104c2b69fe09c266fc2084e118c09
Author: LiBinfeng <46676950+libinfeng...@users.noreply.github.com>
AuthorDate: Wed Mar 6 10:01:00 2024 +0800

    [fix](planner) fix ifnull and nvl function with one parameters exception 
message anbugious (#31808)
    
    When ifnull or nvl funtion have only one parameter, nereids planner would 
throw an exception and go back to
    original planner/ Original planner get secend parameter directly without 
check, so it return unexpected error message
---
 .../java/org/apache/doris/analysis/FunctionCallExpr.java |  2 ++
 .../suites/nereids_function_p0/scalar_function/N.groovy  | 16 +++++++++++++++-
 .../conditional_functions/test_ifnull.groovy             |  9 +++++++++
 .../sql_functions/conditional_functions/test_nvl.groovy  |  8 ++++++++
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index 719bc72b67e..b5184c33fcd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1543,6 +1543,8 @@ public class FunctionCallExpr extends Expr {
 
         } else if (fnName.getFunction().equalsIgnoreCase("ifnull")
                 || fnName.getFunction().equalsIgnoreCase("nvl")) {
+            Preconditions.checkArgument(children != null && children.size() == 
2,
+                    "The " + fnName + " function must have two params");
             Type[] childTypes = collectChildReturnTypes();
             Type assignmentCompatibleType = 
ScalarType.getAssignmentCompatibleType(childTypes[0], childTypes[1], true,
                     enableDecimal256);
diff --git 
a/regression-test/suites/nereids_function_p0/scalar_function/N.groovy 
b/regression-test/suites/nereids_function_p0/scalar_function/N.groovy
index 7b399e3aae8..c99372058ec 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/N.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/N.groovy
@@ -103,4 +103,18 @@ suite("nereids_scalar_fn_N") {
        qt_sql_nvl_Varchar_Varchar_notnull "select nvl(kvchrs1, kvchrs1) from 
fn_test_not_nullable order by kvchrs1, kvchrs1"
        qt_sql_nvl_String_String "select nvl(kstr, kstr) from fn_test order by 
kstr, kstr"
        qt_sql_nvl_String_String_notnull "select nvl(kstr, kstr) from 
fn_test_not_nullable order by kstr, kstr"
-}
\ No newline at end of file
+       test{
+               sql"""select ifnull(kstr) from fn_test"""
+               check {result, exception, startTime, endTime ->
+                       assertTrue(exception != null)
+                       logger.info(exception.message)
+               }
+       }
+       test{
+               sql"""select nvl(kstr) from fn_test"""
+               check {result, exception, startTime, endTime ->
+                       assertTrue(exception != null)
+                       logger.info(exception.message)
+               }
+       }
+}
diff --git 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_ifnull.groovy
 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_ifnull.groovy
index 32ccc70ebc4..f1f0528d54d 100644
--- 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_ifnull.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_ifnull.groovy
@@ -17,6 +17,7 @@
 
 suite("test_ifnull") {
        def tbName = "test_ifnull"
+       sql "set enable_nereids_planner=false"
        sql "DROP TABLE IF EXISTS ${tbName};"
        sql"""
                CREATE TABLE IF NOT EXISTS ${tbName} (
@@ -35,6 +36,14 @@ suite("test_ifnull") {
 
        qt_sql "select id,t_decimal,test_double,ifnull(t_decimal,test_double) 
as if_dou,ifnull(test_double,t_decimal) as if_dei from test_ifnull;"
 
+       test{
+               sql"""select ifnull(kstr) from fn_test"""
+               check {result, exception, startTime, endTime ->
+                       assertTrue(exception != null)
+                       logger.info(exception.message)
+               }
+       }
+
        sql "DROP TABLE ${tbName};"
 }
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_nvl.groovy
 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_nvl.groovy
index 5c19602b6c1..7a9e9f28a29 100644
--- 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_nvl.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_nvl.groovy
@@ -19,4 +19,12 @@ suite("test_nvl") {
     qt_select "select nvl(k6, \"false\") k from test_query_db.test order by k1"
     sql """set enable_nereids_planner=false;"""
     qt_select2 "select nvl(123456.134444454,0);"
+
+    test{
+        sql"""select nvl(k6) from test_query_db.test"""
+        check {result, exception, startTime, endTime ->
+            assertTrue(exception != null)
+            logger.info(exception.message)
+        }
+    }
 }


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

Reply via email to