You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/06/04 01:29:30 UTC

[incubator-doris] branch master updated: [Bug] Fix binaryPredicte's equals function ignore op (#3753)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new a8c95e7  [Bug] Fix binaryPredicte's equals function ignore op (#3753)
a8c95e7 is described below

commit a8c95e73690225e616ebb5038dca8496927d1964
Author: yangzhg <78...@qq.com>
AuthorDate: Thu Jun 4 09:29:19 2020 +0800

    [Bug] Fix binaryPredicte's equals function ignore op (#3753)
    
    BinaryPredicte's equals function compare by opcode ,
    but the opcode may not be inited yet.
    so it will return true if this child is same,  for example `a>1` and `a<1` are equal.
---
 fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java | 1 +
 fe/src/main/java/org/apache/doris/analysis/SelectStmt.java      | 4 +++-
 fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java  | 6 ++++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
index d722030..ad24571 100644
--- a/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
+++ b/fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
@@ -147,6 +147,7 @@ public class BinaryPredicate extends Predicate implements Writable {
     public BinaryPredicate(Operator op, Expr e1, Expr e2) {
         super();
         this.op = op;
+        this.opcode = op.opcode;
         Preconditions.checkNotNull(e1);
         children.add(e1);
         Preconditions.checkNotNull(e2);
diff --git a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 98f2102..f4e66f9 100644
--- a/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -437,6 +437,8 @@ public class SelectStmt extends QueryStmt {
         }
 
         if (whereClause != null) {
+            // do this before whereClause.analyze , some expr is not analyzed, this may cause some
+            // function not work as expected such as equals;
             whereClauseRewrite();
             if (checkGroupingFn(whereClause)) {
                 throw new AnalysisException("grouping operations are not allowed in WHERE.");
@@ -608,7 +610,7 @@ public class SelectStmt extends QueryStmt {
         if (clearExprs.size() == 1) {
             return makeCompound(clearExprs.get(0), CompoundPredicate.Operator.AND);
         }
-        // 2. find duplcate cross the clause
+        // 2. find duplicate cross the clause
         List<Expr> cloneExprs = new ArrayList<>(clearExprs.get(0));
         for (int i = 1; i < clearExprs.size(); ++i) {
             cloneExprs.retainAll(clearExprs.get(i));
diff --git a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
index 4ba9387..3cb0f2f 100644
--- a/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
+++ b/fe/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
@@ -312,6 +312,12 @@ public class SelectStmtTest {
         stmt8.rewriteExprs(new Analyzer(ctx.getCatalog(), ctx).getExprRewriter());
         Assert.assertTrue(stmt8.toSql().contains("((`t2`.`k1` IS NOT NULL) AND (`t1`.`k1` IS NOT NULL))" +
                 " AND (`t1`.`k1` IS NOT NULL)"));
+
+        String sql9 = "select * from db1.tbl1 where (k1='shutdown' and k4<1) or (k1='switchOff' and k4>=1)";
+        SelectStmt stmt9 = (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql9, ctx);
+        stmt9.rewriteExprs(new Analyzer(ctx.getCatalog(), ctx).getExprRewriter());
+        Assert.assertTrue(stmt9.toSql().contains("((`k1` = 'shutdown') AND (`k4` < 1))" +
+                " OR ((`k1` = 'switchOff') AND (`k4` >= 1))"));
     }
 
     @Test


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