Repository: tajo Updated Branches: refs/heads/master 54e848e56 -> 72dd1c025
TAJO-1889: UndefinedColumnException when a query with table subquery is executed on self-describing tables. (jihoon) Closes #787 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/72dd1c02 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/72dd1c02 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/72dd1c02 Branch: refs/heads/master Commit: 72dd1c025fa0fe54a0161c26c01e2ae5d03d8bcb Parents: 54e848e Author: Jihoon Son <[email protected]> Authored: Tue Sep 29 06:17:29 2015 +0900 Committer: Jihoon Son <[email protected]> Committed: Tue Sep 29 06:17:29 2015 +0900 ---------------------------------------------------------------------- CHANGES | 3 + .../engine/query/TestQueryOnSelfDescTable.java | 63 ++++++++++++++++++++ .../testTableSubquery.1.result | 3 + .../testTableSubquery2.1.result | 3 + .../testTableSubquery3.1.result | 3 + .../plan/rewrite/SelfDescSchemaBuildPhase.java | 22 +++++-- 6 files changed, 93 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 25c2389..2f3904a 100644 --- a/CHANGES +++ b/CHANGES @@ -301,6 +301,9 @@ Release 0.11.0 - unreleased BUG FIXES + TAJO-1889: UndefinedColumnException when a query with table subquery is + executed on self-describing tables. (jihoon) + TAJO-1894: Filter condition is ignored when a query involves multiple subqueries and aggregations. (jihoon) http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestQueryOnSelfDescTable.java ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestQueryOnSelfDescTable.java b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestQueryOnSelfDescTable.java index 9ce46bc..84ebbc2 100644 --- a/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestQueryOnSelfDescTable.java +++ b/tajo-core-tests/src/test/java/org/apache/tajo/engine/query/TestQueryOnSelfDescTable.java @@ -69,6 +69,69 @@ public class TestQueryOnSelfDescTable extends QueryTestCaseBase { @Test @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select title1, title2, null_expected, sortas, abbrev from (\n" + + "select\n" + + " glossary.title title1,\n" + + " glossary.\"GlossDiv\".title title2,\n" + + " glossary.\"GlossDiv\".null_expected null_expected,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"SortAs\" sortas,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"Abbrev\" abbrev\n" + + "from\n" + + " self_desc_table2\n" + + " where glossary.title is not null" + + ") t" + ) + ) + public final void testTableSubquery() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select title1, title2, null_expected, sortas, abbrev from (\n" + + "select\n" + + " glossary.title title1,\n" + + " glossary.\"GlossDiv\".title title2,\n" + + " glossary.\"GlossDiv\".null_expected null_expected,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"SortAs\" sortas,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"Abbrev\" abbrev\n" + + "from\n" + + " self_desc_table2\n" + + ") t " + + "where title1 is not null" + ) + ) + public final void testTableSubquery2() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select title1, char_length(title2) len, null_expected, sortas, abbrev from (\n" + + "select\n" + + " glossary.title title1,\n" + + " glossary.\"GlossDiv\".title title2,\n" + + " glossary.\"GlossDiv\".null_expected null_expected,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"SortAs\" sortas,\n" + + " glossary.\"GlossDiv\".\"GlossList\".\"GlossEntry\".\"Abbrev\" abbrev\n" + + "from\n" + + " self_desc_table2\n" + + ") t " + + "where len > 1" + ) + ) + public final void testTableSubquery3() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) @SimpleTest public final void testGroupby() throws Exception { runSimpleTests(); http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery.1.result new file mode 100644 index 0000000..38a838b --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery.1.result @@ -0,0 +1,3 @@ +title1,title2,null_expected,sortas,abbrev +------------------------------- +example glossary,S,null,SGML,ISO 8879:1986 http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery2.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery2.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery2.1.result new file mode 100644 index 0000000..38a838b --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery2.1.result @@ -0,0 +1,3 @@ +title1,title2,null_expected,sortas,abbrev +------------------------------- +example glossary,S,null,SGML,ISO 8879:1986 http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery3.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery3.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery3.1.result new file mode 100644 index 0000000..5f91225 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testTableSubquery3.1.result @@ -0,0 +1,3 @@ +title1,len,null_expected,sortas,abbrev +------------------------------- +example glossary,1,null,SGML,ISO 8879:1986 http://git-wip-us.apache.org/repos/asf/tajo/blob/72dd1c02/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/SelfDescSchemaBuildPhase.java ---------------------------------------------------------------------- diff --git a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/SelfDescSchemaBuildPhase.java b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/SelfDescSchemaBuildPhase.java index 310f238..f609db2 100644 --- a/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/SelfDescSchemaBuildPhase.java +++ b/tajo-plan/src/main/java/org/apache/tajo/plan/rewrite/SelfDescSchemaBuildPhase.java @@ -144,6 +144,7 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { static class ProcessorContext { final PlanContext planContext; final Map<String, List<ColumnReferenceExpr>> projectColumns = new HashMap<>(); + final Set<String> aliasSet = new HashSet<>(); public ProcessorContext(PlanContext planContext) { this.planContext = planContext; @@ -175,6 +176,9 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { for (ColumnReferenceExpr col : columns) { TUtil.putToNestedList(ctx.projectColumns, col.getQualifier(), col); } + if (eachNamedExpr.hasAlias()) { + ctx.aliasSet.add(eachNamedExpr.getAlias()); + } } super.visitProjection(ctx, stack, expr); @@ -245,8 +249,10 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { public LogicalNode visitFilter(ProcessorContext ctx, Stack<Expr> stack, Selection expr) throws TajoException { Set<ColumnReferenceExpr> columnSet = ExprFinder.finds(expr.getQual(), OpType.Column); for (ColumnReferenceExpr col : columnSet) { - NameRefInSelectListNormalizer.normalize(ctx.planContext, col); - TUtil.putToNestedList(ctx.projectColumns, col.getQualifier(), col); + if (!ctx.aliasSet.contains(col.getName())) { + NameRefInSelectListNormalizer.normalize(ctx.planContext, col); + TUtil.putToNestedList(ctx.projectColumns, col.getQualifier(), col); + } } super.visitFilter(ctx, stack, expr); @@ -294,7 +300,11 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { @Override public LogicalNode visitSimpleTableSubquery(ProcessorContext ctx, Stack<Expr> stack, SimpleTableSubquery expr) throws TajoException { - super.visitSimpleTableSubquery(ctx, stack, expr); + QueryBlock childBlock = ctx.planContext.getPlan().getBlock( + ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); + ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); + + super.visitSimpleTableSubquery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery()); @@ -306,7 +316,11 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { @Override public LogicalNode visitTableSubQuery(ProcessorContext ctx, Stack<Expr> stack, TablePrimarySubQuery expr) throws TajoException { - super.visitTableSubQuery(ctx, stack, expr); + QueryBlock childBlock = ctx.planContext.getPlan().getBlock( + ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); + ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); + + super.visitTableSubQuery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery());
