You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2014/05/16 01:32:10 UTC

git commit: TAJO-829: Same constants in groupby clause may cause planning error.

Repository: tajo
Updated Branches:
  refs/heads/master 77fdbfb2e -> 1c21e8bb6


TAJO-829: Same constants in groupby clause may cause planning error.


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

Branch: refs/heads/master
Commit: 1c21e8bb692a33530cb804291517f57635b4b091
Parents: 77fdbfb
Author: Hyunsik Choi <hy...@apache.org>
Authored: Wed May 14 15:04:41 2014 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Wed May 14 15:04:41 2014 +0900

----------------------------------------------------------------------
 .../planner/rewrite/ProjectionPushDownRule.java   | 18 ++++++++++++------
 .../tajo/engine/query/TestGroupByQuery.java       |  5 +++--
 .../testGroupByWithSameConstantKeys1.sql          |  1 +
 .../testGroupByWithSameConstantKeys1.result       |  5 +++++
 4 files changed, 21 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/1c21e8bb/tajo-core/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java b/tajo-core/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
index c21c087..8e91dca 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/rewrite/ProjectionPushDownRule.java
@@ -199,6 +199,14 @@ public class ProjectionPushDownRule extends
     public String add(EvalNode evalNode) throws PlanningException {
       String name;
 
+      if (evalNode.getType() == EvalType.FIELD) {
+        FieldEval fieldEval = (FieldEval) evalNode;
+        if (nameToIdBiMap.containsKey(fieldEval.getName())) {
+          int refId = nameToIdBiMap.get(fieldEval.getName());
+          return getPrimaryName(refId);
+        }
+      }
+
       if (idToEvalBiMap.inverse().containsKey(evalNode)) {
         int refId = idToEvalBiMap.inverse().get(evalNode);
         return getPrimaryName(refId);
@@ -542,12 +550,12 @@ public class ProjectionPushDownRule extends
 
     // Getting grouping key names
     final int groupingKeyNum = node.getGroupingColumns().length;
-    String [] groupingKeyNames = null;
+    LinkedHashSet<String> groupingKeyNames = null;
     if (groupingKeyNum > 0) {
-      groupingKeyNames = new String[groupingKeyNum];
+      groupingKeyNames = Sets.newLinkedHashSet();
       for (int i = 0; i < groupingKeyNum; i++) {
         FieldEval fieldEval = new FieldEval(node.getGroupingColumns()[i]);
-        groupingKeyNames[i] = newContext.addExpr(fieldEval);
+        groupingKeyNames.add(newContext.addExpr(fieldEval));
       }
     }
 
@@ -575,9 +583,7 @@ public class ProjectionPushDownRule extends
     if (groupingKeyNum > 0 && groupingKeyNames != null) {
       // Restoring grouping key columns
       final List<Column> groupingColumns = new ArrayList<Column>();
-      for (int i = 0; i < groupingKeyNum; i++) {
-        String groupingKey = groupingKeyNames[i];
-
+      for (String groupingKey : groupingKeyNames) {
         Target target = context.targetListMgr.getTarget(groupingKey);
 
         // it rewrite grouping keys.

http://git-wip-us.apache.org/repos/asf/tajo/blob/1c21e8bb/tajo-core/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
index cf97090..1f8cb2a 100644
--- a/tajo-core/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
@@ -124,9 +124,10 @@ public class TestGroupByQuery extends QueryTestCaseBase {
   }
 
   @Test
-  public final void testGroupByWithConstantKeys1() throws Exception {
+  public final void testGroupByWithSameConstantKeys1() throws Exception {
+    // select l_partkey as a, '##' as b, '##' as c, count(*) d from lineitem group by a, b, c;
     ResultSet res = executeQuery();
-    System.out.println(resultSetToString(res));
+    assertResultSet(res);
     cleanupQuery(res);
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/1c21e8bb/tajo-core/src/test/resources/queries/TestGroupByQuery/testGroupByWithSameConstantKeys1.sql
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/queries/TestGroupByQuery/testGroupByWithSameConstantKeys1.sql b/tajo-core/src/test/resources/queries/TestGroupByQuery/testGroupByWithSameConstantKeys1.sql
new file mode 100644
index 0000000..47a7832
--- /dev/null
+++ b/tajo-core/src/test/resources/queries/TestGroupByQuery/testGroupByWithSameConstantKeys1.sql
@@ -0,0 +1 @@
+select l_partkey as a, '##' as b, '##' as c, count(*) d from lineitem group by a, b, c;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tajo/blob/1c21e8bb/tajo-core/src/test/resources/results/TestGroupByQuery/testGroupByWithSameConstantKeys1.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestGroupByQuery/testGroupByWithSameConstantKeys1.result b/tajo-core/src/test/resources/results/TestGroupByQuery/testGroupByWithSameConstantKeys1.result
new file mode 100644
index 0000000..b08b1bc
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestGroupByQuery/testGroupByWithSameConstantKeys1.result
@@ -0,0 +1,5 @@
+a,b,c,d
+-------------------------------
+1,##,##,2
+3,##,##,1
+2,##,##,2
\ No newline at end of file