mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 17:41:59 +00:00
Added more checks in CAST function.
This commit is contained in:
parent
ef7d19e143
commit
50c39e8b86
@ -1632,6 +1632,7 @@ private:
|
|||||||
using ToDataType = DataTypeDecimal<FieldType>;
|
using ToDataType = DataTypeDecimal<FieldType>;
|
||||||
|
|
||||||
TypeIndex type_index = from_type->getTypeId();
|
TypeIndex type_index = from_type->getTypeId();
|
||||||
|
UInt32 precision = to_type->getPrecision();
|
||||||
UInt32 scale = to_type->getScale();
|
UInt32 scale = to_type->getScale();
|
||||||
|
|
||||||
WhichDataType which(type_index);
|
WhichDataType which(type_index);
|
||||||
@ -1645,9 +1646,9 @@ private:
|
|||||||
throw Exception{"Conversion from " + from_type->getName() + " to " + to_type->getName() + " is not supported",
|
throw Exception{"Conversion from " + from_type->getName() + " to " + to_type->getName() + " is not supported",
|
||||||
ErrorCodes::CANNOT_CONVERT_TYPE};
|
ErrorCodes::CANNOT_CONVERT_TYPE};
|
||||||
|
|
||||||
return [type_index, scale] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t input_rows_count)
|
return [type_index, precision, scale] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t input_rows_count)
|
||||||
{
|
{
|
||||||
callOnIndexAndDataType<ToDataType>(type_index, [&](const auto & types) -> bool
|
auto res = callOnIndexAndDataType<ToDataType>(type_index, [&](const auto & types) -> bool
|
||||||
{
|
{
|
||||||
using Types = std::decay_t<decltype(types)>;
|
using Types = std::decay_t<decltype(types)>;
|
||||||
using LeftDataType = typename Types::LeftType;
|
using LeftDataType = typename Types::LeftType;
|
||||||
@ -1656,6 +1657,14 @@ private:
|
|||||||
ConvertImpl<LeftDataType, RightDataType, NameCast>::execute(block, arguments, result, input_rows_count, scale);
|
ConvertImpl<LeftDataType, RightDataType, NameCast>::execute(block, arguments, result, input_rows_count, scale);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// Additionally check if callOnIndexAndDataType wasn't called at all.
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
auto to = DataTypeDecimal<FieldType>(precision, scale);
|
||||||
|
throw Exception{"Conversion from " + std::string(getTypeName(type_index)) + " to " + to.getName() +
|
||||||
|
" is not supported", ErrorCodes::CANNOT_CONVERT_TYPE};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2022,6 +2031,11 @@ private:
|
|||||||
|
|
||||||
const auto & tmp_res = tmp_block.getByPosition(tmp_res_index);
|
const auto & tmp_res = tmp_block.getByPosition(tmp_res_index);
|
||||||
|
|
||||||
|
/// May happen in fuzzy tests. For debug purpose.
|
||||||
|
if (!tmp_res.column)
|
||||||
|
throw Exception("Couldn't convert " + block.getByPosition(arguments[0]).type->getName() + " to "
|
||||||
|
+ nested_type->getName() + " in " + " prepareRemoveNullable wrapper.", ErrorCodes::LOGICAL_ERROR);
|
||||||
|
|
||||||
res.column = wrapInNullable(tmp_res.column, Block({block.getByPosition(arguments[0]), tmp_res}), {0}, 1, input_rows_count);
|
res.column = wrapInNullable(tmp_res.column, Block({block.getByPosition(arguments[0]), tmp_res}), {0}, 1, input_rows_count);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user