Search in sources :

Example 1 with JoinCriteria

use of io.prestosql.sql.tree.JoinCriteria 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 2 with JoinCriteria

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

the class RelationPlanner method planLateralJoin.

private RelationPlan planLateralJoin(Join join, RelationPlan leftPlan, Lateral lateral) {
    RelationPlan rightPlan = process(lateral.getQuery(), null);
    PlanBuilder leftPlanBuilder = initializePlanBuilder(leftPlan);
    PlanBuilder rightPlanBuilder = initializePlanBuilder(rightPlan);
    Expression filterExpression;
    if (!join.getCriteria().isPresent()) {
        filterExpression = TRUE_LITERAL;
    } else {
        JoinCriteria criteria = join.getCriteria().get();
        if (criteria instanceof JoinUsing || criteria instanceof NaturalJoin) {
            throw notSupportedException(join, "Lateral join with criteria other than ON");
        }
        filterExpression = (Expression) getOnlyElement(criteria.getNodes());
    }
    List<Symbol> rewriterOutputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getFieldMappings()).addAll(rightPlan.getFieldMappings()).build();
    // this node is not used in the plan. It is only used for creating the TranslationMap.
    PlanNode dummy = new ValuesNode(idAllocator.getNextId(), ImmutableList.<Symbol>builder().addAll(leftPlanBuilder.getRoot().getOutputSymbols()).addAll(rightPlanBuilder.getRoot().getOutputSymbols()).build(), ImmutableList.of());
    RelationPlan intermediateRelationPlan = new RelationPlan(dummy, analysis.getScope(join), rewriterOutputSymbols);
    TranslationMap translationMap = new TranslationMap(intermediateRelationPlan, analysis, lambdaDeclarationToSymbolMap);
    translationMap.setFieldMappings(rewriterOutputSymbols);
    translationMap.putExpressionMappingsFrom(leftPlanBuilder.getTranslations());
    translationMap.putExpressionMappingsFrom(rightPlanBuilder.getTranslations());
    Expression rewrittenFilterCondition = translationMap.rewrite(filterExpression);
    PlanBuilder planBuilder = subqueryPlanner.appendLateralJoin(leftPlanBuilder, rightPlanBuilder, lateral.getQuery(), true, LateralJoinNode.Type.typeConvert(join.getType()), rewrittenFilterCondition);
    List<Symbol> outputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getRoot().getOutputSymbols()).addAll(rightPlan.getRoot().getOutputSymbols()).build();
    return new RelationPlan(planBuilder.getRoot(), analysis.getScope(join), outputSymbols);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) PlanNode(io.prestosql.spi.plan.PlanNode) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Symbol(io.prestosql.spi.plan.Symbol) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) JoinUsing(io.prestosql.sql.tree.JoinUsing) NaturalJoin(io.prestosql.sql.tree.NaturalJoin)

Example 3 with JoinCriteria

use of io.prestosql.sql.tree.JoinCriteria 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 4 with JoinCriteria

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

the class ImpalaAstBuilder method visitJoinRelation.

@Override
public Node visitJoinRelation(ImpalaSqlParser.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());
    }
    if (context.joinType().SEMI() != null) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().SEMI().getText(), "[SEMI] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "SEMI", context);
    }
    if (context.joinType().ANTI() != null) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().ANTI().getText(), "[ANTI] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "ANTI", context);
    }
    if (context.joinType().INNER() != null && (context.joinType().LEFT() != null || context.joinType().RIGHT() != null)) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().INNER().getText(), "[LEFT INNER || RIGHT INNER] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "LEFT INNER || RIGHT INNER", context);
    }
    JoinCriteria criteria;
    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) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Join(io.prestosql.sql.tree.Join) JoinUsing(io.prestosql.sql.tree.JoinUsing) JoinOn(io.prestosql.sql.tree.JoinOn)

Aggregations

JoinCriteria (io.prestosql.sql.tree.JoinCriteria)4 AliasedRelation (io.prestosql.sql.tree.AliasedRelation)3 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)3 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)3 Expression (io.prestosql.sql.tree.Expression)3 Join (io.prestosql.sql.tree.Join)3 JoinOn (io.prestosql.sql.tree.JoinOn)3 JoinUsing (io.prestosql.sql.tree.JoinUsing)3 Relation (io.prestosql.sql.tree.Relation)3 SampledRelation (io.prestosql.sql.tree.SampledRelation)3 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)2 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)2 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)2 Identifier (io.prestosql.sql.tree.Identifier)2 IfExpression (io.prestosql.sql.tree.IfExpression)2 InListExpression (io.prestosql.sql.tree.InListExpression)2 LambdaExpression (io.prestosql.sql.tree.LambdaExpression)2 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)2 NaturalJoin (io.prestosql.sql.tree.NaturalJoin)2 NotExpression (io.prestosql.sql.tree.NotExpression)2