Cast to array from empty array

This commit is contained in:
Maksim Kita 2021-04-21 20:29:49 +03:00
parent 3604aa92f8
commit 631d870ae3
3 changed files with 14 additions and 7 deletions

View File

@ -2517,14 +2517,17 @@ private:
from_nested_type = from_type->getNestedType(); from_nested_type = from_type->getNestedType();
to_nested_type = to_type->getNestedType(); to_nested_type = to_type->getNestedType();
from_type = checkAndGetDataType<DataTypeArray>(from_nested_type.get()); if (from_type->getNumberOfDimensions() != to_type->getNumberOfDimensions())
to_type = checkAndGetDataType<DataTypeArray>(to_nested_type.get()); {
} WhichDataType from_nested_data_type(from_nested_type);
/// both from_type and to_type should be nullptr now is array types had same dimensions /// In query SELECT CAST([] AS Array(Array(String))) from type is Array(Nothing)
if ((from_type == nullptr) != (to_type == nullptr)) bool is_empty_array = from_nested_data_type.isNothing();
throw Exception{"CAST AS Array can only be performed between same-dimensional array types or from String", if (!is_empty_array)
ErrorCodes::TYPE_MISMATCH}; throw Exception(ErrorCodes::TYPE_MISMATCH,
"CAST AS Array can only be performed between same-dimensional array types or from String");
}
}
/// Prepare nested type conversion /// Prepare nested type conversion
const auto nested_function = prepareUnpackDictionaries(from_nested_type, to_nested_type); const auto nested_function = prepareUnpackDictionaries(from_nested_type, to_nested_type);

View File

@ -0,0 +1,2 @@
[]
[]

View File

@ -0,0 +1,2 @@
SELECT CAST([] AS Array(Array(String)));
SELECT CAST([] AS Array(Array(Array(String))));