Fix a segfault in fromModifiedJulianDay()

It was crashing when the argument type was Nullable(T) where T was any integral type other than Int32.
This commit is contained in:
PHO 2021-02-02 12:36:40 +09:00
parent 8c0ec5105b
commit 5f7a852b92
3 changed files with 4 additions and 2 deletions

View File

@ -163,7 +163,7 @@ namespace DB
FunctionBaseImplPtr build(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override
{
const DataTypePtr & from_type = arguments[0].type;
const DataTypePtr & from_type = removeNullable(arguments[0].type);
DataTypes argument_types = { from_type };
FunctionBaseImplPtr base;
auto call = [&](const auto & types) -> bool
@ -185,7 +185,7 @@ namespace DB
* here causes a SEGV. So we must somehow create a
* dummy implementation and return it.
*/
if (WhichDataType(from_type).isNullable()) // Nullable(Nothing)
if (WhichDataType(from_type).isNothing()) // Nullable(Nothing)
return std::make_unique<FunctionBaseFromModifiedJulianDay<Name, DataTypeInt32, nullOnErrors>>(argument_types, return_type);
else
// Should not happen.

View File

@ -3,6 +3,7 @@ Invocation with constant
1858-11-17
2020-11-01
\N
\N
or null
2020-11-01
\N

View File

@ -5,6 +5,7 @@ SELECT fromModifiedJulianDay(-1);
SELECT fromModifiedJulianDay(0);
SELECT fromModifiedJulianDay(59154);
SELECT fromModifiedJulianDay(NULL);
SELECT fromModifiedJulianDay(CAST(NULL, 'Nullable(Int64)'));
SELECT fromModifiedJulianDay(-678942); -- { serverError 490 }
SELECT fromModifiedJulianDay(2973484); -- { serverError 490 }