Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public final void testSelect2() throws Exception {
runSimpleTests();
}

@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(
Expand Down Expand Up @@ -217,13 +226,102 @@ public final void testJoinOfSelfDescTables() throws Exception {
" 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
public final void testJoinOfSelfDescTablesWithQualifiedColumns() 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" +
" 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("" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
?cast,l_linenumber,l_comment
-------------------------------
0,1,egular courts above the
0,2,ly final dependencies: slyly bold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
?cast,l_linenumber,l_comment
-------------------------------
0,2,ly final dependencies: slyly bold
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
?cast
-------------------------------
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
?cast
-------------------------------
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
glossary/title
-------------------------------
example glossary
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public String getName() {
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;
}
Expand All @@ -94,7 +94,7 @@ private static class ExprFinderIncludeSubquery extends SimpleAlgebraVisitor<Find
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;
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public LogicalNode process(PlanContext context, Expr expr) throws TajoException
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 {
Expand Down Expand Up @@ -361,19 +361,29 @@ public LogicalNode visitRelation(ProcessorContext ctx, Stack<Expr> stack, Relati
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;
Expand Down