Search in sources :

Example 1 with NaturalJoin

use of io.crate.sql.tree.NaturalJoin in project crate by crate.

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(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 = identsToStrings(context.joinCriteria().ident());
            criteria = new JoinUsing(columns);
        } else {
            throw new IllegalArgumentException("Unsupported join criteria");
        }
    }
    return new Join(getJoinType(context.joinType()), left, right, Optional.of(criteria));
}
Also used : AliasedRelation(io.crate.sql.tree.AliasedRelation) Relation(io.crate.sql.tree.Relation) SubscriptExpression(io.crate.sql.tree.SubscriptExpression) IfExpression(io.crate.sql.tree.IfExpression) NotExpression(io.crate.sql.tree.NotExpression) SearchedCaseExpression(io.crate.sql.tree.SearchedCaseExpression) LogicalBinaryExpression(io.crate.sql.tree.LogicalBinaryExpression) ArraySliceExpression(io.crate.sql.tree.ArraySliceExpression) ArraySubQueryExpression(io.crate.sql.tree.ArraySubQueryExpression) SimpleCaseExpression(io.crate.sql.tree.SimpleCaseExpression) SubqueryExpression(io.crate.sql.tree.SubqueryExpression) InListExpression(io.crate.sql.tree.InListExpression) ParameterExpression(io.crate.sql.tree.ParameterExpression) ArrayComparisonExpression(io.crate.sql.tree.ArrayComparisonExpression) Expression(io.crate.sql.tree.Expression) ComparisonExpression(io.crate.sql.tree.ComparisonExpression) ArithmeticExpression(io.crate.sql.tree.ArithmeticExpression) NegativeExpression(io.crate.sql.tree.NegativeExpression) JoinCriteria(io.crate.sql.tree.JoinCriteria) Join(io.crate.sql.tree.Join) NaturalJoin(io.crate.sql.tree.NaturalJoin) ValuesList(io.crate.sql.tree.ValuesList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) JoinUsing(io.crate.sql.tree.JoinUsing) NaturalJoin(io.crate.sql.tree.NaturalJoin) JoinOn(io.crate.sql.tree.JoinOn)

Aggregations

AliasedRelation (io.crate.sql.tree.AliasedRelation)1 ArithmeticExpression (io.crate.sql.tree.ArithmeticExpression)1 ArrayComparisonExpression (io.crate.sql.tree.ArrayComparisonExpression)1 ArraySliceExpression (io.crate.sql.tree.ArraySliceExpression)1 ArraySubQueryExpression (io.crate.sql.tree.ArraySubQueryExpression)1 ComparisonExpression (io.crate.sql.tree.ComparisonExpression)1 Expression (io.crate.sql.tree.Expression)1 IfExpression (io.crate.sql.tree.IfExpression)1 InListExpression (io.crate.sql.tree.InListExpression)1 Join (io.crate.sql.tree.Join)1 JoinCriteria (io.crate.sql.tree.JoinCriteria)1 JoinOn (io.crate.sql.tree.JoinOn)1 JoinUsing (io.crate.sql.tree.JoinUsing)1 LogicalBinaryExpression (io.crate.sql.tree.LogicalBinaryExpression)1 NaturalJoin (io.crate.sql.tree.NaturalJoin)1 NegativeExpression (io.crate.sql.tree.NegativeExpression)1 NotExpression (io.crate.sql.tree.NotExpression)1 ParameterExpression (io.crate.sql.tree.ParameterExpression)1 Relation (io.crate.sql.tree.Relation)1 SearchedCaseExpression (io.crate.sql.tree.SearchedCaseExpression)1