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

zclll 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 5285135c126 [Fix](funtion) Fix utc_time result when input null (#57716)
5285135c126 is described below

commit 5285135c12667306149ada3ae4c750cf2bdf6334
Author: linrrarity <[email protected]>
AuthorDate: Wed Nov 5 19:03:44 2025 +0800

    [Fix](funtion) Fix utc_time result when input null (#57716)
    
    Related PR: https://github.com/apache/doris/pull/57347
    
    Before:
    ```text
    mysql> select utc_time(NULL);
    +----------------+
    | utc_time(NULL) |
    +----------------+
    | 00:00:00       |
    +----------------+
    ```
    
    After(throw error same with MySQL):
    ```text
    mysql> select utc_time(NULL);
    ERROR 1105 (HY000): errCode = 2, detailMessage = UTC_TIME argument cannot 
be NULL.
    ```
---
 .../nereids/trees/expressions/functions/scalar/UtcTime.java      | 9 +++++++--
 .../nereids/trees/expressions/functions/scalar/UtcTimestamp.java | 9 +++++++--
 .../sql_functions/datetime_functions/test_date_function.groovy   | 9 +++++++++
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTime.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTime.java
index 9210bab252b..bc239d24cf8 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTime.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTime.java
@@ -84,8 +84,13 @@ public class UtcTime extends ScalarFunction
 
     @Override
     public void checkLegalityAfterRewrite() {
-        if (arity() == 1 && !child(0).isLiteral()) {
-            throw new AnalysisException("UTC_TIME scale argument must be a 
constant literal.");
+        if (arity() == 1) {
+            if (child(0).isNullLiteral()) {
+                throw new AnalysisException("UTC_TIME argument cannot be 
NULL.");
+            }
+            if (!child(0).isLiteral()) {
+                throw new AnalysisException("UTC_TIME scale argument must be a 
constant literal.");
+            }
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTimestamp.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTimestamp.java
index 62965878289..4e35392ce63 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTimestamp.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/UtcTimestamp.java
@@ -79,8 +79,13 @@ public class UtcTimestamp extends ScalarFunction
 
     @Override
     public void checkLegalityAfterRewrite() {
-        if (arity() == 1 && !child(0).isLiteral()) {
-            throw new AnalysisException("UTC_TIMESTAMP scale argument must be 
a constant literal.");
+        if (arity() == 1) {
+            if (child(0).isNullLiteral()) {
+                throw new AnalysisException("UTC_TIMESTAMP argument cannot be 
NULL.");
+            }
+            if (!child(0).isLiteral()) {
+                throw new AnalysisException("UTC_TIMESTAMP scale argument must 
be a constant literal.");
+            }
         }
     }
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index e0c87139eba..c7223d076a7 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -503,7 +503,12 @@ suite("test_date_function") {
         sql """ select utc_timestamp(7) """
         exception "scale must be between 0 and 6"
     }
+    test {
+        sql """ SELECT UTC_TIMESTAMP(NULL); """
+        exception "UTC_TIMESTAMP argument cannot be NULL."
+    }
 
+    // UTC_TIME
     def utc_time_str = sql """ select utc_time(),utc_time() + 1 """
     assertTrue(utc_time_str[0].size() == 2)
     utc_time_str = sql """ select utc_time(6), utc_time(6) + 1 """
@@ -512,6 +517,10 @@ suite("test_date_function") {
         sql """ select utc_time(7) """
         exception "scale must be between 0 and 6"
     }
+    test {
+        sql """ SELECT UTC_TIME(NULL); """
+        exception "UTC_TIME argument cannot be NULL."
+    }
 
     def utc_date_str = sql """ select utc_date(),utc_date() + 1 """
     assertTrue(utc_date_str[0].size() == 2)


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

Reply via email to