presto-main/src/main/java/io/prestosql/sql/planner/SubqueryPlanner.java/SubqueryPlanner/appendApplyNode
class SubqueryPlanner:    private PlanBuilder appendApplyNode(
            PlanBuilder subPlan,
            Node subquery,
            PlanNode subqueryNode,
            Assignments subqueryAssignments,
            boolean correlationAllowed)
    {
        Map<NodeRef<Expression>, Expression> correlation = extractCorrelation(subPlan, subqueryNode);
        if (!correlationAllowed && !correlation.isEmpty()) {
            throw semanticException(NOT_SUPPORTED, subquery, "Correlated subquery in given context is not supported");
        }
        subPlan = subPlan.appendProjections(
                correlation.keySet().stream().map(NodeRef::getNode).collect(toImmutableSet()),
                symbolAllocator,
                idAllocator);
        subqueryNode = replaceExpressionsWithSymbols(subqueryNode, correlation);

        TranslationMap translations = subPlan.copyTranslations();
        PlanNode root = subPlan.getRoot();
        return new PlanBuilder(translations,
                new ApplyNode(idAllocator.getNextId(),
                        root,
                        subqueryNode,
                        subqueryAssignments,
                        ImmutableList.copyOf(SymbolsExtractor.extractUnique(correlation.values())),
                        subquery));
    }