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

        // do not push topN between projection and filter(table scan) so that they can be merged into a PageProcessor
        PlanNode projectSource = context.getLookup().resolve(projectNode.getSource());
        if (projectSource instanceof FilterNode) {
            PlanNode filterSource = context.getLookup().resolve(((FilterNode) projectSource).getSource());
            if (filterSource instanceof TableScanNode) {
                return Result.empty();
            }
        }

        Optional<SymbolMapper> symbolMapper = symbolMapper(parent.getOrderingScheme().getOrderBy(), projectNode.getAssignments());
        if (!symbolMapper.isPresent()) {
            return Result.empty();
        }

        TopNNode mappedTopN = symbolMapper.get().map(parent, projectNode.getSource(), context.getIdAllocator().getNextId());
        return Result.ofPlanNode(projectNode.replaceChildren(ImmutableList.of(mappedTopN)));
    }