tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-829: Same constants in groupby clause may cause planning error.
Date Thu, 15 May 2014 23:34:48 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.8.1 05cf59539 -> 9e2b31c2e


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/9e2b31c2
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/9e2b31c2
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/9e2b31c2

Branch: refs/heads/branch-0.8.1
Commit: 9e2b31c2ea3534f5014ee10004e40468ecd4c9fb
Parents: 05cf595
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed May 14 15:04:41 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Fri May 16 08:32:43 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/9e2b31c2/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 668ed68..d781f6b 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
@@ -200,6 +200,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);
@@ -543,12 +551,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));
       }
     }
 
@@ -576,9 +584,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/9e2b31c2/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 9e3c375..098a542 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/9e2b31c2/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/9e2b31c2/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


Mime
View raw message