diff --git a/dbms/src/Functions/FunctionsConversion.h b/dbms/src/Functions/FunctionsConversion.h index a83ae586d80..b0fcc0103d6 100644 --- a/dbms/src/Functions/FunctionsConversion.h +++ b/dbms/src/Functions/FunctionsConversion.h @@ -1632,6 +1632,7 @@ private: using ToDataType = DataTypeDecimal; TypeIndex type_index = from_type->getTypeId(); + UInt32 precision = to_type->getPrecision(); UInt32 scale = to_type->getScale(); WhichDataType which(type_index); @@ -1645,9 +1646,9 @@ private: 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) + return [type_index, precision, scale] (Block & block, const ColumnNumbers & arguments, const size_t result, size_t input_rows_count) { - callOnIndexAndDataType(type_index, [&](const auto & types) -> bool + auto res = callOnIndexAndDataType(type_index, [&](const auto & types) -> bool { using Types = std::decay_t; using LeftDataType = typename Types::LeftType; @@ -1656,6 +1657,14 @@ private: ConvertImpl::execute(block, arguments, result, input_rows_count, scale); return true; }); + + /// Additionally check if callOnIndexAndDataType wasn't called at all. + if (!res) + { + auto to = DataTypeDecimal(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); + /// 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); }; }