morrySnow commented on code in PR #57741:
URL: https://github.com/apache/doris/pull/57741#discussion_r2522725317


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewExprReplacer.java:
##########
@@ -0,0 +1,114 @@
+// 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.
+
+package org.apache.doris.nereids.rules.exploration.mv;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.VirtualSlotReference;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction;
+import 
org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.algebra.Repeat;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Expression replacer which support to handle VirtualSlotReference, if 
replaceMap contained, just use it
+ */
+public class MaterializedViewExprReplacer extends 
DefaultExpressionRewriter<Void> {
+
+    private final Map<? extends Expression, ? extends Expression> replaceMap;
+    private final Plan queryTopPlan;
+    private final BitSet sourcePlanBitSet;
+    private boolean valid = true;
+
+    public MaterializedViewExprReplacer(
+            Map<? extends Expression, ? extends Expression> replaceMap,
+            Plan queryTopPlan,
+            BitSet sourcePlanBitSet) {
+        this.replaceMap = replaceMap;
+        this.queryTopPlan = queryTopPlan;
+        this.sourcePlanBitSet = sourcePlanBitSet;
+    }
+
+    public boolean isValid() {
+        return valid;
+    }
+
+    @Override
+    public Expression visit(Expression expr, Void context) {
+        if (!valid) {
+            return expr;
+        }
+        Expression replacedExpr = replaceMap.get(expr);
+        if (replacedExpr != null) {
+            return replacedExpr;
+        }
+        List<Expression> newChildren = new ArrayList<>();
+        boolean hasChanged = false;
+        for (Expression child : expr.children()) {
+            Expression newChild = child.accept(this, context);
+            if (!valid) {
+                return expr;
+            }
+            if (newChild != child) {
+                hasChanged = true;
+            }
+            newChildren.add(newChild);
+        }
+        return hasChanged ? expr.withChildren(newChildren) : expr;
+    }
+
+    @Override
+    public Expression visitSlot(Slot slot, Void context) {
+        if (!valid) {
+            return slot;
+        }
+        if (slot instanceof VirtualSlotReference) {
+            return handleVirtualSlot((VirtualSlotReference) slot, context);
+        }

Review Comment:
   why not override visitVirtualReference



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -672,7 +674,7 @@ protected List<Expression> rewriteExpression(List<? extends 
Expression> sourceEx
                 Expression dateTruncWithLiteral = ExpressionUtils.replace(
                         
viewExprParamToDateTruncMap.get(queryShuttledExprParam), datetruncMap);
                 Expression foldedExpressionWithLiteral = 
FoldConstantRuleOnFE.evaluate(dateTruncWithLiteral,
-                        new ExpressionRewriteContext(cascadesContext));
+                        new 
org.apache.doris.nereids.rules.expression.ExpressionRewriteContext(cascadesContext));

Review Comment:
   why use full name here?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewExprReplacer.java:
##########
@@ -0,0 +1,114 @@
+// 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.
+
+package org.apache.doris.nereids.rules.exploration.mv;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.expressions.VirtualSlotReference;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.GroupingScalarFunction;
+import 
org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.algebra.Repeat;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Expression replacer which support to handle VirtualSlotReference, if 
replaceMap contained, just use it
+ */
+public class MaterializedViewExprReplacer extends 
DefaultExpressionRewriter<Void> {
+
+    private final Map<? extends Expression, ? extends Expression> replaceMap;
+    private final Plan queryTopPlan;
+    private final BitSet sourcePlanBitSet;
+    private boolean valid = true;

Review Comment:
   what's the valid mean? add comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to