924060929 commented on code in PR #12996:
URL: https://github.com/apache/doris/pull/12996#discussion_r996729772


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/InferPredicates.java:
##########
@@ -0,0 +1,123 @@
+// 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.rewrite.logical;
+
+import org.apache.doris.nereids.rules.PlanRuleFactory;
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RulePromise;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.plans.JoinType;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * infer additional predicates for filter and join.
+ */
+public class InferPredicates implements PlanRuleFactory {
+    PredicatePropagation propagation = new PredicatePropagation();
+    EffectivePredicatesExtractor predicatesExtractor = new 
EffectivePredicatesExtractor();
+
+    @Override
+    public List<Rule> buildRules() {
+        return ImmutableList.of(
+                inferWhere(),
+                inferOn()
+        );
+    }
+
+    private Rule inferWhere() {
+        return logicalFilter(any()).thenApply(ctx -> {
+            LogicalFilter<Plan> root = ctx.root;
+            Plan filter = 
ctx.cascadesContext.getMemo().copyOut(root.getGroupExpression().get(), false);
+            Set<Expression> filterPredicates = 
filter.accept(predicatesExtractor, null);
+            Set<Expression> filterChildPredicates = 
filter.child(0).accept(predicatesExtractor, null);
+            filterPredicates.removeAll(filterChildPredicates);
+            
ExpressionUtils.extractConjunction(root.getPredicates()).forEach(filterPredicates::remove);

Review Comment:
   I think this rule should process the current predicate, and not need to 
remove the predicate which exist in the child, this is the responsibility of 
another rule.
   keep the logical orthogonality too, and this rule will become more clarity, 
so you not need to copy out from the memo in the EffectivePredicateExtractor. 
and then, EffectivePredicateExtractor can be removed
   
   



-- 
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-unsubscr...@doris.apache.org

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


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

Reply via email to