Fix KeyCondition with no common types

This commit is contained in:
Amos Bird 2022-01-20 21:56:12 +08:00
parent 3e6c94929b
commit e62f4e50a6
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
5 changed files with 29 additions and 1 deletions

View File

@ -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;
}
}
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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;