Search in sources :

Example 6 with SubqueryExpression

use of com.facebook.presto.sql.tree.SubqueryExpression in project presto by prestodb.

the class SubqueryPlanner method appendInPredicateApplyNode.

private PlanBuilder appendInPredicateApplyNode(PlanBuilder subPlan, InPredicate inPredicate, boolean correlationAllowed, Node node) {
    if (subPlan.canTranslate(inPredicate)) {
        // given subquery is already appended
        return subPlan;
    }
    subPlan = handleSubqueries(subPlan, inPredicate.getValue(), node);
    subPlan = subPlan.appendProjections(ImmutableList.of(inPredicate.getValue()), variableAllocator, idAllocator);
    checkState(inPredicate.getValueList() instanceof SubqueryExpression);
    SubqueryExpression valueListSubquery = (SubqueryExpression) inPredicate.getValueList();
    SubqueryExpression uncoercedValueListSubquery = uncoercedSubquery(valueListSubquery);
    PlanBuilder subqueryPlan = createPlanBuilder(uncoercedValueListSubquery);
    subqueryPlan = subqueryPlan.appendProjections(ImmutableList.of(valueListSubquery), variableAllocator, idAllocator);
    SymbolReference valueList = createSymbolReference(subqueryPlan.translate(valueListSubquery));
    VariableReferenceExpression rewrittenValue = subPlan.translate(inPredicate.getValue());
    InPredicate inPredicateSubqueryExpression = new InPredicate(new SymbolReference(inPredicate.getLocation(), rewrittenValue.getName()), valueList);
    VariableReferenceExpression inPredicateSubqueryVariable = variableAllocator.newVariable(inPredicateSubqueryExpression, BOOLEAN);
    subPlan.getTranslations().put(inPredicate, inPredicateSubqueryVariable);
    return appendApplyNode(subPlan, inPredicate, subqueryPlan.getRoot(), Assignments.of(inPredicateSubqueryVariable, castToRowExpression(inPredicateSubqueryExpression)), correlationAllowed);
}
Also used : SymbolReference(com.facebook.presto.sql.tree.SymbolReference) ExpressionTreeUtils.createSymbolReference(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.createSymbolReference) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) InPredicate(com.facebook.presto.sql.tree.InPredicate) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression)

Aggregations

SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)6 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)3 InPredicate (com.facebook.presto.sql.tree.InPredicate)3 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)3 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)2 Expression (com.facebook.presto.sql.tree.Expression)2 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)2 SingleColumn (com.facebook.presto.sql.tree.SingleColumn)2 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)2 RowExpression (com.facebook.presto.spi.relation.RowExpression)1 ExpressionTreeUtils.createSymbolReference (com.facebook.presto.sql.analyzer.ExpressionTreeUtils.createSymbolReference)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 AliasedRelation (com.facebook.presto.sql.tree.AliasedRelation)1 AllColumns (com.facebook.presto.sql.tree.AllColumns)1 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)1 BinaryLiteral (com.facebook.presto.sql.tree.BinaryLiteral)1 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)1