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/04/14 07:51:04 UTC

[GitHub] [incubator-doris] morrySnow commented on a diff in pull request #9018: [feature](optimizer): rewrite expr self compare

morrySnow commented on code in PR #9018:
URL: https://github.com/apache/incubator-doris/pull/9018#discussion_r850172078


##########
fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteSelfCmpRuleTest.java:
##########
@@ -0,0 +1,79 @@
+
+// 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.common.FeConstants;
+import org.apache.doris.common.Pair;
+import org.apache.doris.utframe.DorisAssert;
+import org.apache.doris.utframe.UtFrameUtils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+public class RewriteSelfCmpRuleTest {
+    private static final Logger LOG = LogManager.getLogger(RewriteSelfCmpRuleTest.class);
+
+    private static String baseDir = "fe";
+    private static String runningDir = baseDir + "/mocked/RewriteSelfCmpRuleTest/"
+            + UUID.randomUUID().toString() + "/";

Review Comment:
   nit: toString is not needed



##########
fe/fe-core/src/test/java/org/apache/doris/rewrite/RewriteSelfCmpRuleTest.java:
##########
@@ -0,0 +1,79 @@
+

Review Comment:
   nit: useless blank line



##########
fe/fe-core/src/main/java/org/apache/doris/rewrite/RewriteSelfCmpRule.java:
##########
@@ -0,0 +1,53 @@
+// 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.BoolLiteral;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.IsNullPredicate;
+import org.apache.doris.common.AnalysisException;
+
+/**
+ * Rewrites predicate which is self compare self like A = A.
+ * =, >= , <= , <=>: where col is not null;
+ * <, >, !=: where false;
+ */
+public class RewriteSelfCmpRule implements ExprRewriteRule {
+    public static ExprRewriteRule INSTANCE = new RewriteSelfCmpRule();
+
+    @Override
+    public Expr apply(Expr expr, Analyzer analyzer, ExprRewriter.ClauseType clauseType) throws AnalysisException {
+        if (!(expr instanceof BinaryPredicate) || !expr.getChild(0).equals(expr.getChild(1)))
+            return expr;
+
+        switch (((BinaryPredicate) expr).getOp()) {
+            case EQ:
+            case LE:
+            case GE:
+            case EQ_FOR_NULL:

Review Comment:
   equal for null return true if both side of op are null. so we need to return `BoolLiteral(true)` when op is `EQ_FOR_NULL`
   ref: https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html#operator_equal-to



##########
fe/fe-core/src/test/java/org/apache/doris/planner/PlannerTest.java:
##########
@@ -40,6 +40,7 @@
 import java.util.List;
 import java.util.UUID;
 
+

Review Comment:
   nit: redundant blank line



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