[Fix](Planner) disable bitmap type in compare expression (#24792)

Problem:
be core because of bitmap calculation.

Reason:
when be check failed, it would core directly.

Example:
SELECT id_bitmap FROM test_bitmap WHERE id_bitmap IN (NULL) LIMIT 20;

Solved:
Forbidden this kind of expression in fe when analyze. And also forbid bitmap type comparing in other unsupported expressions.
This commit is contained in:
LiBinfeng
2023-09-27 16:57:06 +08:00
committed by GitHub
parent 0227292c85
commit 00e8d1c3b4
7 changed files with 53 additions and 2 deletions

View File

@ -474,7 +474,7 @@ public class BinaryPredicate extends Predicate implements Writable {
@Override
public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
super.analyzeImpl(analyzer);
this.checkIncludeBitmap();
// Ignore placeholder
if (getChild(0) instanceof PlaceHolderExpr || getChild(1) instanceof PlaceHolderExpr) {
return;

View File

@ -192,6 +192,9 @@ public class CaseExpr extends Expr {
if (caseExpr instanceof Subquery && !caseExpr.getType().isScalarType()) {
throw new AnalysisException("Subquery in case-when must return scala type");
}
if (caseExpr.getType().isBitmapType()) {
throw new AnalysisException("Unsupported bitmap type in expression: " + toSql());
}
whenType = caseExpr.getType();
lastCompatibleWhenExpr = children.get(0);
} else {
@ -226,6 +229,9 @@ public class CaseExpr extends Expr {
&& !((hasCaseExpr() && whenExpr instanceof Subquery || !checkSubquery(whenExpr)))) {
throw new AnalysisException("Only support subquery in binary predicate in case statement.");
}
if (whenExpr.getType().isBitmapType()) {
throw new AnalysisException("Unsupported bitmap type in expression: " + toSql());
}
// Determine maximum compatible type of the then exprs seen so far.
// We will add casts to them at the very end.
Expr thenExpr = children.get(i + 1);

View File

@ -1419,6 +1419,17 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
}
}
/**
* Checks whether comparing predicates' children include bitmap type.
*/
public void checkIncludeBitmap() throws AnalysisException {
for (int i = 0; i < children.size(); ++i) {
if (children.get(i).getType().isBitmapType()) {
throw new AnalysisException("Unsupported bitmap type in expression: " + toSql());
}
}
}
public Expr checkTypeCompatibility(Type targetType) throws AnalysisException {
if (!targetType.isComplexType() && !targetType.isAggStateType()
&& targetType.getPrimitiveType() == type.getPrimitiveType()) {

View File

@ -170,6 +170,7 @@ public class InPredicate extends Predicate {
@Override
public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
super.analyzeImpl(analyzer);
this.checkIncludeBitmap();
if (contains(Subquery.class)) {
// An [NOT] IN predicate with a subquery must contain two children, the second

View File

@ -492,7 +492,7 @@ public class QueryPlanTest extends TestWithFeService {
assertSQLPlanOrErrorMsgContains(
"select count(*) from test.bitmap_table where id2 = 1;",
"Bitmap type dose not support operand: `id2` = 1"
"Unsupported bitmap type in expression: `id2` = 1"
);
}

View File

@ -44,6 +44,39 @@ suite("test_bitmap_int") {
sql "DROP TABLE test_int_bitmap"
sql "DROP TABLE IF EXISTS test_bitmap"
sql """CREATE TABLE
`test_bitmap` (
`id` varchar(16) NOT NULL,
`id_bitmap` bitmap BITMAP_UNION NOT NULL
) DISTRIBUTED BY HASH (`id`) BUCKETS 1 PROPERTIES ("replication_num" = "1");"""
test {
sql """SELECT id_bitmap FROM test_bitmap WHERE (id_bitmap NOT IN (NULL) OR (1 = 1)) AND id_bitmap IS NOT NULL LIMIT 20;"""
exception "errCode"
}
test {
sql """SELECT id_bitmap FROM test_bitmap WHERE id_bitmap IN (NULL) LIMIT 20;"""
exception "errCode"
}
test {
sql """SELECT id_bitmap FROM test_bitmap WHERE id_bitmap = 1 LIMIT 20;"""
exception "errCode"
}
test {
sql """SELECT case id_bitmap when 1 then 1 else 0 FROM test_bitmap;"""
exception "errCode"
}
qt_sql64_4 """SELECT id_bitmap FROM test_bitmap WHERE id_bitmap is null LIMIT 20;"""
qt_sql64_5 """select case when 1 = 0 then bitmap_from_string('0') else bitmap_from_string('0') end as new_bitmap;"""
sql "DROP TABLE IF EXISTS test_bitmap"
}