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/05/23 09:23:15 UTC

[GitHub] [incubator-doris] jackwener commented on a diff in pull request #9739: [Enhancement][fix] Add a rewrite rule to optimize InPredicate.

jackwener commented on code in PR #9739:
URL: https://github.com/apache/incubator-doris/pull/9739#discussion_r879216788


##########
fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteInPredicateRule.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.rewrite;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BoolLiteral;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.InPredicate;
+import org.apache.doris.analysis.LiteralExpr;
+import org.apache.doris.analysis.SlotRef;
+import org.apache.doris.analysis.Subquery;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.rewrite.ExprRewriter.ClauseType;
+
+import com.clearspring.analytics.util.Lists;
+
+import java.util.List;
+
+/**
+ * Optimize the InPredicate when the child expr type is integerType, largeIntType, floatingPointType, decimalV2,
+ * char, varchar, string and the column type is integerType, largeIntType: convert the child expr type to the column
+ * type and discard the expressions that cannot be converted exactly.
+ * <p>
+ * For example:
+ * column type is integerType or largeIntType, then
+ * col in (1, 2.5, 2.0, "3.0", "4.6") -> col in (1, 2, 3)
+ * col in (2.5, "4.6") -> false
+ * <p>
+ * column type is tinyType, then
+ * col in (1, 2.0, 128, "1000") -> col in (1, 2)
+ */
+public class RewriteInPredicateRule implements ExprRewriteRule {
+    public static ExprRewriteRule INSTANCE = new RewriteInPredicateRule();
+
+    @Override
+    public Expr apply(Expr expr, Analyzer analyzer, ClauseType clauseType) throws AnalysisException {
+        if (!(expr instanceof InPredicate)) {
+            return expr;
+        }
+        InPredicate inPredicate = (InPredicate) expr;
+        if (inPredicate.contains(Subquery.class) || !inPredicate.isLiteralChildren() || inPredicate.isNotIn() ||

Review Comment:
   Please notice that `checkstyle`, you can see this [doc](https://doris.apache.org/zh-CN/developer-guide/java-format-code.html#import-order)



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