Repository: tajo Updated Branches: refs/heads/master 51198d040 -> 145c17f74
TAJO-1912: Selection from aliased schemaless tables throws an error. Closes #807 Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/145c17f7 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/145c17f7 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/145c17f7 Branch: refs/heads/master Commit: 145c17f74b08877d19800b8e4da63a788f0021df Parents: 51198d0 Author: Jihoon Son <[email protected]> Authored: Thu Oct 8 17:21:39 2015 +0900 Committer: Jihoon Son <[email protected]> Committed: Thu Oct 8 17:21:39 2015 +0900 ---------------------------------------------------------------------- CHANGES | 3 + .../engine/query/TestQueryOnSelfDescTable.java | 98 ++++++++++++++++++++ .../testJoinAliasedTables.1.result | 4 + .../testJoinAliasedTables2.1.result | 3 + ...SelfDescTablesWithQualifiedColumns2.1.result | 3 + ...SelfDescTablesWithQualifiedColumns3.1.result | 3 + .../testSelectFromAliasedTable.1.result | 3 + .../plan/rewrite/SelfDescSchemaBuildPhase.java | 38 +++++--- 8 files changed, 141 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 23349a7..5870d67 100644 --- a/CHANGES +++ b/CHANGES @@ -333,6 +333,9 @@ Release 0.11.0 - unreleased BUG FIXES + TAJO-1912: Selection from aliased schemaless tables throws an error. + (jihoon) + TAJO-1918: Writing text type in Parquet should handle text bytes. (Contributed by Jongyoung Park. Committed by jinho) http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/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 0e5e577..3672697 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 @@ -70,6 +70,15 @@ public class TestQueryOnSelfDescTable extends QueryTestCaseBase { @Test @Option(sort = true) @SimpleTest( + queries = @QuerySpec("select t1.glossary.title from self_desc_table2 t1") + ) + public final void testSelectFromAliasedTable() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) + @SimpleTest( queries = @QuerySpec("" + "select title1, title2, null_expected, sortas, abbrev from (\n" + "select\n" + @@ -217,6 +226,63 @@ public class TestQueryOnSelfDescTable extends QueryTestCaseBase { " user.favourites_count = name.first_name"); } + + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select\n" + + " user.favourites_count::int8,\n" + + " l_linenumber,\n" + + " l_comment\n" + + "from\n" + + " default.lineitem l1, self_desc_table3 t1\n" + + "where\n" + + " user.favourites_count::int8 = (l_orderkey - 1)" + ) + ) + public final void testJoinAliasedTables() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select\n" + + " user.favourites_count::int8,\n" + + " l_linenumber,\n" + + " l_comment\n" + + "from\n" + + " default.lineitem l1, self_desc_table3 t3, default.orders o1, default.supplier s1\n" + + "where\n" + + " user.favourites_count::int8 = (l_orderkey - 1) and l_orderkey = o_orderkey and l_linenumber = s_suppkey" + ) + ) + public final void testJoinAliasedTables2() throws Exception { + runSimpleTests(); + } + + @Test(expected = AmbiguousColumnException.class) + public final void testJoinAliasedTables3() throws Exception { + executeString("" + + "select " + + " user.favourites_count::int8, " + + " l_linenumber, " + + " l_comment " + + "from " + + " default.lineitem l1, " + + " self_desc_table1 t1, " + + " self_desc_table3 t2, " + + " default.orders o2, " + + " default.supplier s2 " + + "where " + + " user.favourites_count::int8 = (l_orderkey - 1) and " + + " l_orderkey = o_orderkey and " + + " l_linenumber = s_suppkey and " + + " self_desc_table3.user.favourites_count = self_desc_table1.name.first_name"); + } + @Test @Option(sort = true) @SimpleTest @@ -224,6 +290,38 @@ public class TestQueryOnSelfDescTable extends QueryTestCaseBase { runSimpleTests(); } + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select\n" + + " t1.user.favourites_count::int8\n" + + "from\n" + + " github g1, self_desc_table3 t1\n" + + "where\n" + + " t1.user.favourites_count = (g1.actor.id::int8 - 206379)::text" + ) + ) + public final void testJoinOfSelfDescTablesWithQualifiedColumns2() throws Exception { + runSimpleTests(); + } + + @Test + @Option(sort = true) + @SimpleTest( + queries = @QuerySpec("" + + "select\n" + + " t1.user.favourites_count::int8\n" + + "from\n" + + " github g1, self_desc_table3 t1\n" + + "where\n" + + " self_desc_table3.user.favourites_count = (github.actor.id::int8 - 206379)::text" + ) + ) + public final void testJoinOfSelfDescTablesWithQualifiedColumns3() throws Exception { + runSimpleTests(); + } + @Test(expected = AmbiguousColumnException.class) public final void testJoinWithSingleQualifiedColumn() throws Exception { executeString("" + http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables.1.result new file mode 100644 index 0000000..1754d7f --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables.1.result @@ -0,0 +1,4 @@ +?cast,l_linenumber,l_comment +------------------------------- +0,1,egular courts above the +0,2,ly final dependencies: slyly bold http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables2.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables2.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables2.1.result new file mode 100644 index 0000000..ef95de3 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinAliasedTables2.1.result @@ -0,0 +1,3 @@ +?cast,l_linenumber,l_comment +------------------------------- +0,2,ly final dependencies: slyly bold http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns2.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns2.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns2.1.result new file mode 100644 index 0000000..9e68a19 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns2.1.result @@ -0,0 +1,3 @@ +?cast +------------------------------- +0 http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns3.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns3.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns3.1.result new file mode 100644 index 0000000..9e68a19 --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testJoinOfSelfDescTablesWithQualifiedColumns3.1.result @@ -0,0 +1,3 @@ +?cast +------------------------------- +0 http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testSelectFromAliasedTable.1.result ---------------------------------------------------------------------- diff --git a/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testSelectFromAliasedTable.1.result b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testSelectFromAliasedTable.1.result new file mode 100644 index 0000000..6f9137e --- /dev/null +++ b/tajo-core-tests/src/test/resources/results/TestQueryOnSelfDescTable/testSelectFromAliasedTable.1.result @@ -0,0 +1,3 @@ +glossary/title +------------------------------- +example glossary http://git-wip-us.apache.org/repos/asf/tajo/blob/145c17f7/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 f609db2..d697d22 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 @@ -62,17 +62,17 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { return "Self-describing schema build phase"; } - private static String getQualifiedRelationName(PlanContext context, Relation relation) { - return CatalogUtil.isFQTableName(relation.getName()) ? - relation.getName() : - CatalogUtil.buildFQName(context.getQueryContext().get(SessionVars.CURRENT_DATABASE), relation.getName()); + private static String getQualifiedName(PlanContext context, String simpleName) { + return CatalogUtil.isFQTableName(simpleName) ? + simpleName : + CatalogUtil.buildFQName(context.getQueryContext().get(SessionVars.CURRENT_DATABASE), simpleName); } @Override public boolean isEligible(PlanContext context, Expr expr) throws TajoException { Set<Relation> relations = ExprFinderIncludeSubquery.finds(expr, OpType.Relation); for (Relation eachRelation : relations) { - TableDesc tableDesc = catalog.getTableDesc(getQualifiedRelationName(context, eachRelation)); + TableDesc tableDesc = catalog.getTableDesc(getQualifiedName(context, eachRelation.getName())); if (tableDesc.hasEmptySchema()) { return true; } @@ -94,7 +94,7 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { public static <T extends Expr> Set<T> finds(Expr expr, OpType type) throws TajoException { FinderContext<T> context = new FinderContext<>(type); ExprFinderIncludeSubquery finder = new ExprFinderIncludeSubquery(); - finder.visit(context, new Stack<Expr>(), expr); + finder.visit(context, new Stack<>(), expr); return context.set; } @@ -138,7 +138,7 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { if (processor == null) { processor = new Processor(); } - return processor.visit(new ProcessorContext(context), new Stack<Expr>(), expr); + return processor.visit(new ProcessorContext(context), new Stack<>(), expr); } static class ProcessorContext { @@ -361,19 +361,29 @@ public class SelfDescSchemaBuildPhase extends LogicalPlanPreprocessPhase { TableDesc desc = scan.getTableDesc(); if (desc.hasEmptySchema()) { - if (ctx.projectColumns.containsKey(getQualifiedRelationName(ctx.planContext, expr))) { - Set<Column> columns = new HashSet<>(); - for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedRelationName(ctx.planContext, expr))) { + Set<Column> columns = new HashSet<>(); + if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getName()))) { + for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getName()))) { columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); } + } - desc.setSchema(buildSchemaFromColumnSet(columns)); - scan.init(desc); - } else { + if (expr.hasAlias()) { + if (ctx.projectColumns.containsKey(getQualifiedName(ctx.planContext, expr.getAlias()))) { + for (ColumnReferenceExpr col : ctx.projectColumns.get(getQualifiedName(ctx.planContext, expr.getAlias()))) { + columns.add(NameResolver.resolve(plan, queryBlock, col, NameResolvingMode.RELS_ONLY, true)); + } + } + } + + if (columns.isEmpty()) { // error throw new TajoInternalError( - "Columns projected from " + getQualifiedRelationName(ctx.planContext, expr) + " is not found."); + "Columns projected from " + getQualifiedName(ctx.planContext, expr.getName()) + " is not found."); } + + desc.setSchema(buildSchemaFromColumnSet(columns)); + scan.init(desc); } return scan;
