diff --git a/be/src/vec/functions/function_date_or_datetime_computation.cpp b/be/src/vec/functions/function_date_or_datetime_computation.cpp index 8034d34c195e05..9506835c5d31d4 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.cpp +++ b/be/src/vec/functions/function_date_or_datetime_computation.cpp @@ -89,7 +89,7 @@ using FunctionLocalTimestamp = FunctionCurrentDateOrDateTime>; using FunctionNowWithPrecision = - FunctionCurrentDateOrDateTime, false>; + FunctionCurrentDateOrDateTime>; using FunctionCurrentTimestampWithPrecision = FunctionCurrentDateOrDateTime>; using FunctionLocalTimeWithPrecision = diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h b/be/src/vec/functions/function_date_or_datetime_computation.h index f91fe643b307b4..3ba1808c9cd6ac 100644 --- a/be/src/vec/functions/function_date_or_datetime_computation.h +++ b/be/src/vec/functions/function_date_or_datetime_computation.h @@ -832,7 +832,7 @@ class FunctionDateOrDateTimeComputation : public IFunction { } }; -template +template class FunctionCurrentDateOrDateTime : public IFunction { public: static constexpr bool has_variadic_argument = @@ -845,8 +845,6 @@ class FunctionCurrentDateOrDateTime : public IFunction { size_t get_number_of_arguments() const override { return 0; } - bool use_default_implementation_for_nulls() const override { return DefaultNullable; } - DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { return std::make_shared(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Now.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Now.java index 19feb7684cb571..90b1f77a375494 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Now.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/Now.java @@ -19,7 +19,6 @@ import org.apache.doris.catalog.FunctionSignature; import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable; import org.apache.doris.nereids.trees.expressions.functions.DateTimeWithPrecision; import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature; import org.apache.doris.nereids.trees.expressions.functions.Nondeterministic; @@ -36,8 +35,7 @@ /** * ScalarFunction 'now'. This class is generated by GenerateFunction. */ -public class Now extends DateTimeWithPrecision - implements ExplicitlyCastableSignature, Nondeterministic, AlwaysNotNullable { +public class Now extends DateTimeWithPrecision implements ExplicitlyCastableSignature, Nondeterministic { public static final List SIGNATURES = ImmutableList.of( FunctionSignature.ret(DateTimeType.INSTANCE).args(), @@ -72,6 +70,18 @@ public Now withChildren(List children) { } } + /** + * Depend on child. + */ + @Override + public boolean nullable() { + if (arity() == 0) { + return false; + } + Preconditions.checkArgument(children.size() == 1); + return child(0).nullable(); + } + @Override public List getSignatures() { return SIGNATURES; diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index 31c1bef74dc1e7..a0141972a9352f 100644 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -857,8 +857,8 @@ [['from_unixtime'], 'VARCHAR', ['INT'], 'ALWAYS_NULLABLE'], [['from_unixtime'], 'VARCHAR', ['INT', 'VARCHAR'], 'ALWAYS_NULLABLE'], [['from_unixtime'], 'VARCHAR', ['INT', 'STRING'], 'ALWAYS_NULLABLE'], - [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 'DATETIME', [], 'ALWAYS_NOT_NULLABLE'], - [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 'DATETIMEV2', ['INT'], 'ALWAYS_NOT_NULLABLE'], + [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 'DATETIME', [], 'DEPEND_ON_ARGUMENT'], + [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 'DATETIMEV2', ['INT'], 'DEPEND_ON_ARGUMENT'], [['curtime', 'current_time'], 'TIME', [], 'ALWAYS_NOT_NULLABLE'], [['curdate', 'current_date'], 'DATE', [], 'ALWAYS_NOT_NULLABLE'], [['utc_timestamp'], 'DATETIME', [], 'ALWAYS_NOT_NULLABLE'], 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 6debd4d0b823ac..f3d775408ecbd5 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 @@ -317,6 +317,8 @@ suite("test_date_function") { // NOW def now_result = sql """ select now() """ assertTrue(now_result[0].size() == 1) + def now_null_result = sql """ select now(null) """ + assertTrue(now_null_result[0].size() == 1) // SECOND qt_sql """ select second('2018-12-31 23:59:59') """