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/06/13 12:11:15 UTC
git commit: TAJO-14: The ambiguous column error occurs when an alias
name is used as a sort key. (hyunsik)
Updated Branches:
refs/heads/master 9ca8d365d -> 08c57915b
TAJO-14: The ambiguous column error occurs when an alias name is used as a sort key. (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/08c57915
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/08c57915
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/08c57915
Branch: refs/heads/master
Commit: 08c57915bd9f91fc351c69313d0e1f202ff5464c
Parents: 9ca8d36
Author: Hyunsik Choi <hy...@apache.org>
Authored: Thu Jun 13 19:10:07 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Thu Jun 13 19:10:07 2013 +0900
----------------------------------------------------------------------
.../java/tajo/engine/parser/QueryAnalyzer.java | 38 +++++++++++---------
.../java/tajo/engine/query/TestSortQuery.java | 20 +++++++++++
2 files changed, 41 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/08c57915/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
index 36d00d3..09dac27 100644
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
@@ -896,6 +896,8 @@ public final class QueryAnalyzer {
Schema schema;
Column column = null;
int count = 0;
+
+ // find a column corresponding to the given column name from tables of the catalog
for(String table : tree.getAllTableNames()) {
desc =
catalog.getTableDesc(table);
@@ -905,30 +907,32 @@ public final class QueryAnalyzer {
column = schema.getColumn(table+"."+columnName);
count++;
}
+ }
- if (tree instanceof QueryBlock) {
- QueryBlock block = ((QueryBlock)tree);
- if (block.getTargetList() != null) {
- for (Target target : block.getTargetList()) {
- if (target.hasAlias() && target.getAlias().equals(columnName)) {
- try {
- column = (Column) target.getColumnSchema().clone();
- column.setName(target.getAlias());
- } catch (CloneNotSupportedException e) {
- e.printStackTrace();
- }
- count++;
+ // find a column corresponding to the given column name from the target list
+ if (tree instanceof QueryBlock) {
+ QueryBlock block = ((QueryBlock)tree);
+ if (block.getTargetList() != null) {
+ for (Target target : block.getTargetList()) {
+ if (target.hasAlias() && target.getAlias().equals(columnName)) {
+ try {
+ column = (Column) target.getColumnSchema().clone();
+ column.setName(target.getAlias());
+ } catch (CloneNotSupportedException e) {
+ e.printStackTrace();
}
+ count++;
}
}
}
-
- // if there are more than one column, we cannot expect
- // that this column belongs to which table.
- if(count > 1)
- throw new AmbiguousFieldException(columnName);
}
+ // if there are more than one column, we cannot exactly expect
+ // that this column belongs to which table.
+ if(count > 1)
+ throw new AmbiguousFieldException(columnName);
+
+
if(column == null) { // if there are no matched column
throw new InvalidQueryException("ERROR: column \"" + columnName
+ "\" does not exist");
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/08c57915/tajo-core/tajo-core-backend/src/test/java/tajo/engine/query/TestSortQuery.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/query/TestSortQuery.java b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/query/TestSortQuery.java
index 81a9fe7..2098367 100644
--- a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/query/TestSortQuery.java
+++ b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/query/TestSortQuery.java
@@ -116,4 +116,24 @@ public class TestSortQuery {
assertEquals(3, cnt);
}
+
+ @Test
+ public final void testSortAfterGroupbyWithAlias() throws Exception {
+ ResultSet res = tpch.execute("select max(l_quantity) as max_quantity, l_orderkey "
+ + "from lineitem group by l_orderkey order by max_quantity");
+
+ int cnt = 0;
+ Long prev = null;
+ while(res.next()) {
+ if (prev == null) {
+ prev = res.getLong(1);
+ } else {
+ assertTrue(prev <= res.getLong(1));
+ prev = res.getLong(1);
+ }
+ cnt++;
+ }
+
+ assertEquals(3, cnt);
+ }
}