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 2021/12/24 15:34:48 UTC

[GitHub] [incubator-doris] wangshuo128 commented on a change in pull request #7357: [feature] (planner) InferPredicate (#7096)

wangshuo128 commented on a change in pull request #7357:
URL: https://github.com/apache/incubator-doris/pull/7357#discussion_r775042289



##########
File path: fe/fe-core/src/main/java/org/apache/doris/rewrite/InferFiltersRule.java
##########
@@ -0,0 +1,523 @@
+// 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.rewrite;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.IsNullPredicate;
+import org.apache.doris.analysis.JoinOperator;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.analysis.TupleId;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.Pair;
+
+import com.google.common.collect.Sets;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.Map;
+
+/**
+ * The function of this rule is to derive a new predicate based on the current predicate.
+ * eg.
+ * t1.id = t2.id and t2.id = t3.id and t3.id = 100;
+ * -->
+ * t1.id = 100 and t2.id = 100 and t3.id = 100;
+ *
+ * 1. Register a new rule InferFiltersRule and add it to GlobalState.
+ * 2. Traverse Conjunct to construct on/where equivalence connection, numerical connection and isNullPredicate.
+ * 3. Use Warshall to infer all equivalence connections
+ * 4. Construct additional numerical connections and isNullPredicate
+ */
+public class InferFiltersRule implements ExprRewriteRule {
+    private final static Logger LOG = LogManager.getLogger(InferFiltersRule.class);
+    public static InferFiltersRule INSTANCE = new InferFiltersRule();
+
+    @Override
+    public Expr apply(Expr expr, Analyzer analyzer, ExprRewriter.ClauseType clauseType) throws AnalysisException {
+        if (expr == null) {
+            return null;
+        }
+        
+        if (!analyzer.enableInferPredicate() || clauseType == ExprRewriter.ClauseType.OTHERCLAUSE) {
+            return expr;
+        } 
+
+        // slotEqSlotExpr: Record existing and infer equivalent connections
+        List<Expr> slotEqSlotExpr =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnSlotEqSlotExpr() : new ArrayList<>();
+
+        // slotEqSlotDeDuplication: De-Duplication for slotEqSlotExpr
+        Set<Pair<Expr, Expr>> slotEqSlotDeDuplication =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnSlotEqSlotDeDuplication() : Sets.newHashSet();
+
+        // slotToLiteralExpr: Record existing and infer expr which slot and literal are equal
+        List<Expr> slotToLiteralExpr =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnSlotToLiteralExpr() : new ArrayList<>();
+
+        // slotToLiteralDeDuplication: De-Duplication for slotToLiteralExpr
+        Set<Pair<Expr, Expr>> slotToLiteralDeDuplication =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnSlotToLiteralDeDuplication() : Sets.newHashSet();
+
+        // newExprWithState: just record infer expr which slot and literal are equal and which is not null predicate
+        // false : Unexecutable intermediate results will be produced during the derivation process.
+        // true : The new expr will be add to expr.
+        List<Pair<Expr, Boolean>> newExprWithState = new ArrayList<>();
+
+        // isNullExpr: Record existing and infer not null predicate
+        List<Expr> isNullExpr =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnIsNullExpr() : new ArrayList<>();
+
+        //isNullDeDuplication: De-Duplication for isNullExpr
+        Set<Expr> isNullDeDuplication =
+                (clauseType == ExprRewriter.ClauseType.ONCLAUSE) ? analyzer.getOnIsNullDeDuplication() : Sets.newHashSet();
+
+
+        // exprToInteger/integerToExpr: function is easy to build warshall and newExprWithState
+        Map<Expr, Integer> exprToInteger = new HashMap<>();

Review comment:
       What's the meaning of integer in `exprToInteger` and `integerToExpr`? Names of variables should be as specific as possible.




-- 
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