diff --git a/be/src/vec/runtime/vdatetime_value.cpp b/be/src/vec/runtime/vdatetime_value.cpp index 05a568f9ad..401856f48d 100644 --- a/be/src/vec/runtime/vdatetime_value.cpp +++ b/be/src/vec/runtime/vdatetime_value.cpp @@ -278,6 +278,11 @@ void VecDateTimeValue::set_zero(int type) { void VecDateTimeValue::set_type(int type) { _type = type; + if (type == TIME_DATE) { + _hour = 0; + _minute = 0; + _second = 0; + } } void VecDateTimeValue::set_max_time(bool neg) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java index 61b3bf116b..b1160a9118 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java @@ -309,11 +309,13 @@ public class DateLiteral extends LiteralExpr { this.year = dateTime.getYear(); this.month = dateTime.getMonthValue(); this.day = dateTime.getDayOfMonth(); - this.hour = dateTime.getHour(); - this.minute = dateTime.getMinute(); - this.second = dateTime.getSecond(); - this.microsecond = dateTime.get(ChronoField.MICRO_OF_SECOND); this.type = type; + if (type.equals(Type.DATETIME) || type.equals(Type.DATETIMEV2)) { + this.hour = dateTime.getHour(); + this.minute = dateTime.getMinute(); + this.second = dateTime.getSecond(); + this.microsecond = dateTime.get(ChronoField.MICRO_OF_SECOND); + } } public DateLiteral(DateLiteral other) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java index 5324a05e4c..746137af2c 100755 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java @@ -745,7 +745,7 @@ public abstract class Expr extends TreeNode implements ParseNode, Cloneabl try { return trySubstituteList(exprs, smap, analyzer, preserveRootTypes); } catch (Exception e) { - throw new IllegalStateException("Failed analysis after expr substitution.", e); + throw new IllegalStateException("Failed analysis after expr substitution: " + e.getMessage()); } } diff --git a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out index df4a4cd085..8b68ed3ee6 100644 --- a/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out +++ b/regression-test/data/query/sql_functions/datetime_functions/test_date_function.out @@ -341,3 +341,9 @@ February -- !sql -- 1 2022-08-01 17:00:31 +-- !sql -- +true + +-- !sql -- +true + diff --git a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy index 70e98134eb..8740bbc0a9 100644 --- a/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy +++ b/regression-test/suites/query/sql_functions/datetime_functions/test_date_function.groovy @@ -286,5 +286,8 @@ suite("test_date_function", "query") { qt_sql """ SELECT id,FROM_UNIXTIME(update_time,"%Y-%m-%d %H:%i:%s") FROM ${tableName} WHERE FROM_UNIXTIME(update_time,"%Y-%m-%d %H:%i:%s") LIKE '2022-08-01 00:00:00' ORDER BY id; """ qt_sql """ SELECT id,FROM_UNIXTIME(update_time,"%Y-%m-%d %H:%i:%s") FROM ${tableName} WHERE FROM_UNIXTIME(update_time,"%Y-%m-%d %H:%i:%s") = '2022-08-01 17:00:31' ORDER BY id; """ + qt_sql """SELECT CURDATE() = CURRENT_DATE();""" + qt_sql """SELECT unix_timestamp(CURDATE()) = unix_timestamp(CURRENT_DATE());""" + sql """ drop table ${tableName} """ }