presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/PushTopNThroughOuterJoin.java/PushTopNThroughOuterJoin/apply
class PushTopNThroughOuterJoin:    @Override
    public Result apply(TopNNode parent, Captures captures, Context context)
    {
        JoinNode joinNode = captures.get(JOIN_CHILD);

        List<Symbol> orderBySymbols = parent.getOrderingScheme().getOrderBy();

        PlanNode left = joinNode.getLeft();
        PlanNode right = joinNode.getRight();
        JoinNode.Type type = joinNode.getType();

        if ((type == LEFT)
                && ImmutableSet.copyOf(left.getOutputSymbols()).containsAll(orderBySymbols)
                && !isAtMost(left, context.getLookup(), parent.getCount())) {
            return Result.ofPlanNode(
                    joinNode.replaceChildren(ImmutableList.of(
                            parent.replaceChildren(ImmutableList.of(left)),
                            right)));
        }

        if ((type == RIGHT)
                && ImmutableSet.copyOf(right.getOutputSymbols()).containsAll(orderBySymbols)
                && !isAtMost(right, context.getLookup(), parent.getCount())) {
            return Result.ofPlanNode(
                    joinNode.replaceChildren(ImmutableList.of(
                            left,
                            parent.replaceChildren(ImmutableList.of(right)))));
        }

        return Result.empty();
    }