[Bug](function) fix current_date not equal to curdate (#11463)

* fix current_date not equal to curdate
This commit is contained in:
Pxl
2022-08-04 09:25:50 +08:00
committed by GitHub
parent 33053ad1fe
commit ce68d24e95
5 changed files with 21 additions and 5 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -745,7 +745,7 @@ public abstract class Expr extends TreeNode<Expr> 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());
}
}

View File

@ -341,3 +341,9 @@ February
-- !sql --
1 2022-08-01 17:00:31
-- !sql --
true
-- !sql --
true

View File

@ -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} """
}