diff --git a/src/DataTypes/getLeastSupertype.cpp b/src/DataTypes/getLeastSupertype.cpp index f8d10535be2..22f6a077504 100644 --- a/src/DataTypes/getLeastSupertype.cpp +++ b/src/DataTypes/getLeastSupertype.cpp @@ -530,4 +530,16 @@ DataTypePtr getLeastSupertype(const DataTypes & types) throw Exception(getExceptionMessagePrefix(types), ErrorCodes::NO_COMMON_TYPE); } +DataTypePtr tryGetLeastSupertype(const DataTypes & types) +{ + try + { + return getLeastSupertype(types); + } + catch (...) + { + return nullptr; + } +} + } diff --git a/src/DataTypes/getLeastSupertype.h b/src/DataTypes/getLeastSupertype.h index 57e011a0529..c35ec7d722c 100644 --- a/src/DataTypes/getLeastSupertype.h +++ b/src/DataTypes/getLeastSupertype.h @@ -14,4 +14,7 @@ namespace DB */ DataTypePtr getLeastSupertype(const DataTypes & types); +/// Same as above but return nullptr instead of throwing exception. +DataTypePtr tryGetLeastSupertype(const DataTypes & types); + } diff --git a/src/Storages/MergeTree/KeyCondition.cpp b/src/Storages/MergeTree/KeyCondition.cpp index 3d4e909cf60..8ce65211e3e 100644 --- a/src/Storages/MergeTree/KeyCondition.cpp +++ b/src/Storages/MergeTree/KeyCondition.cpp @@ -1306,7 +1306,10 @@ bool KeyCondition::tryParseAtomFromAST(const ASTPtr & node, ContextPtr context, } else { - DataTypePtr common_type = getLeastSupertype({key_expr_type_not_null, const_type}); + DataTypePtr common_type = tryGetLeastSupertype({key_expr_type_not_null, const_type}); + if (!common_type) + return false; + if (!const_type->equals(*common_type)) { castValueToType(common_type, const_value, const_type, node); diff --git a/tests/queries/0_stateless/02179_key_condition_no_common_type.reference b/tests/queries/0_stateless/02179_key_condition_no_common_type.reference new file mode 100644 index 00000000000..b63ba696b7a --- /dev/null +++ b/tests/queries/0_stateless/02179_key_condition_no_common_type.reference @@ -0,0 +1 @@ +0.9 diff --git a/tests/queries/0_stateless/02179_key_condition_no_common_type.sql b/tests/queries/0_stateless/02179_key_condition_no_common_type.sql new file mode 100644 index 00000000000..3d2adc3f2ee --- /dev/null +++ b/tests/queries/0_stateless/02179_key_condition_no_common_type.sql @@ -0,0 +1,9 @@ +drop table if exists t; + +create table t (c Decimal32(9)) engine MergeTree order by c; + +insert into t values (0.9); + +select * from t where c < 1.2; + +drop table t;