presto-main/src/main/java/io/prestosql/sql/planner/optimizations/IndexJoinOptimizer.java/IndexJoinOptimizer/visitWindow
class IndexJoinOptimizer:        @Override
        public PlanNode visitWindow(WindowNode node, RewriteContext<Context> context)
        {
            if (!node.getWindowFunctions().values().stream()
                    .map(Function::getResolvedFunction)
                    .map(ResolvedFunction::getSignature)
                    .map(Signature::getName)
                    .map(QualifiedName::of)
                    .allMatch(metadata::isAggregationFunction)) {
                return node;
            }

            // Don't need this restriction if we can prove that all order by symbols are deterministically produced
            if (node.getOrderingScheme().isPresent()) {
                return node;
            }

            // Only RANGE frame type currently supported for aggregation functions because it guarantees the
            // same value for each peer group.
            // ROWS frame type requires the ordering to be fully deterministic (e.g. deterministically sorted on all columns)
            if (node.getFrames().stream().map(WindowNode.Frame::getType).anyMatch(type -> type != WindowFrame.Type.RANGE)) { // TODO: extract frames of type RANGE and allow optimization on them
                return node;
            }

            // Lookup symbols can only be passed through if they are part of the partitioning
            Set<Symbol> partitionByLookupSymbols = context.get().getLookupSymbols().stream()
                    .filter(node.getPartitionBy()::contains)
                    .collect(toImmutableSet());

            if (partitionByLookupSymbols.isEmpty()) {
                return node;
            }

            return context.defaultRewrite(node, new Context(partitionByLookupSymbols, context.get().getSuccess()));
        }