Search in sources :

Example 6 with ApplyNode

use of com.facebook.presto.sql.planner.plan.ApplyNode in project urban-eureka by errir503.

the class CheckSubqueryNodesAreRewritten method optimize.

@Override
public PlanNode optimize(PlanNode plan, Session session, TypeProvider types, PlanVariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator, WarningCollector warningCollector) {
    searchFrom(plan).where(ApplyNode.class::isInstance).findFirst().ifPresent(node -> {
        ApplyNode applyNode = (ApplyNode) node;
        error(applyNode.getCorrelation(), applyNode.getOriginSubqueryError());
    });
    searchFrom(plan).where(LateralJoinNode.class::isInstance).findFirst().ifPresent(node -> {
        LateralJoinNode lateralJoinNode = (LateralJoinNode) node;
        error(lateralJoinNode.getCorrelation(), lateralJoinNode.getOriginSubqueryError());
    });
    return plan;
}
Also used : LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode)

Example 7 with ApplyNode

use of com.facebook.presto.sql.planner.plan.ApplyNode in project urban-eureka by errir503.

the class SubqueryPlanner method appendApplyNode.

private PlanBuilder appendApplyNode(PlanBuilder subPlan, Node subquery, PlanNode subqueryNode, Assignments subqueryAssignments, boolean correlationAllowed) {
    Map<Expression, Expression> correlation = extractCorrelation(subPlan, subqueryNode);
    if (!correlationAllowed && !correlation.isEmpty()) {
        throw notSupportedException(subquery, "Correlated subquery in given context");
    }
    subPlan = subPlan.appendProjections(correlation.keySet(), variableAllocator, idAllocator);
    subqueryNode = replaceExpressionsWithSymbols(subqueryNode, correlation);
    TranslationMap translations = subPlan.copyTranslations();
    PlanNode root = subPlan.getRoot();
    verifySubquerySupported(subqueryAssignments);
    return new PlanBuilder(translations, new ApplyNode(subqueryNode.getSourceLocation(), idAllocator.getNextId(), root, subqueryNode, subqueryAssignments, ImmutableList.copyOf(VariablesExtractor.extractUnique(correlation.values(), variableAllocator.getTypes())), subQueryNotSupportedError(subquery, "Given correlated subquery")));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) ExpressionNodeInliner.replaceExpression(com.facebook.presto.sql.planner.ExpressionNodeInliner.replaceExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) OriginalExpressionUtils.castToExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode)

Example 8 with ApplyNode

use of com.facebook.presto.sql.planner.plan.ApplyNode in project urban-eureka by errir503.

the class TestVerifyNoOriginalExpression method testValidateForApplyFailed.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testValidateForApplyFailed() {
    ImmutableMap<VariableReferenceExpression, RowExpression> map = ImmutableMap.of(VARIABLE_REFERENCE_EXPRESSION, castToRowExpression(new SymbolReference("count")));
    Assignments assignments = new Assignments(map);
    ImmutableList<VariableReferenceExpression> variableReferenceExpressions = ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION);
    ApplyNode applyNode = builder.apply(assignments, variableReferenceExpressions, valuesNode, valuesNode);
    testValidation(applyNode);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) Assignments(com.facebook.presto.spi.plan.Assignments) RowExpression(com.facebook.presto.spi.relation.RowExpression) OriginalExpressionUtils.castToRowExpression(com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 9 with ApplyNode

use of com.facebook.presto.sql.planner.plan.ApplyNode in project presto by prestodb.

the class CorrelationMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ApplyNode applyNode = (ApplyNode) node;
    if (correlation.size() != applyNode.getCorrelation().size()) {
        return NO_MATCH;
    }
    int i = 0;
    for (String alias : correlation) {
        if (!symbolAliases.get(alias).equals(applyNode.getCorrelation().get(i++).toSymbolReference())) {
            return NO_MATCH;
        }
    }
    return match();
}
Also used : ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode)

Aggregations

ApplyNode (com.facebook.presto.sql.planner.plan.ApplyNode)9 RowExpression (com.facebook.presto.spi.relation.RowExpression)4 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)4 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)4 Expression (com.facebook.presto.sql.tree.Expression)4 ExpressionNodeInliner.replaceExpression (com.facebook.presto.sql.planner.ExpressionNodeInliner.replaceExpression)3 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)3 NotExpression (com.facebook.presto.sql.tree.NotExpression)3 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)3 SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)3 Assignments (com.facebook.presto.spi.plan.Assignments)2 PlanNode (com.facebook.presto.spi.plan.PlanNode)2 BasePlanTest (com.facebook.presto.sql.planner.assertions.BasePlanTest)2 LateralJoinNode (com.facebook.presto.sql.planner.plan.LateralJoinNode)2 OriginalExpressionUtils.castToExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression)2 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)2 Test (org.testng.annotations.Test)2 Symbol (com.facebook.presto.sql.planner.Symbol)1 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)1 LimitNode (com.facebook.presto.sql.planner.plan.LimitNode)1