fix failure tests

This commit is contained in:
zhanglistar 2024-12-03 11:13:19 +08:00
parent 0e30bd3b72
commit 99c8d1fd61
2 changed files with 8 additions and 4 deletions

View File

@ -10,7 +10,7 @@ namespace DB
namespace ErrorCodes namespace ErrorCodes
{ {
extern const int BAD_ARGUMENTS; extern const int UNKNOWN_ELEMENT_OF_ENUM;
} }
template <typename T> template <typename T>
@ -38,7 +38,7 @@ public:
{ {
auto it = value_to_name_map.find(value); auto it = value_to_name_map.find(value);
if (it == value_to_name_map.end()) 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; return it;
} }

View File

@ -660,14 +660,18 @@ static bool decimalEqualsFloat(Field field, Float64 float_value)
std::optional<Field> convertFieldToTypeStrict(const Field & from_value, const IDataType & from_type, const IDataType & to_type, const FormatSettings & format_settings) std::optional<Field> 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; Field result_value;
try try
{ {
result_value = convertFieldToType(from_value, to_type, &from_type, format_settings); 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())) if (Field::isDecimal(from_value.getType()) && Field::isDecimal(result_value.getType()))