Search in sources :

Example 6 with AliasedRelation

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;
}
Also used : JoinCriteria(com.facebook.presto.sql.tree.JoinCriteria) Unnest(com.facebook.presto.sql.tree.Unnest) JoinOn(com.facebook.presto.sql.tree.JoinOn) AliasedRelation(com.facebook.presto.sql.tree.AliasedRelation)

Example 7 with AliasedRelation

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;
}
Also used : QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) AliasedRelation(com.facebook.presto.sql.tree.AliasedRelation) Relation(com.facebook.presto.sql.tree.Relation) SampledRelation(com.facebook.presto.sql.tree.SampledRelation) WithQuery(com.facebook.presto.sql.tree.WithQuery) Query(com.facebook.presto.sql.tree.Query) AllColumns(com.facebook.presto.sql.tree.AllColumns) SchemaTableName(com.facebook.presto.spi.SchemaTableName) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) AliasedRelation(com.facebook.presto.sql.tree.AliasedRelation)

Example 8 with AliasedRelation

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;
}
Also used : AliasedRelation(com.facebook.presto.sql.tree.AliasedRelation)

Aggregations

AliasedRelation (com.facebook.presto.sql.tree.AliasedRelation)8 AllColumns (com.facebook.presto.sql.tree.AllColumns)5 Identifier (com.facebook.presto.sql.tree.Identifier)4 Query (com.facebook.presto.sql.tree.Query)4 Table (com.facebook.presto.sql.tree.Table)4 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)3 Relation (com.facebook.presto.sql.tree.Relation)3 SampledRelation (com.facebook.presto.sql.tree.SampledRelation)3 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)2 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)2 CreateTable (com.facebook.presto.sql.tree.CreateTable)2 DropTable (com.facebook.presto.sql.tree.DropTable)2 Expression (com.facebook.presto.sql.tree.Expression)2 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)2 GroupingElement (com.facebook.presto.sql.tree.GroupingElement)2 Join (com.facebook.presto.sql.tree.Join)2 JoinOn (com.facebook.presto.sql.tree.JoinOn)2 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)2 NaturalJoin (com.facebook.presto.sql.tree.NaturalJoin)2 Node (com.facebook.presto.sql.tree.Node)2