[fix](cast) Add validity check for date conversion for non-vectorization (#12608)

actual result
select cast("0.0000031417" as date);
+------------------------------+
| CAST('0.0000031417' AS DATE) |
+------------------------------+
| 2000-00-00 |
+------------------------------+

expect result
select cast("0.0000031417" as date);
+------------------------------+
| CAST('0.0000031417' AS DATE) |
+------------------------------+
| NULL |
+------------------------------+
This commit is contained in:
yinzhijian
2022-09-16 09:08:53 +08:00
committed by GitHub
parent d906e97f1b
commit a97f63141e
7 changed files with 60 additions and 18 deletions

View File

@ -54,15 +54,19 @@ bool DateTimeValue::check_range(uint32_t year, uint32_t month, uint32_t day, uin
uint16_t type) {
bool time = hour > (type == TIME_TIME ? TIME_MAX_HOUR : 23) || minute > 59 || second > 59 ||
microsecond > 999999;
return time || check_date(year, month, day);
if (type == TIME_TIME) {
return time;
} else {
return time || check_date(year, month, day);
}
}
bool DateTimeValue::check_date(uint32_t year, uint32_t month, uint32_t day) {
if (month != 0 && month <= 12 && day > s_days_in_month[month]) {
// Feb 29 in leap year is valid.
if (!(month == 2 && day == 29 && is_leap(year))) return true;
if (month == 2 && day == 29 && doris::is_leap(year)) return false;
if (year > 9999 || month == 0 || month > 12 || day > s_days_in_month[month] || day == 0) {
return true;
}
return year > 9999 || month > 12 || day > 31;
return false;
}
// The interval format is that with no delimiters