You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ji...@apache.org on 2015/09/28 23:09:05 UTC

tajo git commit: TAJO-1894: Filter condition is ignored when a query involves multiple subqueries and aggregations.

Repository: tajo
Updated Branches:
  refs/heads/master cd01b739d -> 54e848e56


TAJO-1894: Filter condition is ignored when a query involves multiple subqueries and aggregations.

Closes #791


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

Branch: refs/heads/master
Commit: 54e848e56b6194974360564fa147c9463dfa94f8
Parents: cd01b73
Author: Jihoon Son <ji...@apache.org>
Authored: Tue Sep 29 06:08:30 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Tue Sep 29 06:08:30 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../tajo/engine/query/TestTableSubQuery.java    | 31 ++++++++++++++++++++
 ...stMultipleSubqueriesWithAggregation.1.result |  5 ++++
 .../plan/rewrite/rules/FilterPushDownRule.java  |  4 +++
 4 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/54e848e5/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 0048d37..25c2389 100644
--- a/CHANGES
+++ b/CHANGES
@@ -301,6 +301,9 @@ Release 0.11.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1894: Filter condition is ignored when a query involves multiple 
+    subqueries and aggregations. (jihoon)
+
     TAJO-1827: JSON parsing error at storage-site.json while tajo master
     starts up. (jaehwa)
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/54e848e5/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTableSubQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTableSubQuery.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTableSubQuery.java
index bc643ab..f59bac7 100644
--- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTableSubQuery.java
+++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestTableSubQuery.java
@@ -78,4 +78,35 @@ public class TestTableSubQuery extends QueryTestCaseBase {
     assertResultSet(res);
     cleanupQuery(res);
   }
+
+  @Test
+  @Option(sort = true)
+  @SimpleTest(
+      queries = @QuerySpec("" +
+          "select \n" +
+          "  o_custkey, cnt \n" +
+          "from \n" +
+          "  ( \n" +
+          "    select \n" +
+          "      o_custkey, cnt, row_number() over (partition by o_custkey order by cnt desc) ranking \n" +
+          "    from \n" +
+          "      (\n" +
+          "        select \n" +
+          "          o_custkey, l_suppkey, count(*) cnt\n" +
+          "        from \n" +
+          "          orders, lineitem\n" +
+          "        where \n" +
+          "          l_orderkey = o_orderkey\n" +
+          "        group by \n" +
+          "          o_custkey, l_suppkey\n" +
+          "        having cnt > 0\n" +
+          "      ) t\n" +
+          "  ) t2 \n" +
+          "where \n" +
+          "  ranking = 1;"
+      )
+  )
+  public void testMultipleSubqueriesWithAggregation() throws Exception {
+    runSimpleTests();
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/54e848e5/tajo-core-tests/src/test/resources/results/TestTableSubQuery/testMultipleSubqueriesWithAggregation.1.result
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/resources/results/TestTableSubQuery/testMultipleSubqueriesWithAggregation.1.result b/tajo-core-tests/src/test/resources/results/TestTableSubQuery/testMultipleSubqueriesWithAggregation.1.result
new file mode 100644
index 0000000..fea9f56
--- /dev/null
+++ b/tajo-core-tests/src/test/resources/results/TestTableSubQuery/testMultipleSubqueriesWithAggregation.1.result
@@ -0,0 +1,5 @@
+o_custkey,cnt
+-------------------------------
+2,1
+3,1
+4,1

http://git-wip-us.apache.org/repos/asf/tajo/blob/54e848e5/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 7d21622..e44bba5 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
@@ -532,9 +532,12 @@ public class FilterPushDownRule extends BasicLogicalPlanVisitor<FilterPushDownCo
   public LogicalNode visitTableSubQuery(FilterPushDownContext context, LogicalPlan plan, LogicalPlan.QueryBlock block,
                                         TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException {
     List<EvalNode> matched = TUtil.newList();
+    List<EvalNode> unmatched = TUtil.newList();
     for (EvalNode eval : context.pushingDownFilters) {
       if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, eval, node)) {
         matched.add(eval);
+      } else {
+        unmatched.add(eval);
       }
     }
 
@@ -544,6 +547,7 @@ public class FilterPushDownRule extends BasicLogicalPlanVisitor<FilterPushDownCo
     context.setFiltersTobePushed(transformedMap.keySet());
     visit(context, plan, plan.getBlock(node.getSubQuery()));
     context.setToOrigin(transformedMap);
+    context.addFiltersTobePushed(unmatched);
 
     return node;
   }