Return-Path: X-Original-To: apmail-tajo-commits-archive@minotaur.apache.org Delivered-To: apmail-tajo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 949E511A96 for ; Fri, 16 May 2014 23:12:15 +0000 (UTC) Received: (qmail 19083 invoked by uid 500); 16 May 2014 10:16:28 -0000 Delivered-To: apmail-tajo-commits-archive@tajo.apache.org Received: (qmail 15838 invoked by uid 500); 16 May 2014 10:16:15 -0000 Mailing-List: contact commits-help@tajo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tajo.apache.org Delivered-To: mailing list commits@tajo.apache.org Received: (qmail 15303 invoked by uid 99); 16 May 2014 10:16:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 May 2014 10:16:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 41A90921C4F; Thu, 15 May 2014 23:34:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hyunsik@apache.org To: commits@tajo.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: TAJO-829: Same constants in groupby clause may cause planning error. Date: Thu, 15 May 2014 23:34:48 +0000 (UTC) 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 Authored: Wed May 14 15:04:41 2014 +0900 Committer: Hyunsik Choi 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 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 groupingColumns = new ArrayList(); - 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