You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/06/20 05:34:10 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #10241: [feature](Nereids)Add bind slot reference rules and support any/multi/group/multigroup with predicate pattern

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteBottomUpJob.java:
##########
@@ -72,12 +72,14 @@ public void execute() throws AnalysisException {
                 Preconditions.checkArgument(afters.size() == 1);
                 Plan after = afters.get(0);
                 if (after != before) {
-                    context.getOptimizerContext().getMemo().copyIn(after, group, rule.isRewrite());
+                    GroupExpression gexpr = context.getOptimizerContext()
+                            .getMemo()
+                            .copyIn(after, group, rule.isRewrite());
+                    gexpr.setApplied(rule);
                     pushTask(new RewriteBottomUpJob(group, rules, context, false));
                     return;
                 }
             }
-            logicalExpression.setApplied(rule);

Review Comment:
   this should not be removed



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/exceptions/AnalysisException.java:
##########
@@ -0,0 +1,32 @@
+// 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.exceptions;
+
+/** Nereids's AnalysisException. */
+public class AnalysisException extends RuntimeException {

Review Comment:
   👍🏻



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java:
##########
@@ -18,18 +18,22 @@
 package org.apache.doris.nereids.trees.expressions;
 
 import org.apache.doris.nereids.exceptions.UnboundException;
-import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
 import org.apache.doris.nereids.trees.AbstractTreeNode;
 import org.apache.doris.nereids.trees.NodeType;
 import org.apache.doris.nereids.types.DataType;
 
+import org.slf4j.Logger;

Review Comment:
   most of doris fe's class use log4j2 directly



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/physical/PhysicalProject.java:
##########
@@ -53,4 +55,9 @@ public String toString() {
     public <R, C> R accept(PlanOperatorVisitor<R, C> visitor, Plan plan, C context) {
         return visitor.visitPhysicalProject(((PhysicalUnaryPlan<PhysicalProject, Plan>) plan), context);
     }
+
+    @Override
+    public List<Expression> getExpressions() {
+        return ImmutableList.of();

Review Comment:
   why not return projects?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -54,11 +56,14 @@ public Group getRoot() {
      * @param rewrite whether to rewrite the node to the target group
      * @return Reference of node in Memo
      */
-    public GroupExpression copyIn(Plan node, Group target, boolean rewrite) {
-        Preconditions.checkArgument(!rewrite || target != null);

Review Comment:
   why remove this line?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -69,6 +74,20 @@ public GroupExpression copyIn(Plan node, Group target, boolean rewrite) {
         // TODO: need to derive logical property if generate new group. currently we not copy logical plan into
     }
 
+    public Plan copyOut() {

Review Comment:
   Add a comment stating that this function is only used for testing



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/pattern/GroupExpressionMatching.java:
##########
@@ -60,58 +59,101 @@ public GroupExpressionIterator<Plan> iterator() {
          * @param pattern pattern to match
          * @param groupExpression group expression to be matched
          */
-        public GroupExpressionIterator(Pattern<? extends NODE_TYPE, NODE_TYPE> pattern,
-                GroupExpression groupExpression) {
-            results = Lists.newArrayList();
-
+        public GroupExpressionIterator(Pattern<Plan, Plan> pattern, GroupExpression groupExpression) {
             if (!pattern.matchOperator(groupExpression.getOperator())) {
                 return;
             }
-            if (pattern.arity() > groupExpression.arity()) {
+
+            // (logicalFilter(), multi()) match (logicalFilter()),
+            // but (logicalFilter(), logicalFilter(), multi()) not match (logicalFilter())
+            boolean extraMulti = pattern.arity() == groupExpression.arity() + 1
+                    && (pattern.hasMultiChild() || pattern.hasMultiGroupChild());
+            if (pattern.arity() > groupExpression.arity() && !extraMulti) {
                 return;
             }
-            if (pattern.arity() < groupExpression.arity()
-                    && (!pattern.children().contains(Pattern.MULTI)
-                    || !pattern.children().contains(Pattern.MULTI_FIXED))) {
+
+            // (multi()) match (logicalFilter(), logicalFilter()),
+            // but (logicalFilter()) not match (logicalFilter(), logicalFilter())
+            if (!pattern.isAny() && pattern.arity() < groupExpression.arity()
+                    && !pattern.hasMultiChild() && !pattern.hasMultiGroupChild()) {
                 return;
             }
 
-            NODE_TYPE root = groupExpression.getOperator().toTreeNode(groupExpression);
-
-            List<List<NODE_TYPE>> childrenResults = Lists.newArrayListWithCapacity(groupExpression.arity());
-            for (int i = 0; i < groupExpression.arity(); ++i) {
-                childrenResults.add(Lists.newArrayList());
-                int patternChildIndex = i >= pattern.arity() ? pattern.arity() - 1 : i;
-                for (NODE_TYPE child : new GroupMatching<NODE_TYPE>(
-                        pattern.child(patternChildIndex), groupExpression.child(i))) {
-                    childrenResults.get(i).add(child);
-                }
+            // Pattern.GROUP / Pattern.MULTI / Pattern.MULTI_GROUP can not match GroupExpression
+            if (pattern.isGroup() || pattern.isMulti() || pattern.isMultiGroup()) {

Review Comment:
   where do we do multi match? or multi should not return?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Expression.java:
##########
@@ -18,18 +18,22 @@
 package org.apache.doris.nereids.trees.expressions;
 
 import org.apache.doris.nereids.exceptions.UnboundException;
-import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
 import org.apache.doris.nereids.trees.AbstractTreeNode;
 import org.apache.doris.nereids.trees.NodeType;
 import org.apache.doris.nereids.types.DataType;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.util.List;
 
 /**
  * Abstract class for all Expression in Nereids.
  */
 public abstract class Expression extends AbstractTreeNode<Expression> {
 
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());

Review Comment:
   should be static?



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org