Skip to content

Commit 24a912c

Browse files
authored
[I1261]: printing datetime throws exceptions (#369)
* Added meaningful exception * check datetime year in range * Moved Date out of range check to Kql_datetime native function * Added try-ctach block for DateTime conversion to be within range
1 parent 859cef3 commit 24a912c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Functions/Kusto/kqlDateTime.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
namespace DB::ErrorCodes
1212
{
1313
extern const int LOGICAL_ERROR;
14+
extern const int BAD_ARGUMENTS;
1415
}
1516

1617
namespace
1718
{
19+
1820
enum class InputPolicy
1921
{
2022
Arbitrary,
@@ -77,7 +79,19 @@ ColumnPtr FunctionKqlDateTime<input_policy>::executeImpl(
7779

7880
const auto * const conversion_function
7981
= WhichDataType(*argument.type).isStringOrFixedString() ? getDateTimeParsingFunction(input_policy) : "toDateTime64";
80-
const auto converted = executeFunctionCall(context, conversion_function, conversion_args, input_rows_count);
82+
83+
std::pair<ColumnPtr, DataTypePtr> converted;
84+
try
85+
{
86+
converted = executeFunctionCall(context, conversion_function, conversion_args, input_rows_count);
87+
}
88+
catch (Exception & e)
89+
{
90+
if (e.code() == ErrorCodes::DECIMAL_OVERFLOW)
91+
throw DB::Exception(DB::ErrorCodes::BAD_ARGUMENTS, "Datetime out of range");
92+
93+
throw;
94+
}
8195

8296
const ColumnsWithTypeAndName addition_args{
8397
asArgument(converted, "converted"),

0 commit comments

Comments
 (0)