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 9210bab252b919..bc239d24cf8740 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 FunctionSignature computeSignature(FunctionSignature signature) { @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 62965878289a64..4e35392ce63558 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 FunctionSignature computeSignature(FunctionSignature signature) { @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 542b8778d6368c..2d9c6feb995b6f 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 @@ -506,7 +506,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 """ @@ -515,6 +520,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)