Merge pull request #6297 from 4ertus2/bugs

Fix crash on CAST exotic types to Decimal
This commit is contained in:
alexey-milovidov 2019-08-02 22:47:27 +03:00 committed by GitHub
commit 12a8bf20eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 }