Search in sources :

Example 1 with BasicRelationStatistics

use of io.trino.spi.connector.BasicRelationStatistics in project trino by trinodb.

the class PushJoinIntoTableScan method getJoinStatistics.

private JoinStatistics getJoinStatistics(JoinNode join, TableScanNode left, TableScanNode right, Context context) {
    return new JoinStatistics() {

        @Override
        public Optional<BasicRelationStatistics> getLeftStatistics() {
            return getBasicRelationStats(left, left.getOutputSymbols(), context);
        }

        @Override
        public Optional<BasicRelationStatistics> getRightStatistics() {
            return getBasicRelationStats(right, right.getOutputSymbols(), context);
        }

        @Override
        public Optional<BasicRelationStatistics> getJoinStatistics() {
            return getBasicRelationStats(join, join.getOutputSymbols(), context);
        }

        private Optional<BasicRelationStatistics> getBasicRelationStats(PlanNode node, List<Symbol> outputSymbols, Context context) {
            PlanNodeStatsEstimate stats = context.getStatsProvider().getStats(node);
            TypeProvider types = context.getSymbolAllocator().getTypes();
            double outputRowCount = stats.getOutputRowCount();
            double outputSize = stats.getOutputSizeInBytes(outputSymbols, types);
            if (isNaN(outputRowCount) || isNaN(outputSize)) {
                return Optional.empty();
            }
            return Optional.of(new BasicRelationStatistics((long) outputRowCount, (long) outputSize));
        }
    };
}
Also used : JoinStatistics(io.trino.spi.connector.JoinStatistics) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) TypeProvider(io.trino.sql.planner.TypeProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) BasicRelationStatistics(io.trino.spi.connector.BasicRelationStatistics)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)1 BasicRelationStatistics (io.trino.spi.connector.BasicRelationStatistics)1 JoinStatistics (io.trino.spi.connector.JoinStatistics)1 TypeProvider (io.trino.sql.planner.TypeProvider)1 PlanNode (io.trino.sql.planner.plan.PlanNode)1 List (java.util.List)1