Merge pull request #19959 from depressed-pho/fix-segv-fromModifiedJulianDay

Fix a segfault in fromModifiedJulianDay()
This commit is contained in:
alexey-milovidov 2021-02-02 13:50:14 +03:00 committed by GitHub
commit 4d0973cf25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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 }; DataTypes argument_types = { from_type };
FunctionBaseImplPtr base; FunctionBaseImplPtr base;
auto call = [&](const auto & types) -> bool auto call = [&](const auto & types) -> bool
@ -185,7 +185,7 @@ namespace DB
* here causes a SEGV. So we must somehow create a * here causes a SEGV. So we must somehow create a
* dummy implementation and return it. * 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); return std::make_unique<FunctionBaseFromModifiedJulianDay<Name, DataTypeInt32, nullOnErrors>>(argument_types, return_type);
else else
// Should not happen. // Should not happen.

View File

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

View File

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