Search in sources :

Example 1 with JoinCriteria

use of com.facebook.presto.sql.tree.JoinCriteria in project presto by prestodb.

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) {
            List<String> columns = context.joinCriteria().identifier().stream().map(ParseTree::getText).collect(toList());
            criteria = new JoinUsing(columns);
        } 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 : AliasedRelation(com.facebook.presto.sql.tree.AliasedRelation) SampledRelation(com.facebook.presto.sql.tree.SampledRelation) Relation(com.facebook.presto.sql.tree.Relation) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) IfExpression(com.facebook.presto.sql.tree.IfExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) TryExpression(com.facebook.presto.sql.tree.TryExpression) ArithmeticUnaryExpression(com.facebook.presto.sql.tree.ArithmeticUnaryExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) JoinCriteria(com.facebook.presto.sql.tree.JoinCriteria) NaturalJoin(com.facebook.presto.sql.tree.NaturalJoin) Join(com.facebook.presto.sql.tree.Join) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) JoinUsing(com.facebook.presto.sql.tree.JoinUsing) NaturalJoin(com.facebook.presto.sql.tree.NaturalJoin) JoinOn(com.facebook.presto.sql.tree.JoinOn) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

AliasedRelation (com.facebook.presto.sql.tree.AliasedRelation)1 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)1 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 Expression (com.facebook.presto.sql.tree.Expression)1 IfExpression (com.facebook.presto.sql.tree.IfExpression)1 InListExpression (com.facebook.presto.sql.tree.InListExpression)1 Join (com.facebook.presto.sql.tree.Join)1 JoinCriteria (com.facebook.presto.sql.tree.JoinCriteria)1 JoinOn (com.facebook.presto.sql.tree.JoinOn)1 JoinUsing (com.facebook.presto.sql.tree.JoinUsing)1 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)1 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)1 NaturalJoin (com.facebook.presto.sql.tree.NaturalJoin)1 NotExpression (com.facebook.presto.sql.tree.NotExpression)1 NullIfExpression (com.facebook.presto.sql.tree.NullIfExpression)1 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)1 Relation (com.facebook.presto.sql.tree.Relation)1