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 2013/12/11 10:36:22 UTC
git commit: TAJO-410: A query with a combination of general and
distinct aggregation functions fails. (hyunsik)
Updated Branches:
refs/heads/master 2a3173757 -> df56fca7c
TAJO-410: A query with a combination of general and distinct aggregation functions fails. (hyunsik)
Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/df56fca7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/df56fca7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/df56fca7
Branch: refs/heads/master
Commit: df56fca7c0d47188497444052eeea9b0abc9cbf6
Parents: 2a31737
Author: Hyunsik Choi <hy...@apache.org>
Authored: Wed Dec 11 18:35:51 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Wed Dec 11 18:35:51 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 5 +++-
.../engine/planner/global/GlobalPlanner.java | 10 +++++++
.../tajo/engine/query/TestGroupByQuery.java | 28 ++++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/df56fca7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 00e6b3d..e7e8074 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -139,7 +139,10 @@ Release 0.8.0 - unreleased
BUG FIXES
- TAJO-404: TAJO-404: Tajo does not recognize boolean literal. (hyunsik)
+ TAJO-410: A query with a combination of general and distinct aggregation
+ functions fails. (hyunsik)
+
+ TAJO-404: Tajo does not recognize boolean literal. (hyunsik)
TAJO-344: Tajo cannot recognize negative numeric expressions. (hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/df56fca7/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
index f10408d..5ce8922 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/global/GlobalPlanner.java
@@ -173,6 +173,13 @@ public class GlobalPlanner {
return currentBlock;
}
+ /**
+ * If a query contains a distinct aggregation function, the query does not
+ * perform pre-aggregation in the first phase. Instead, in the fist phase,
+ * the query performs only hash shuffle. Then, the query performs the
+ * sort aggregation in the second phase. At that time, the aggregation
+ * function should be executed as the first phase.
+ */
private ExecutionBlock buildDistinctGroupBy(GlobalPlanContext context, ExecutionBlock childBlock,
GroupbyNode groupbyNode) {
// setup child block
@@ -187,6 +194,9 @@ public class GlobalPlanner {
for (AggregationFunctionCallEval function : functions) {
if (function.isDistinct()) {
columnsForDistinct.addAll(EvalTreeUtil.findDistinctRefColumns(function));
+ } else {
+ // See the comment of this method. the aggregation function should be executed as the first phase.
+ function.setFirstPhase();
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/df56fca7/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
index 3fd38ec..311dabb 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/query/TestGroupByQuery.java
@@ -138,6 +138,34 @@ public class TestGroupByQuery {
}
@Test
+ /**
+ * This is an unit test for a combination of aggregation and distinct aggregation functions.
+ */
+ public final void testCountDistinct2() throws Exception {
+ ResultSet res = tpch.execute(
+ "select l_orderkey, count(*) as cnt, count(distinct l_linenumber) as unique_key from lineitem " +
+ "group by l_orderkey");
+
+ long [][] expectedRows = new long[3][];
+ expectedRows[0] = new long [] {1,2,2};
+ expectedRows[1] = new long [] {2,1,1};
+ expectedRows[2] = new long [] {3,2,2};
+
+ Map<Long, long []> expected = Maps.newHashMap();
+ for (long [] expectedRow : expectedRows) {
+ expected.put(expectedRow[0], expectedRow);
+ }
+ for (int i = 0; i < expectedRows.length; i++) {
+ assertTrue(res.next());
+ long [] expectedRow = expected.get(res.getLong(1));
+ assertEquals(expectedRow[1], res.getLong(2));
+ assertEquals(expectedRow[2], res.getLong(3));
+ }
+ assertFalse(res.next());
+ res.close();
+ }
+
+ @Test
public final void testComplexParameter() throws Exception {
ResultSet res = tpch.execute(
"select sum(l_extendedprice*l_discount) as revenue from lineitem");