From 3ae875d6cac3e0ed8915c2686d86cec1de747f01 Mon Sep 17 00:00:00 2001 From: seawinde Date: Thu, 12 Dec 2024 11:15:17 +0800 Subject: [PATCH] fix code usage --- .../exploration/mv/AbstractMaterializedViewRule.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java index 8789e07a165ac3..9339f0066a92a7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java @@ -42,6 +42,7 @@ import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE; import org.apache.doris.nereids.rules.rewrite.MergeProjects; import org.apache.doris.nereids.trees.expressions.Alias; +import org.apache.doris.nereids.trees.expressions.ComparisonPredicate; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.Not; @@ -137,6 +138,7 @@ public List rewrite(Plan queryPlan, CascadesContext cascadesContext) { rewrittenPlans.addAll(doRewrite(queryStructInfo, cascadesContext, context)); } } catch (Exception exception) { + LOG.warn("Materialized view rule exec fail", exception); context.recordFailReason(queryStructInfo, "Materialized view rule exec fail", exception::toString); } @@ -608,8 +610,14 @@ protected List rewriteExpression(List sourceEx // if contains any slot to rewrite, which means can not be rewritten by target, // expressionShuttledToRewrite is slot#0 > '2024-01-01' but mv plan output is date_trunc(slot#0, 'day') // which would try to rewrite + if (viewExprParamToDateTruncMap.isEmpty() + || expressionShuttledToRewrite.children().isEmpty() + || !(expressionShuttledToRewrite instanceof ComparisonPredicate)) { + // view doesn't have date_trunc, or + // expressionShuttledToRewrite is not ComparisonPredicate, bail out + return ImmutableList.of(); + } Expression queryShuttledExprParam = expressionShuttledToRewrite.child(0); - Expression queryOriginalExpr = sourceExpressionsToWrite.get(exprIndex); if (!queryExprToInfoMap.containsKey(queryOriginalExpr) || !viewExprParamToDateTruncMap.containsKey(queryShuttledExprParam)) {