You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2016/10/22 05:33:30 UTC

[03/14] incubator-impala git commit: IMPALA-4325: StmtRewrite lost parentheses of CompoundPredicate

IMPALA-4325: StmtRewrite lost parentheses of CompoundPredicate

StmtRewrite lost parentheses of CompoundPredicate in pushNegationToOperands()
and leads to incorrect toSql() result. Even though this issue would not leads
to incorrect result of query, it makes user confuse of the logical operator
precedence of predicates shown in EXPLAIN statement.

Change-Id: I79bfc67605206e0e026293bf7032a88227a95623
Reviewed-on: http://gerrit.cloudera.org:8080/4753
Reviewed-by: Alex Behm <al...@cloudera.com>
Tested-by: Internal Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/f8d48b85
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/f8d48b85
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/f8d48b85

Branch: refs/heads/master
Commit: f8d48b8582b9e460c2e0e3dbb4881636f179ae73
Parents: 9ef9512
Author: Yuanhao Luo <lu...@software.ict.ac.cn>
Authored: Wed Oct 19 17:10:39 2016 +0800
Committer: Internal Jenkins <cl...@gerrit.cloudera.org>
Committed: Fri Oct 21 07:45:53 2016 +0000

----------------------------------------------------------------------
 .../java/org/apache/impala/analysis/Expr.java   |  6 ++++-
 .../queries/PlannerTest/subquery-rewrite.test   | 23 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/f8d48b85/fe/src/main/java/org/apache/impala/analysis/Expr.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/Expr.java b/fe/src/main/java/org/apache/impala/analysis/Expr.java
index 6eed7a8..23ae65f 100644
--- a/fe/src/main/java/org/apache/impala/analysis/Expr.java
+++ b/fe/src/main/java/org/apache/impala/analysis/Expr.java
@@ -238,6 +238,7 @@ abstract public class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
   }
   public boolean hasCost() { return evalCost_ >= 0; }
   public long getNumDistinctValues() { return numDistinctValues_; }
+  public boolean getPrintSqlInParens() { return printSqlInParens_; }
   public void setPrintSqlInParens(boolean b) { printSqlInParens_ = b; }
   public boolean isOnClauseConjunct() { return isOnClauseConjunct_; }
   public void setIsOnClauseConjunct(boolean b) { isOnClauseConjunct_ = b; }
@@ -1160,7 +1161,10 @@ abstract public class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
     if (root instanceof CompoundPredicate) {
       Expr left = pushNegationToOperands(root.getChild(0));
       Expr right = pushNegationToOperands(root.getChild(1));
-      return new CompoundPredicate(((CompoundPredicate)root).getOp(), left, right);
+      CompoundPredicate compoundPredicate =
+        new CompoundPredicate(((CompoundPredicate)root).getOp(), left, right);
+      compoundPredicate.setPrintSqlInParens(root.getPrintSqlInParens());
+      return compoundPredicate;
     }
 
     return root;

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/f8d48b85/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test b/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
index 060d470..1f52597 100644
--- a/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
+++ b/testdata/workloads/functional-planner/queries/PlannerTest/subquery-rewrite.test
@@ -99,6 +99,29 @@ PLAN-ROOT SINK
    predicates: bool_col = FALSE
    runtime filters: RF000 -> a.id, RF001 -> int_col
 ====
+# IMPALA-4325: Preserve parenthesis of expressions when rewriting subqueries
+select *
+from functional.alltypes t1
+where t1.int_col in
+  (select t2.int_col
+   from functional.alltypes t2
+   where (t2.int_col is not null and (t2.int_col < 0 or t2.int_col > 10)
+   or t2.bigint_col is not null and (t2.bigint_col < 0 or t2.bigint_col > 10)))
+---- PLAN
+PLAN-ROOT SINK
+|
+02:HASH JOIN [LEFT SEMI JOIN]
+|  hash predicates: t1.int_col = t2.int_col
+|  runtime filters: RF000 <- t2.int_col
+|
+|--01:SCAN HDFS [functional.alltypes t2]
+|     partitions=24/24 files=24 size=478.45KB
+|     predicates: (t2.int_col IS NOT NULL AND (t2.int_col < 0 OR t2.int_col > 10) OR t2.bigint_col IS NOT NULL AND (t2.bigint_col < 0 OR t2.bigint_col > 10))
+|
+00:SCAN HDFS [functional.alltypes t1]
+   partitions=24/24 files=24 size=478.45KB
+   runtime filters: RF000 -> t1.int_col
+====
 # Complex expression in the IN predicate
 select *
 from functional.alltypes t