@@ -58,7 +58,6 @@ namespace Setting
5858namespace ErrorCodes
5959{
6060extern const int LOGICAL_ERROR;
61- extern const int BAD_TYPE_OF_FIELD;
6261}
6362
6463// / Returns the prefix of like_pattern before the first wildcard, e.g. 'Hello\_World% ...' --> 'Hello\_World'
@@ -1982,19 +1981,6 @@ KeyCondition::RPNElement::RPNElement(Function function_, size_t key_column_, con
19821981{
19831982}
19841983
1985- static void castValueToType (const DataTypePtr & desired_type, Field & src_value, const DataTypePtr & src_type, const String & node_column_name)
1986- {
1987- try
1988- {
1989- src_value = convertFieldToType (src_value, *desired_type, src_type.get ());
1990- }
1991- catch (...)
1992- {
1993- throw Exception (ErrorCodes::BAD_TYPE_OF_FIELD, " Key expression contains comparison between inconvertible types: "
1994- " {} and {} inside {}" , desired_type->getName (), src_type->getName (), node_column_name);
1995- }
1996- }
1997-
19981984
19991985bool KeyCondition::extractAtomFromTree (const RPNBuilderTreeNode & node, RPNElement & out)
20001986{
@@ -2254,7 +2240,12 @@ bool KeyCondition::extractAtomFromTree(const RPNBuilderTreeNode & node, RPNEleme
22542240
22552241 if (!const_type->equals (*common_type))
22562242 {
2257- castValueToType (common_type, const_value, const_type, node.getColumnName ());
2243+ // Replace direct call that throws exception with try version
2244+ Field converted = tryConvertFieldToType (const_value, *common_type, const_type.get (), {});
2245+ if (converted.isNull ())
2246+ return false ;
2247+
2248+ const_value = converted;
22582249
22592250 // Need to set is_constant_transformed unless we're doing exact conversion
22602251 if (!key_expr_type_not_null->equals (*common_type))
0 commit comments