Fixed tests

This commit is contained in:
Maksim Kita 2021-04-22 00:19:01 +03:00
parent 631d870ae3
commit ddcffcb723
2 changed files with 18 additions and 23 deletions

View File

@ -360,7 +360,8 @@ inline bool isEnum(const DataTypePtr & data_type) { return WhichDataType(data_ty
inline bool isDecimal(const DataTypePtr & data_type) { return WhichDataType(data_type).isDecimal(); } inline bool isDecimal(const DataTypePtr & data_type) { return WhichDataType(data_type).isDecimal(); }
inline bool isTuple(const DataTypePtr & data_type) { return WhichDataType(data_type).isTuple(); } inline bool isTuple(const DataTypePtr & data_type) { return WhichDataType(data_type).isTuple(); }
inline bool isArray(const DataTypePtr & data_type) { return WhichDataType(data_type).isArray(); } inline bool isArray(const DataTypePtr & data_type) { return WhichDataType(data_type).isArray(); }
inline bool isMap(const DataTypePtr & data_type) {return WhichDataType(data_type).isMap(); } inline bool isMap(const DataTypePtr & data_type) { return WhichDataType(data_type).isMap(); }
inline bool isNothing(const DataTypePtr & data_type) { return WhichDataType(data_type).isNothing(); }
template <typename T> template <typename T>
inline bool isUInt8(const T & data_type) inline bool isUInt8(const T & data_type)

View File

@ -2496,7 +2496,7 @@ private:
} }
} }
WrapperType createArrayWrapper(const DataTypePtr & from_type_untyped, const DataTypeArray * to_type) const WrapperType createArrayWrapper(const DataTypePtr & from_type_untyped, const DataTypeArray & to_type) const
{ {
/// Conversion from String through parsing. /// Conversion from String through parsing.
if (checkAndGetDataType<DataTypeString>(from_type_untyped.get())) if (checkAndGetDataType<DataTypeString>(from_type_untyped.get()))
@ -2507,27 +2507,23 @@ private:
}; };
} }
DataTypePtr from_nested_type;
DataTypePtr to_nested_type;
const auto * from_type = checkAndGetDataType<DataTypeArray>(from_type_untyped.get()); const auto * from_type = checkAndGetDataType<DataTypeArray>(from_type_untyped.get());
if (!from_type)
/// get the most nested type
if (from_type && to_type)
{ {
from_nested_type = from_type->getNestedType(); throw Exception(ErrorCodes::TYPE_MISMATCH,
to_nested_type = to_type->getNestedType(); "CAST AS Array can only be perforamed between same-dimensional Array or String types");
}
if (from_type->getNumberOfDimensions() != to_type->getNumberOfDimensions()) DataTypePtr from_nested_type = from_type->getNestedType();
{
WhichDataType from_nested_data_type(from_nested_type);
/// In query SELECT CAST([] AS Array(Array(String))) from type is Array(Nothing) /// In query SELECT CAST([] AS Array(Array(String))) from type is Array(Nothing)
bool is_empty_array = from_nested_data_type.isNothing(); bool from_empty_array = isNothing(from_nested_type);
if (!is_empty_array)
if (from_type->getNumberOfDimensions() != to_type.getNumberOfDimensions() && !from_empty_array)
throw Exception(ErrorCodes::TYPE_MISMATCH, throw Exception(ErrorCodes::TYPE_MISMATCH,
"CAST AS Array can only be performed between same-dimensional array types or from String"); "CAST AS Array can only be perforamed between same-dimensional array types");
}
} const DataTypePtr & to_nested_type = to_type.getNestedType();
/// 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);
@ -3093,14 +3089,12 @@ private:
return createStringWrapper(from_type); return createStringWrapper(from_type);
case TypeIndex::FixedString: case TypeIndex::FixedString:
return createFixedStringWrapper(from_type, checkAndGetDataType<DataTypeFixedString>(to_type.get())->getN()); return createFixedStringWrapper(from_type, checkAndGetDataType<DataTypeFixedString>(to_type.get())->getN());
case TypeIndex::Array: case TypeIndex::Array:
return createArrayWrapper(from_type, checkAndGetDataType<DataTypeArray>(to_type.get())); return createArrayWrapper(from_type, static_cast<const DataTypeArray &>(*to_type));
case TypeIndex::Tuple: case TypeIndex::Tuple:
return createTupleWrapper(from_type, checkAndGetDataType<DataTypeTuple>(to_type.get())); return createTupleWrapper(from_type, checkAndGetDataType<DataTypeTuple>(to_type.get()));
case TypeIndex::Map: case TypeIndex::Map:
return createMapWrapper(from_type, checkAndGetDataType<DataTypeMap>(to_type.get())); return createMapWrapper(from_type, checkAndGetDataType<DataTypeMap>(to_type.get()));
case TypeIndex::AggregateFunction: case TypeIndex::AggregateFunction:
return createAggregateFunctionWrapper(from_type, checkAndGetDataType<DataTypeAggregateFunction>(to_type.get())); return createAggregateFunctionWrapper(from_type, checkAndGetDataType<DataTypeAggregateFunction>(to_type.get()));
default: default: