mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 18:12:02 +00:00
Merge pull request #58139 from zvonand/zvonand-issue-53190
Fix `accurateCastOrNull` for out-of-range DateTime
This commit is contained in:
commit
a30980c930
@ -1413,10 +1413,10 @@ inline bool tryParseImpl<DataTypeDate32>(DataTypeDate32::FieldType & x, ReadBuff
|
||||
template <>
|
||||
inline bool tryParseImpl<DataTypeDateTime>(DataTypeDateTime::FieldType & x, ReadBuffer & rb, const DateLUTImpl * time_zone, bool)
|
||||
{
|
||||
time_t tmp = 0;
|
||||
if (!tryReadDateTimeText(tmp, rb, *time_zone))
|
||||
time_t time = 0;
|
||||
if (!tryReadDateTimeText(time, rb, *time_zone))
|
||||
return false;
|
||||
x = static_cast<UInt32>(tmp);
|
||||
convertFromTime<DataTypeDateTime>(x, time);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1697,7 +1697,6 @@ struct ConvertThroughParsing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parseImpl<ToDataType>(vec_to[i], read_buffer, local_time_zone, precise_float_parsing);
|
||||
} while (false);
|
||||
}
|
||||
@ -3291,7 +3290,6 @@ private:
|
||||
{
|
||||
/// In case when converting to Nullable type, we apply different parsing rule,
|
||||
/// that will not throw an exception but return NULL in case of malformed input.
|
||||
|
||||
FunctionPtr function = FunctionConvertFromString<ToDataType, FunctionName, ConvertFromStringExceptionMode::Null>::create();
|
||||
return createFunctionAdaptor(function, from_type);
|
||||
}
|
||||
|
@ -36,6 +36,8 @@
|
||||
2023-05-30 14:38:20
|
||||
1970-01-01 00:00:19
|
||||
1970-01-01 19:26:40
|
||||
1970-01-01 00:00:00
|
||||
2106-02-07 06:28:15
|
||||
\N
|
||||
\N
|
||||
\N
|
||||
|
@ -39,9 +39,12 @@ SELECT accurateCastOrNull(number + 127, 'Int8') AS x FROM numbers (2) ORDER BY x
|
||||
SELECT accurateCastOrNull(-1, 'DateTime');
|
||||
SELECT accurateCastOrNull(5000000000, 'DateTime');
|
||||
SELECT accurateCastOrNull('1xxx', 'DateTime');
|
||||
select toString(accurateCastOrNull('2023-05-30 14:38:20', 'DateTime'), timezone());
|
||||
SELECT toString(accurateCastOrNull('2023-05-30 14:38:20', 'DateTime'), timezone());
|
||||
SELECT toString(accurateCastOrNull(19, 'DateTime'), 'UTC');
|
||||
SELECT toString(accurateCastOrNull(70000, 'DateTime'), 'UTC');
|
||||
-- need fixed timezone in these two lines
|
||||
SELECT toString(accurateCastOrNull('1965-05-30 14:38:20', 'DateTime'), timezone()) SETTINGS session_timezone = 'UTC';
|
||||
SELECT toString(accurateCastOrNull('2223-05-30 14:38:20', 'DateTime'), timezone()) SETTINGS session_timezone = 'UTC';
|
||||
|
||||
SELECT accurateCastOrNull(-1, 'Date');
|
||||
SELECT accurateCastOrNull(5000000000, 'Date');
|
||||
|
Loading…
Reference in New Issue
Block a user