Fix Illegal column Nothing while using arrayMap

This commit is contained in:
avogar 2022-05-09 15:42:59 +00:00
parent db06b98027
commit cbada6fe03
3 changed files with 26 additions and 0 deletions

View File

@ -275,6 +275,11 @@ ColumnPtr IExecutableFunction::executeWithoutSparseColumns(const ColumnsWithType
ColumnPtr IExecutableFunction::execute(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count, bool dry_run) const
{
/// Result type Nothing means that we don't need to execute function at all.
/// Example: select arrayMap(x -> 2 * x, []);
if (isNothing(result_type))
return result_type->createColumn();
if (useDefaultImplementationForSparseColumns())
{
size_t num_sparse_columns = 0;
@ -430,6 +435,15 @@ DataTypePtr IFunctionOverloadResolver::getReturnTypeWithoutLowCardinality(const
}
}
/// If one of the arguments is Nothing, then we won't really execute
/// the function and the result type should be also Nothing.
/// Example: select arrayMap(x -> 2 * x, []);
for (const auto & arg : arguments)
{
if (isNothing(arg.type))
return std::make_shared<DataTypeNothing>();
}
return getReturnTypeImpl(arguments);
}

View File

@ -0,0 +1,6 @@
[]
Array(Nothing)
[]
Array(Nothing)
[]
Array(Nothing)

View File

@ -0,0 +1,6 @@
select arrayMap(x -> 2 * x, []);
select toTypeName(arrayMap(x -> 2 * x, []));
select arrayMap((x, y) -> x + y, [], []);
select toTypeName(arrayMap((x, y) -> x + y, [], []));
select arrayMap((x, y) -> x + y, [], CAST([], 'Array(Int32)'));
select toTypeName(arrayMap((x, y) -> x + y, [], CAST([], 'Array(Int32)')));