Search in sources :

Example 1 with EnforceSingleRowNode

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

the class SubqueryPlanner method appendScalarSubqueryApplyNode.

private PlanBuilder appendScalarSubqueryApplyNode(PlanBuilder subPlan, SubqueryExpression scalarSubquery, boolean correlationAllowed) {
    if (subPlan.canTranslate(scalarSubquery)) {
        // given subquery is already appended
        return subPlan;
    }
    List<Expression> coercions = coercionsFor(scalarSubquery);
    SubqueryExpression uncoercedScalarSubquery = uncoercedSubquery(scalarSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedScalarSubquery);
    subqueryPlan = subqueryPlan.withNewRoot(new EnforceSingleRowNode(subPlan.getRoot().getSourceLocation(), idAllocator.getNextId(), subqueryPlan.getRoot()));
    subqueryPlan = subqueryPlan.appendProjections(coercions, variableAllocator, idAllocator);
    VariableReferenceExpression uncoercedScalarSubqueryVariable = subqueryPlan.translate(uncoercedScalarSubquery);
    subPlan.getTranslations().put(uncoercedScalarSubquery, uncoercedScalarSubqueryVariable);
    for (Expression coercion : coercions) {
        VariableReferenceExpression coercionVariable = subqueryPlan.translate(coercion);
        subPlan.getTranslations().put(coercion, coercionVariable);
    }
    return appendLateralJoin(subPlan, subqueryPlan, scalarSubquery.getQuery(), correlationAllowed, LateralJoinNode.Type.LEFT);
}
Also used : 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) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) EnforceSingleRowNode(com.facebook.presto.sql.planner.plan.EnforceSingleRowNode) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression)

Aggregations

RowExpression (com.facebook.presto.spi.relation.RowExpression)1 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1 ExpressionNodeInliner.replaceExpression (com.facebook.presto.sql.planner.ExpressionNodeInliner.replaceExpression)1 EnforceSingleRowNode (com.facebook.presto.sql.planner.plan.EnforceSingleRowNode)1 OriginalExpressionUtils.castToExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToExpression)1 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 Expression (com.facebook.presto.sql.tree.Expression)1 NotExpression (com.facebook.presto.sql.tree.NotExpression)1 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)1 SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)1