@@ -0,0 +1,2618 @@
+/*%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.facebook.presto.cost;%0A%0Aimport com.facebook.presto.Session;%0Aimport com.facebook.presto.spi.type.Type;%0Aimport com.facebook.presto.sql.planner.Symbol;%0Aimport com.facebook.presto.sql.planner.iterative.Lookup;%0Aimport com.facebook.presto.sql.planner.plan.PlanNode;%0Aimport com.facebook.presto.sql.planner.plan.PlanVisitor;%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0A%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Optional;%0A%0Apublic class ComposableStatsCalculator%0A        implements StatsCalculator%0A%7B%0A    private final List%3CRule%3E rules;%0A%0A    public ComposableStatsCalculator(List%3CRule%3E rules)%0A    %7B%0A        this.rules = ImmutableList.copyOf(rules);%0A    %7D%0A%0A    @Override%0A    public PlanNodeStatsEstimate calculateStats(PlanNode planNode, Lookup lookup, Session session, Map%3CSymbol, Type%3E types)%0A    %7B%0A        Visitor visitor = new Visitor(lookup, session, types);%0A        return planNode.accept(visitor, null);%0A    %7D%0A%0A    public interface Rule%0A    %7B%0A        Optional%3CPlanNodeStatsEstimate%3E calculate(PlanNode node, Lookup lookup, Session session, Map%3CSymbol, Type%3E types);%0A    %7D%0A%0A    private class Visitor%0A            extends PlanVisitor%3CPlanNodeStatsEstimate, Void%3E%0A    %7B%0A        private final Lookup lookup;%0A        private final Session session;%0A        private final Map%3CSymbol, Type%3E types;%0A%0A        public Visitor(Lookup lookup, Session session, Map%3CSymbol, Type%3E types)%0A        %7B%0A            this.lookup = lookup;%0A            this.session = session;%0A            this.types = ImmutableMap.copyOf(types);%0A        %7D%0A%0A        @Override%0A        protected PlanNodeStatsEstimate visitPlan(PlanNode node, Void context)%0A        %7B%0A            for (Rule rule : rules) %7B%0A                Optional%3CPlanNodeStatsEstimate%3E calculatedStats = rule.calculate(node, lookup, session, types);%0A                if (calculatedStats.isPresent()) %7B%0A                    return calculatedStats.get();%0A                %7D%0A            %7D%0A            return PlanNodeStatsEstimate.UNKNOWN_STATS;%0A        %7D%0A    %7D%0A%7D%0A

Add ComposableStatsCalculator