Search in sources :

Example 1 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class AstBuilder method visitQuerySpecification.

@Override
public Node visitQuerySpecification(SqlBaseParser.QuerySpecificationContext context) {
    Optional<Relation> from = Optional.empty();
    List<SelectItem> selectItems = visit(context.selectItem(), SelectItem.class);
    List<Relation> relations = visit(context.relation(), Relation.class);
    if (!relations.isEmpty()) {
        // synthesize implicit join nodes
        Iterator<Relation> iterator = relations.iterator();
        Relation relation = iterator.next();
        while (iterator.hasNext()) {
            relation = new Join(getLocation(context), Join.Type.IMPLICIT, relation, iterator.next(), Optional.empty());
        }
        from = Optional.of(relation);
    }
    return new QuerySpecification(getLocation(context), new Select(getLocation(context.SELECT()), isDistinct(context.setQuantifier()), selectItems), from, visitIfPresent(context.where, Expression.class), visitIfPresent(context.groupBy(), GroupBy.class), visitIfPresent(context.having, Expression.class), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) BindExpression(io.prestosql.sql.tree.BindExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) TryExpression(io.prestosql.sql.tree.TryExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin)

Example 2 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class AstBuilder method visitAliasedRelation.

@Override
public Node visitAliasedRelation(SqlBaseParser.AliasedRelationContext context) {
    Relation child = (Relation) visit(context.relationPrimary());
    if (context.identifier() == null) {
        return child;
    }
    List<Identifier> aliases = null;
    if (context.columnAliases() != null) {
        aliases = visit(context.columnAliases().identifier(), Identifier.class);
    }
    return new AliasedRelation(getLocation(context), child, (Identifier) visit(context.identifier()), aliases);
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) AliasedRelation(io.prestosql.sql.tree.AliasedRelation)

Example 3 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class AstBuilder method visitJoinRelation.

// *************** from clause *****************
@Override
public Node visitJoinRelation(SqlBaseParser.JoinRelationContext context) {
    Relation left = (Relation) visit(context.left);
    Relation right;
    if (context.CROSS() != null) {
        right = (Relation) visit(context.right);
        return new Join(getLocation(context), Join.Type.CROSS, left, right, Optional.empty());
    }
    JoinCriteria criteria;
    if (context.NATURAL() != null) {
        right = (Relation) visit(context.right);
        criteria = new NaturalJoin();
    } else {
        right = (Relation) visit(context.rightRelation);
        if (context.joinCriteria().ON() != null) {
            criteria = new JoinOn((Expression) visit(context.joinCriteria().booleanExpression()));
        } else if (context.joinCriteria().USING() != null) {
            criteria = new JoinUsing(visit(context.joinCriteria().identifier(), Identifier.class));
        } else {
            throw new IllegalArgumentException("Unsupported join criteria");
        }
    }
    Join.Type joinType;
    if (context.joinType().LEFT() != null) {
        joinType = Join.Type.LEFT;
    } else if (context.joinType().RIGHT() != null) {
        joinType = Join.Type.RIGHT;
    } else if (context.joinType().FULL() != null) {
        joinType = Join.Type.FULL;
    } else {
        joinType = Join.Type.INNER;
    }
    return new Join(getLocation(context), joinType, left, right, Optional.of(criteria));
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) BindExpression(io.prestosql.sql.tree.BindExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) TryExpression(io.prestosql.sql.tree.TryExpression) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Join(io.prestosql.sql.tree.Join) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinUsing(io.prestosql.sql.tree.JoinUsing) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) JoinOn(io.prestosql.sql.tree.JoinOn)

Example 4 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class HiveAstBuilder method visitJoinRelation.

