This is an automated email from the ASF dual-hosted git repository.
panxiaolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 89dc1f73b2 [Bug](materialized-view) make mv matched when preagg have
value column predicate contained in mv'where clause (#22779)
89dc1f73b2 is described below
commit 89dc1f73b2d2a247573b9fdc11eee4c5ac03f0e8
Author: Pxl <[email protected]>
AuthorDate: Wed Aug 9 19:17:55 2023 +0800
[Bug](materialized-view) make mv matched when preagg have value column
predicate contained in mv'where clause (#22779)
1. make mv matched when preagg have value column predicate contained in mv
'where clause
2. fix `org.apache.doris.common.AnalysisException: errCode = 2,
detailMessage = BITMAP_UNION need input a bitmap column, but input INVALID_TYPE`
3. make the error message more detailed when create mv stmt parse failed
---
.../doris/analysis/CreateMaterializedViewStmt.java | 4 +-
.../doris/catalog/MaterializedIndexMeta.java | 5 +-
.../mv/SelectMaterializedIndexWithAggregate.java | 19 ++++++--
regression-test/data/mv_p0/where/mvljc/mvljc.out | 19 ++++++++
.../suites/mv_p0/where/mvljc/mvljc.groovy | 56 ++++++++++++++++++++++
5 files changed, 94 insertions(+), 9 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
index 0ed198afe5..25dabac639 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateMaterializedViewStmt.java
@@ -452,14 +452,14 @@ public class CreateMaterializedViewStmt extends DdlStmt {
break;
case FunctionSet.BITMAP_UNION:
type = Type.BITMAP;
- if (analyzer != null && !baseType.isBitmapType()) {
+ if (!isReplay && analyzer != null && !baseType.isBitmapType())
{
throw new AnalysisException(
"BITMAP_UNION need input a bitmap column, but
input " + baseType.toString());
}
break;
case FunctionSet.HLL_UNION:
type = Type.HLL;
- if (analyzer != null && !baseType.isHllType()) {
+ if (!isReplay && analyzer != null && !baseType.isHllType()) {
throw new AnalysisException("HLL_UNION need input a hll
column, but input " + baseType.toString());
}
break;
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndexMeta.java
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndexMeta.java
index f7b50e5f2d..eb5e7b64a9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndexMeta.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndexMeta.java
@@ -316,7 +316,8 @@ public class MaterializedIndexMeta implements Writable,
GsonPostProcessable {
try {
stmt.analyze(analyzer);
} catch (Exception e) {
- LOG.warn("CreateMaterializedViewStmt analyze failed,
reason=" + e.getMessage());
+ LOG.warn("CreateMaterializedViewStmt analyze failed,
reason=", e);
+ return;
}
}
@@ -327,7 +328,7 @@ public class MaterializedIndexMeta implements Writable,
GsonPostProcessable {
Map<String, Expr> columnNameToDefineExpr =
stmt.parseDefineExpr(analyzer);
setColumnsDefineExpr(columnNameToDefineExpr);
} catch (Exception e) {
- LOG.warn("CreateMaterializedViewStmt parseDefineExpr failed,
reason=" + e.getMessage());
+ LOG.warn("CreateMaterializedViewStmt parseDefineExpr failed,
reason=", e);
}
} catch (Exception e) {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
index 062119947b..d9cbe99fd9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/SelectMaterializedIndexWithAggregate.java
@@ -21,10 +21,12 @@ import org.apache.doris.analysis.CreateMaterializedViewStmt;
import org.apache.doris.catalog.AggregateType;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.MaterializedIndex;
+import org.apache.doris.catalog.MaterializedIndexMeta;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.common.Pair;
import org.apache.doris.nereids.annotation.Developing;
import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.rules.rewrite.RewriteRuleFactory;
@@ -63,6 +65,7 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.util.ExpressionUtils;
+import org.apache.doris.planner.PlanNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -1014,6 +1017,10 @@ public class SelectMaterializedIndexWithAggregate
extends AbstractSelectMaterial
public boolean isBaseIndex() {
return index == scan.getTable().getBaseIndexId();
}
+
+ public MaterializedIndexMeta getMeta() {
+ return scan.getTable().getIndexMetaByIndexId(index);
+ }
}
/**
@@ -1029,11 +1036,13 @@ public class SelectMaterializedIndexWithAggregate
extends AbstractSelectMaterial
/**
* Predicates should not have value type columns.
*/
- private PreAggStatus checkPredicates(
- List<Expression> predicates,
- CheckContext checkContext) {
- return disablePreAggIfContainsAnyValueColumn(predicates, checkContext,
- "Predicate %s contains value column %s");
+ private PreAggStatus checkPredicates(List<Expression> predicates,
CheckContext checkContext) {
+ Set<String> indexConjuncts = PlanNode
+
.splitAndCompoundPredicateToConjuncts(checkContext.getMeta().getWhereClause()).stream()
+ .map(e -> new
NereidsParser().parseExpression(e.toSql()).toSql()).collect(Collectors.toSet());
+ return disablePreAggIfContainsAnyValueColumn(
+ predicates.stream().filter(e ->
!indexConjuncts.contains(e.toSql())).collect(Collectors.toList()),
+ checkContext, "Predicate %s contains value column %s");
}
/**
diff --git a/regression-test/data/mv_p0/where/mvljc/mvljc.out
b/regression-test/data/mv_p0/where/mvljc/mvljc.out
new file mode 100644
index 0000000000..9820aed6ff
--- /dev/null
+++ b/regression-test/data/mv_p0/where/mvljc/mvljc.out
@@ -0,0 +1,19 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !select_mv --
+1 2
+3 -6
+
+-- !select_mv --
+2
+2
+2
+2
+2
+2
+4
+4
+4
+4
+4
+4
+
diff --git a/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy
b/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy
new file mode 100644
index 0000000000..29ee41f9de
--- /dev/null
+++ b/regression-test/suites/mv_p0/where/mvljc/mvljc.groovy
@@ -0,0 +1,56 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+import org.codehaus.groovy.runtime.IOGroovyMethods
+
+suite ("mvljc") {
+ sql """ DROP TABLE IF EXISTS d_table; """
+ sql """set enable_nereids_planner=true"""
+ sql """
+ create table d_table(
+ k1 int null,
+ k2 int not null,
+ k3 bigint null,
+ k4 varchar(100) null
+ )
+ duplicate key (k1,k2,k3)
+ distributed BY hash(k1) buckets 3
+ properties("replication_num" = "1");
+ """
+
+ sql "insert into d_table select 1,1,1,'a';"
+ sql "insert into d_table select 2,2,2,'b';"
+ sql "insert into d_table select 3,-3,null,'c';"
+
+ createMV ("""CREATE MATERIALIZED VIEW mvljc AS SELECT k1, SUM(k2) FROM
d_table WHERE k3 < 2 or k2 < 0 GROUP BY k1;""")
+
+ sql "insert into d_table select 1,1,1,'a';"
+ sql "insert into d_table select 2,2,2,'b';"
+ sql "insert into d_table select 3,-3,null,'c';"
+
+ explain {
+ sql("SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP BY
k1 order by 1,2;")
+ contains "(mvljc)"
+ }
+ qt_select_mv "SELECT k1, SUM(k2) FROM d_table WHERE k3 < 2 or k2 < 0 GROUP
BY k1 order by 1,2;"
+
+ explain {
+ sql("SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE k3 <
2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;")
+ contains "(mvljc)"
+ }
+ qt_select_mv "SELECT a.k1 + 1 FROM ( SELECT k1, SUM(k2) FROM d_table WHERE
k3 < 2 or k2 < 0 GROUP BY k1 ) a, d_table order by 1;"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]