Search in sources :

Example 1 with JoinCriteria

use of io.confluent.ksql.parser.tree.JoinCriteria in project ksql by confluentinc.

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.<JoinCriteria>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(AstBuilder::getIdentifierText).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 : Relation(io.confluent.ksql.parser.tree.Relation) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) InListExpression(io.confluent.ksql.parser.tree.InListExpression) NullIfExpression(io.confluent.ksql.parser.tree.NullIfExpression) SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) LogicalBinaryExpression(io.confluent.ksql.parser.tree.LogicalBinaryExpression) TumblingWindowExpression(io.confluent.ksql.parser.tree.TumblingWindowExpression) ArithmeticBinaryExpression(io.confluent.ksql.parser.tree.ArithmeticBinaryExpression) NotExpression(io.confluent.ksql.parser.tree.NotExpression) HoppingWindowExpression(io.confluent.ksql.parser.tree.HoppingWindowExpression) SubscriptExpression(io.confluent.ksql.parser.tree.SubscriptExpression) SessionWindowExpression(io.confluent.ksql.parser.tree.SessionWindowExpression) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) LambdaExpression(io.confluent.ksql.parser.tree.LambdaExpression) SubqueryExpression(io.confluent.ksql.parser.tree.SubqueryExpression) WindowExpression(io.confluent.ksql.parser.tree.WindowExpression) ArithmeticUnaryExpression(io.confluent.ksql.parser.tree.ArithmeticUnaryExpression) JoinCriteria(io.confluent.ksql.parser.tree.JoinCriteria) Join(io.confluent.ksql.parser.tree.Join) NaturalJoin(io.confluent.ksql.parser.tree.NaturalJoin) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) JoinUsing(io.confluent.ksql.parser.tree.JoinUsing) NaturalJoin(io.confluent.ksql.parser.tree.NaturalJoin) JoinOn(io.confluent.ksql.parser.tree.JoinOn)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)1 ArithmeticBinaryExpression (io.confluent.ksql.parser.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (io.confluent.ksql.parser.tree.ArithmeticUnaryExpression)1 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)1 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)1 Expression (io.confluent.ksql.parser.tree.Expression)1 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)1 InListExpression (io.confluent.ksql.parser.tree.InListExpression)1 Join (io.confluent.ksql.parser.tree.Join)1 JoinCriteria (io.confluent.ksql.parser.tree.JoinCriteria)1 JoinOn (io.confluent.ksql.parser.tree.JoinOn)1 JoinUsing (io.confluent.ksql.parser.tree.JoinUsing)1 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)1 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)1 NaturalJoin (io.confluent.ksql.parser.tree.NaturalJoin)1 NotExpression (io.confluent.ksql.parser.tree.NotExpression)1 NullIfExpression (io.confluent.ksql.parser.tree.NullIfExpression)1 Relation (io.confluent.ksql.parser.tree.Relation)1 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)1