// *************** from clause *****************
@Override
public Node visitJoinRelation(HiveSqlParser.JoinRelationContext context) {
    Relation leftRelation = (Relation) visit(context.left);
    Relation rightRelation;
    Optional<JoinCriteria> criteria = Optional.empty();
    // Semi Join
    if (context.semiJoin() != null) {
        addDiff(DiffType.UNSUPPORTED, context.semiJoin().LEFT().getText(), "[LEFT SEMI JOIN] is not supported");
        addDiff(DiffType.UNSUPPORTED, context.semiJoin().SEMI().getText(), null);
        addDiff(DiffType.UNSUPPORTED, context.semiJoin().JOIN().getText(), null);
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Left semi join", context.semiJoin());
    }
    // Cross join
    if (context.crossJoin() != null) {
        if (context.crossJoin().joinCriteria() != null) {
            addDiff(DiffType.UNSUPPORTED, context.crossJoin().CROSS().getText(), "[CROSS JOIN] must not contain join condition");
            addDiff(DiffType.UNSUPPORTED, context.crossJoin().JOIN().getText(), null);
            throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Cross join must not contain join condition", context.crossJoin().joinCriteria());
        }
        rightRelation = (Relation) visit(context.crossJoin().right);
        return new Join(getLocation(context), Join.Type.CROSS, leftRelation, rightRelation, criteria);
    }
    // Inner join
    if (context.innerJoin() != null) {
        if (context.innerJoin().joinCriteria() == null) {
            if (context.innerJoin().INNER() != null) {
                addDiff(DiffType.UNSUPPORTED, context.innerJoin().INNER().getText(), null);
            }
            addDiff(DiffType.UNSUPPORTED, context.innerJoin().JOIN().getText(), "[INNER JOIN] must contain join condition");
            throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: Inner join must contain join condition", context.innerJoin());
        }
        rightRelation = (Relation) visit(context.innerJoin().right);
        criteria = Optional.of(new JoinOn((Expression) visit(context.innerJoin().joinCriteria().booleanExpression())));
        return new Join(getLocation(context), Join.Type.INNER, leftRelation, rightRelation, criteria);
    }
    // Outer join
    HiveSqlParser.OuterJoinContext outerJoinContext = context.outerJoin();
    // Get join type
    Join.Type joinType;
    if (outerJoinContext.joinType().LEFT() != null) {
        joinType = Join.Type.LEFT;
    } else if (outerJoinContext.joinType().RIGHT() != null) {
        joinType = Join.Type.RIGHT;
    } else {
        joinType = Join.Type.FULL;
    }
    // Get right relation
    rightRelation = (Relation) visit(outerJoinContext.rightRelation);
    // Get join criteria
    criteria = Optional.of(new JoinOn((Expression) visit(outerJoinContext.joinCriteria().booleanExpression())));
    return new Join(getLocation(context), joinType, leftRelation, rightRelation, criteria);
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Join(io.prestosql.sql.tree.Join) JoinOn(io.prestosql.sql.tree.JoinOn) HiveSqlParser(io.hetu.core.migration.source.hive.HiveSqlParser)

Example 5 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class HiveAstBuilder method visitAliasedRelation.

@Override
public Node visitAliasedRelation(HiveSqlParser.AliasedRelationContext context) {
    Relation relation = (Relation) visit(context.relationPrimary());
    if (context.identifier() == null) {
        return relation;
    }
    List<Identifier> aliases = null;
    if (context.columnAliases() != null) {
        aliases = visit(context.columnAliases().identifier(), Identifier.class);
    }
    return new AliasedRelation(getLocation(context), relation, (Identifier) visit(context.identifier()), aliases);
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) AliasedRelation(io.prestosql.sql.tree.AliasedRelation)

Aggregations

AliasedRelation (io.prestosql.sql.tree.AliasedRelation)10 Relation (io.prestosql.sql.tree.Relation)10 SampledRelation (io.prestosql.sql.tree.SampledRelation)10 Join (io.prestosql.sql.tree.Join)7 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)6 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)6 Expression (io.prestosql.sql.tree.Expression)6 Identifier (io.prestosql.sql.tree.Identifier)6 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)5 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)5 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)5 IfExpression (io.prestosql.sql.tree.IfExpression)5 InListExpression (io.prestosql.sql.tree.InListExpression)5 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)5 NotExpression (io.prestosql.sql.tree.NotExpression)5 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)5 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)5 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)5 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)5 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)5