tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1800: WHERE clause is ignored with UNION.
Date Sat, 05 Sep 2015 02:13:28 GMT
Repository: tajo
Updated Branches:
  refs/heads/master ea4443d8d -> fd4a3f80c


TAJO-1800: WHERE clause is ignored with UNION.

Closes #727


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

Branch: refs/heads/master
Commit: fd4a3f80c8adb65233ff3fbb1b99dd8585d44a7b
Parents: ea4443d
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Sat Sep 5 11:08:32 2015 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Sat Sep 5 11:08:32 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 .../tajo/engine/query/TestUnionQuery.java       |  7 ++++
 .../TestUnionQuery/testUnionAndFilter.sql       | 23 +++++++++++
 .../TestUnionQuery/testUnionAndFilter.plan      | 42 ++++++++++++++++++++
 .../TestUnionQuery/testUnionAndFilter.result    |  7 ++++
 .../plan/rewrite/rules/FilterPushDownRule.java  | 12 ++----
 6 files changed, 84 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 507293c..892cef0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -244,6 +244,8 @@ Release 0.11.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1800: WHERE clause is ignored with UNION. (hyunsik)
+
     TAJO-1815: Catalog store initialization with PostgreSQL failed.
     (Contributed by Jongyoung Park, Committed by hyunsik)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
index 21500e9..5d1321a 100644
--- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
+++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestUnionQuery.java
@@ -690,4 +690,11 @@ public class TestUnionQuery extends QueryTestCaseBase {
   public void testComplexUnion2() throws Exception {
     runSimpleTests();
   }
+
+  @Test
+  @Option(withExplain =  true)
+  @SimpleTest
+  public void testUnionAndFilter() throws Exception {
+    runSimpleTests();
+  }
 }

