fix crash on CAST exotic types to decimal

This commit is contained in:
chertus 2019-08-02 17:31:15 +03:00
parent 7015e5ca7d
commit fcc6a2c2be
4 changed files with 14 additions and 3 deletions

View File

@ -463,9 +463,8 @@ struct WhichDataType
{
TypeIndex idx;
/// For late initialization.
WhichDataType()
: idx(TypeIndex::Nothing)
WhichDataType(TypeIndex idx_ = TypeIndex::Nothing)
: idx(idx_)
{}
WhichDataType(const IDataType & data_type)

View File

@ -1634,6 +1634,17 @@ private:
TypeIndex type_index = from_type->getTypeId();
UInt32 scale = to_type->getScale();
WhichDataType which(type_index);
bool ok = which.isNativeInt() ||
which.isNativeUInt() ||
which.isDecimal() ||
which.isFloat() ||
which.isDateOrDateTime() ||
which.isStringOrFixedString();
if (!ok)
throw Exception{"Conversion from " + from_type->getName() + " to " + to_type->getName() + " is not supported",
ErrorCodes::CANNOT_CONVERT_TYPE};
return [type_index, scale] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t input_rows_count)
{
callOnIndexAndDataType<ToDataType>(type_index, [&](const auto & types) -> bool

View File

@ -0,0 +1 @@
select cast(toIntervalDay(1) as Nullable(Decimal(10, 10))); -- { serverError 70 }