You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by ji...@apache.org on 2015/09/28 23:19:33 UTC

tajo git commit: TAJO-1889: UndefinedColumnException when a query with table subquery is executed on self-describing tables.

Repository: tajo
Updated Branches:
  refs/heads/branch-0.11.0 31f79c423 -> 9b4c8abb8


TAJO-1889: UndefinedColumnException when a query with table subquery is executed on self-describing tables.


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/9b4c8abb
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/9b4c8abb
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/9b4c8abb

Branch: refs/heads/branch-0.11.0
Commit: 9b4c8abb8af495c2664d53b129fb7c338f6e8af3
Parents: 31f79c4
Author: Jihoon Son <ji...@apache.org>
Authored: Tue Sep 29 06:19:07 2015 +0900
Committer: Jihoon Son <ji...@apache.org>
Committed: Tue Sep 29 06:19:07 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/9b4c8abb/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 08a8d62..fe0a525 100644
--- a/CHANGES
+++ b/CHANGES
@@ -285,6 +285,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/9b4c8abb/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/9b4c8abb/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/9b4c8abb/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/9b4c8abb/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/9b4c8abb/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());