http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/tajo-core-tests/src/test/resources/queries/TestUnionQuery/testUnionAndFilter.sql
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/queries/TestUnionQuery/testUnionAndFilter.sql
b/tajo-core-tests/src/test/resources/queries/TestUnionQuery/testUnionAndFilter.sql
new file mode 100644
index 0000000..6d729a4
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/queries/TestUnionQuery/testUnionAndFilter.sql
@@ -0,0 +1,23 @@
+SELECT
+  c_custkey, ret
+FROM (
+  SELECT
+    c_custkey,
+    ROUND(sum(c_acctbal*15000000)/sum(15000000),4) as ret
+  FROM
+    customer
+  GROUP BY
+    c_custkey
+
+  UNION
+
+  SELECT
+    c_custkey,
+    ROUND(sum(c_acctbal*15000000)/sum(15000000),4) AS ret
+  FROM
+    customer
+  GROUP BY
+    c_custkey
+) a
+WHERE
+  ret > 0.02;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.plan
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.plan
b/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.plan
new file mode 100644
index 0000000..c8a0c13
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.plan
@@ -0,0 +1,42 @@
+explain
+-------------------------------
+TABLE_SUBQUERY(7) as default.a
+  => Targets: default.a.c_custkey (INT4), default.a.ret (FLOAT8)
+  => out schema: {(2) default.a.c_custkey (INT4), default.a.ret (FLOAT8)}
+  => in  schema: {(2) default.a.c_custkey (INT4), default.a.ret (FLOAT8)}
+   HAVING(14) (default.#SQ_0.ret (FLOAT8) > 0.02)
+      GROUP_BY(11)(c_custkey,ret)
+        => target list: default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)
+        => out schema:{(2) default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)}
+        => in schema:{(2) default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)}
+         TABLE_SUBQUERY(10) as default.#SQ_0
+           => Targets: default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)
+           => out schema: {(2) default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)}
+           => in  schema: {(2) default.#SQ_0.c_custkey (INT4), default.#SQ_0.ret (FLOAT8)}
+            UNION(6)
+               PROJECTION(5)
+                 => Targets: default.customer.c_custkey (INT4), round(?sum_5 (FLOAT8)
/ CAST (?sum_6 (INT8) AS FLOAT8),4) as ret
+                 => out schema: {(2) default.customer.c_custkey (INT4), ret (FLOAT8)}
+                 => in  schema: {(3) ?sum_5 (FLOAT8), ?sum_6 (INT8), default.customer.c_custkey
(INT4)}
+                  GROUP_BY(4)(c_custkey)
+                    => exprs: (sum(?multiply_4 (FLOAT8)),sum(15000000))
+                    => target list: default.customer.c_custkey (INT4), ?sum_5 (FLOAT8),
?sum_6 (INT8)
+                    => out schema:{(3) ?sum_5 (FLOAT8), ?sum_6 (INT8), default.customer.c_custkey
(INT4)}
+                    => in schema:{(3) ?multiply_4 (FLOAT8), default.customer.c_acctbal
(FLOAT8), default.customer.c_custkey (INT4)}
+                     SCAN(3) on default.customer
+                       => target list: default.customer.c_acctbal (FLOAT8), default.customer.c_custkey
(INT4), default.customer.c_acctbal (FLOAT8) * 1.5E7 as ?multiply_4
+                       => out schema: {(3) ?multiply_4 (FLOAT8), default.customer.c_acctbal
(FLOAT8), default.customer.c_custkey (INT4)}
+                       => in schema: {(8) default.customer.c_acctbal (FLOAT8), default.customer.c_address
(TEXT), default.customer.c_comment (TEXT), default.customer.c_custkey (INT4), default.customer.c_mktsegment
(TEXT), default.customer.c_name (TEXT), default.customer.c_nationkey (INT4), default.customer.c_phone
(TEXT)}
+               PROJECTION(2)
+                 => Targets: default.customer.c_custkey (INT4), round(?sum_2 (FLOAT8)
/ CAST (?sum_3 (INT8) AS FLOAT8),4) as ret
+                 => out schema: {(2) default.customer.c_custkey (INT4), ret (FLOAT8)}
+                 => in  schema: {(3) ?sum_2 (FLOAT8), ?sum_3 (INT8), default.customer.c_custkey
(INT4)}
+                  GROUP_BY(1)(c_custkey)
+                    => exprs: (sum(?multiply_1 (FLOAT8)),sum(15000000))
+                    => target list: default.customer.c_custkey (INT4), ?sum_2 (FLOAT8),
?sum_3 (INT8)
+                    => out schema:{(3) ?sum_2 (FLOAT8), ?sum_3 (INT8), default.customer.c_custkey
(INT4)}
+                    => in schema:{(3) ?multiply_1 (FLOAT8), default.customer.c_acctbal
(FLOAT8), default.customer.c_custkey (INT4)}
+                     SCAN(0) on default.customer
+                       => target list: default.customer.c_acctbal (FLOAT8), default.customer.c_custkey
(INT4), default.customer.c_acctbal (FLOAT8) * 1.5E7 as ?multiply_1
+                       => out schema: {(3) ?multiply_1 (FLOAT8), default.customer.c_acctbal
(FLOAT8), default.customer.c_custkey (INT4)}
+                       => in schema: {(8) default.customer.c_acctbal (FLOAT8), default.customer.c_address
(TEXT), default.customer.c_comment (TEXT), default.customer.c_custkey (INT4), default.customer.c_mktsegment
(TEXT), default.customer.c_name (TEXT), default.customer.c_nationkey (INT4), default.customer.c_phone
(TEXT)}

http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.result
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.result
b/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.result
new file mode 100644
index 0000000..8eb747b
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/results/TestUnionQuery/testUnionAndFilter.result
@@ -0,0 +1,7 @@
+c_custkey,ret
+-------------------------------
+4,2866.83
+1,711.56
+5,794.47
+3,7498.12
+2,121.65

http://git-wip-us.apache.org/repos/asf/tajo/blob/fd4a3f80/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java
----------------------------------------------------------------------
diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java
b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java
index 83bb700..7d21622 100644
--- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java
+++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/rules/FilterPushDownRule.java
@@ -801,6 +801,9 @@ public class FilterPushDownRule extends BasicLogicalPlanVisitor<FilterPushDownCo
           break;
         }
       }
+      if (groupByNode.getInSchema().containsAll(EvalTreeUtil.findUniqueColumns(copy))) {
+        isEvalAggrFunction = true;
+      }
       if (isEvalAggrFunction) {
         aggrEvals.add(copy);
         aggrEvalOrigins.add(eval);
@@ -812,7 +815,6 @@ public class FilterPushDownRule extends BasicLogicalPlanVisitor<FilterPushDownCo
     }
 
     // transform
-
     HavingNode workingHavingNode;
     if (havingNode != null) {
       workingHavingNode = havingNode;
@@ -1029,14 +1031,6 @@ public class FilterPushDownRule extends BasicLogicalPlanVisitor<FilterPushDownCo
     return simplePredicates;
   }
 
-  private static Datum[] extractPredicateValues(List<Predicate> predicates) {
-    Datum[] values = new Datum[predicates.size()];
-    for (int i = 0; i < values.length; i++) {
-      values[i] = predicates.get(i).value;
-    }
-    return values;
-  }
-
   private static Column[] extractColumns(Set<Predicate> predicates) {
     Column[] columns = new Column[predicates.size()];
     int i = 0;


Mime
View raw message