You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/10/07 07:50:49 UTC
[doris] 06/06: [Fix](Planner) disable bitmap type in compare expression (#24792)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
commit b40fc3e61154760dc0db28d0f153b86d917da93d
Author: LiBinfeng <46...@users.noreply.github.com>
AuthorDate: Wed Sep 27 16:57:06 2023 +0800
[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.
---
.../org/apache/doris/analysis/BinaryPredicate.java | 1 +
.../java/org/apache/doris/analysis/CaseExpr.java | 6 ++++
.../main/java/org/apache/doris/analysis/Expr.java | 11 +++++++
.../org/apache/doris/analysis/InPredicate.java | 1 +
.../org/apache/doris/planner/QueryPlanTest.java | 2 +-
.../data/datatype_p0/bitmap/test_bitmap_int.out | Bin 315 -> 351 bytes
.../datatype_p0/bitmap/test_bitmap_int.groovy | 33 +++++++++++++++++++++
7 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
index 11504d9571c..adf579aa99a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
@@ -412,6 +412,7 @@ public class BinaryPredicate extends Predicate implements Writable {
@Override
public void analyzeImpl(Analyzer analyzer) throws AnalysisException {
super.analyzeImpl(analyzer);
+ this.checkIncludeBitmap();
for (Expr expr : children) {
if (expr instanceof Subquery) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
index 83fb77c120b..177c937c0d5 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CaseExpr.java
@@ -187,6 +187,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 {
@@ -221,6 +224,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);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
index 8615d3d8037..cdc662502b5 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
@@ -1334,6 +1334,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.getPrimitiveType() != PrimitiveType.ARRAY
&& targetType.getPrimitiveType() == type.getPrimitiveType()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java
index e041549ab71..349c761f9bd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/InPredicate.java
@@ -157,6 +157,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 of
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index d536e66a9fa..d5e0a75c54a 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -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"
);
}
diff --git a/regression-test/data/datatype_p0/bitmap/test_bitmap_int.out b/regression-test/data/datatype_p0/bitmap/test_bitmap_int.out
index a8066c8edaf..93c3c065b5c 100644
Binary files a/regression-test/data/datatype_p0/bitmap/test_bitmap_int.out and b/regression-test/data/datatype_p0/bitmap/test_bitmap_int.out differ
diff --git a/regression-test/suites/datatype_p0/bitmap/test_bitmap_int.groovy b/regression-test/suites/datatype_p0/bitmap/test_bitmap_int.groovy
index 8dccfd3b9b2..0b0d577d197 100644
--- a/regression-test/suites/datatype_p0/bitmap/test_bitmap_int.groovy
+++ b/regression-test/suites/datatype_p0/bitmap/test_bitmap_int.groovy
@@ -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"
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org