use of com.facebook.presto.sql.tree.AliasedRelation in project presto by prestodb.
the class MaterializedViewPlanValidator method visitJoin.
@Override
protected Void visitJoin(Join node, MaterializedViewPlanValidatorContext context) {
context.pushJoinNode(node);
if (context.getJoinNodes().size() > 1) {
throw new SemanticException(NOT_SUPPORTED, node, "More than one join in materialized view is not supported yet.");
}
JoinCriteria joinCriteria;
switch(node.getType()) {
case INNER:
if (!node.getCriteria().isPresent()) {
throw new SemanticException(NOT_SUPPORTED, node, "Inner join with no criteria is not supported for materialized view.");
}
joinCriteria = node.getCriteria().get();
if (!(joinCriteria instanceof JoinOn)) {
throw new SemanticException(NOT_SUPPORTED, node, "Only join-on is supported for materialized view.");
}
process(node.getLeft(), context);
process(node.getRight(), context);
context.setWithinJoinOn(true);
process(((JoinOn) joinCriteria).getExpression(), context);
context.setWithinJoinOn(false);
break;
case CROSS:
if (!(node.getRight() instanceof AliasedRelation)) {
throw new SemanticException(NOT_SUPPORTED, node, "Cross join is supported only with unnest for materialized view.");
}
AliasedRelation right = (AliasedRelation) node.getRight();
if (!(right.getRelation() instanceof Unnest)) {
throw new SemanticException(NOT_SUPPORTED, node, "Cross join is supported only with unnest for materialized view.");
}
process(node.getLeft(), context);
break;
case LEFT:
if (!node.getCriteria().isPresent()) {
throw new SemanticException(NOT_SUPPORTED, node, "Outer join with no criteria is not supported for materialized view.");
}
joinCriteria = node.getCriteria().get();
if (!(joinCriteria instanceof JoinOn)) {
throw new SemanticException(NOT_SUPPORTED, node, "Only join-on is supported for materialized view.");
}
process(node.getLeft(), context);
boolean wasWithinOuterJoin = context.isWithinOuterJoin();
context.setWithinOuterJoin(true);
process(node.getRight(), context);
// withinOuterJoin denotes if we are within an outer side of a join. Because it can be nested, replace it with its older value.
// So we set it to false, only when we leave the topmost outer join.
context.setWithinOuterJoin(wasWithinOuterJoin);
context.setWithinJoinOn(true);
process(((JoinOn) joinCriteria).getExpression(), context);
context.setWithinJoinOn(false);
break;
default:
throw new SemanticException(NOT_SUPPORTED, node, "Only inner join, left join and cross join unnested are supported for materialized view.");
}
context.popJoinNode();
return null;
}
use of com.facebook.presto.sql.tree.AliasedRelation in project presto by prestodb.
the class PredicateStitcher method visitTable.
@Override
protected Node visitTable(Table table, PredicateStitcherContext context) {
SchemaTableName schemaTableName = toSchemaTableName(createQualifiedObjectName(session, table, table.getName()));
if (!predicates.containsKey(schemaTableName)) {
return table;
}
QuerySpecification queryWithPredicateStitching = new QuerySpecification(selectList(new AllColumns()), Optional.of(table), Optional.of(predicates.get(schemaTableName)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
Relation subquery = subquery(new Query(Optional.empty(), queryWithPredicateStitching, Optional.empty(), Optional.empty(), Optional.empty()));
if (context.isCreateAlias()) {
return new AliasedRelation(subquery, identifier(schemaTableName.getTableName()), null);
}
return subquery;
}
use of com.facebook.presto.sql.tree.AliasedRelation in project presto by prestodb.
the class PredicateStitcher method visitAliasedRelation.
@Override
protected Node visitAliasedRelation(AliasedRelation node, PredicateStitcherContext context) {
context.setCreateAlias(false);
AliasedRelation aliasedRelation = new AliasedRelation((Relation) process(node.getRelation(), context), node.getAlias(), node.getColumnNames());
context.setCreateAlias(true);
return aliasedRelation;
}
Aggregations