From 492ec6059c68359fed7b223af4548d3e446ce8a4 Mon Sep 17 00:00:00 2001 From: seawinde Date: Thu, 19 Sep 2024 11:57:24 +0800 Subject: [PATCH] fix comment --- .../AbstractMaterializedViewAggregateRule.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java index 26d53c30eda8ca..1a66eda2ad3eed 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java @@ -17,8 +17,10 @@ package org.apache.doris.nereids.rules.exploration.mv; +import org.apache.doris.catalog.Column; import org.apache.doris.catalog.MTMV; import org.apache.doris.common.Pair; +import org.apache.doris.mtmv.BaseTableInfo; import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.jobs.executor.Rewriter; import org.apache.doris.nereids.properties.DataTrait; @@ -65,6 +67,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Supplier; @@ -338,19 +341,21 @@ protected Expression tryRewriteExpression(StructInfo queryStructInfo, Expression */ @Override protected boolean canUnionRewrite(Plan queryPlan, MTMV mtmv, CascadesContext cascadesContext) { - // check query plan is contain the partition column + // Check query plan is contain the partition column + // Query plan in the current rule must contain aggregate node, because the rule pattern is + // Optional> logicalAggregateOptional = queryPlan.collectFirst(planTreeNode -> planTreeNode instanceof LogicalAggregate); if (!logicalAggregateOptional.isPresent()) { return true; } - List groupByExpressions = logicalAggregateOptional.get().getGroupByExpressions(); if (groupByExpressions.isEmpty()) { // Scalar aggregate can not compensate union all return false; } - String relatedCol = mtmv.getMvPartitionInfo().getRelatedCol(); + final String relatedCol = mtmv.getMvPartitionInfo().getRelatedCol(); + final BaseTableInfo relatedTableInfo = mtmv.getMvPartitionInfo().getRelatedTableInfo(); boolean canUnionRewrite = false; // Check the query plan group by expression contains partition col or not List groupByShuttledExpressions = @@ -358,7 +363,10 @@ protected boolean canUnionRewrite(Plan queryPlan, MTMV mtmv, CascadesContext cas for (Expression expression : groupByShuttledExpressions) { canUnionRewrite = !expression.collectToSet(expr -> expr instanceof SlotReference && ((SlotReference) expr).isColumnFromTable() - && ((SlotReference) expr).getColumn().get().getName().equals(relatedCol)).isEmpty(); + && Objects.equals(((SlotReference) expr).getColumn().map(Column::getName).orElse(null), + relatedCol) + && Objects.equals(((SlotReference) expr).getTable().map(BaseTableInfo::new).orElse(null), + relatedTableInfo)).isEmpty(); if (canUnionRewrite) { break; }