From 99c8d1fd61895e15859a29bdcfcd51f26293ed82 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Tue, 3 Dec 2024 11:13:19 +0800 Subject: [PATCH] fix failure tests --- src/DataTypes/EnumValues.h | 4 ++-- src/Interpreters/convertFieldToType.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/DataTypes/EnumValues.h b/src/DataTypes/EnumValues.h index ec5991abff1..352f91e2851 100644 --- a/src/DataTypes/EnumValues.h +++ b/src/DataTypes/EnumValues.h @@ -10,7 +10,7 @@ namespace DB namespace ErrorCodes { - extern const int BAD_ARGUMENTS; + extern const int UNKNOWN_ELEMENT_OF_ENUM; } template @@ -38,7 +38,7 @@ public: { auto it = value_to_name_map.find(value); if (it == value_to_name_map.end()) - throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unexpected value {} in enum", toString(value)); + throw Exception(ErrorCodes::UNKNOWN_ELEMENT_OF_ENUM, "Unexpected value {} in enum", toString(value)); return it; } diff --git a/src/Interpreters/convertFieldToType.cpp b/src/Interpreters/convertFieldToType.cpp index 8dd1eb56fbf..2d6f08eaffc 100644 --- a/src/Interpreters/convertFieldToType.cpp +++ b/src/Interpreters/convertFieldToType.cpp @@ -660,14 +660,18 @@ static bool decimalEqualsFloat(Field field, Float64 float_value) std::optional convertFieldToTypeStrict(const Field & from_value, const IDataType & from_type, const IDataType & to_type, const FormatSettings & format_settings) { + //Field result_value = convertFieldToType(from_value, to_type, &from_type, format_settings); + Field result_value; try { result_value = convertFieldToType(from_value, to_type, &from_type, format_settings); } - catch (...) + catch (Exception & e) { - return {}; + if (isEnum(from_type) && e.code() == ErrorCodes::UNKNOWN_ELEMENT_OF_ENUM) + return {}; + throw; } if (Field::isDecimal(from_value.getType()) && Field::isDecimal(result_value.getType()))