private PlanNodeStatsAssertion assertExpression(Expression expression) { return PlanNodeStatsAssertion.assertThat(statsCalculator.filterStats( standardInputStatistics, expression, session, standardTypes)); } }
private PlanNodeStatsAssertion assertCalculate(Expression comparisonExpression) { return PlanNodeStatsAssertion.assertThat(filterStatsCalculator.filterStats(standardInputStatistics, comparisonExpression, session, types)); }
public StatsCalculatorAssertion check(Rule<?> rule, Consumer<PlanNodeStatsAssertion> statisticsAssertionConsumer) { Optional<PlanNodeStatsEstimate> statsEstimate = calculatedStats(rule, planNode, this::getSourceStats, noLookup(), session, types); checkState(statsEstimate.isPresent(), "Expected stats estimates to be present"); statisticsAssertionConsumer.accept(PlanNodeStatsAssertion.assertThat(statsEstimate.get())); return this; }
public StatsCalculatorAssertion check(Consumer<PlanNodeStatsAssertion> statisticsAssertionConsumer) { PlanNodeStatsEstimate statsEstimate = statsCalculator.calculateStats(planNode, this::getSourceStats, noLookup(), session, types); statisticsAssertionConsumer.accept(PlanNodeStatsAssertion.assertThat(statsEstimate)); return this; }
private PlanNodeStatsAssertion assertNormalized(PlanNodeStatsEstimate estimate, TypeProvider types) { PlanNodeStatsEstimate normalized = normalizer.normalize(estimate, estimate.getSymbolsWithKnownStatistics(), types); return PlanNodeStatsAssertion.assertThat(normalized); }
@Test public void testAddJoinComplementStats() { double statsToAddNdv = 5; PlanNodeStatsEstimate statsToAdd = planNodeStats(RIGHT_ROWS_COUNT, symbolStatistics(LEFT_JOIN_COLUMN, 0.0, 5.0, 0.2, statsToAddNdv)); PlanNodeStatsEstimate addedStats = planNodeStats(TOTAL_ROWS_COUNT, symbolStatistics(LEFT_JOIN_COLUMN, 0.0, 20.0, (LEFT_ROWS_COUNT * LEFT_JOIN_COLUMN_NULLS + RIGHT_ROWS_COUNT * 0.2) / TOTAL_ROWS_COUNT, LEFT_JOIN_COLUMN_NDV), symbolStatistics(LEFT_OTHER_COLUMN, 42, 42, (0.42 * LEFT_ROWS_COUNT + RIGHT_ROWS_COUNT) / TOTAL_ROWS_COUNT, 1)); assertThat(JOIN_STATS_RULE.addJoinComplementStats( LEFT_STATS, LEFT_STATS, statsToAdd)) .equalTo(addedStats); }
@Test public void testDropNonOutputSymbols() { Symbol a = new Symbol("a"); Symbol b = new Symbol("b"); Symbol c = new Symbol("c"); PlanNodeStatsEstimate estimate = PlanNodeStatsEstimate.builder() .setOutputRowCount(40) .addSymbolStatistics(a, SymbolStatsEstimate.builder().setDistinctValuesCount(20).build()) .addSymbolStatistics(b, SymbolStatsEstimate.builder().setDistinctValuesCount(30).build()) .addSymbolStatistics(c, SymbolStatsEstimate.unknown()) .build(); PlanNodeStatsAssertion.assertThat(normalizer.normalize(estimate, ImmutableList.of(b, c), TypeProvider.copyOf(ImmutableMap.of(b, BIGINT, c, BIGINT)))) .symbolsWithKnownStats(b) .symbolStats(b, symbolAssert -> symbolAssert.distinctValuesCount(30)); }
assertThat(computeSemiJoin(inputStatistics, inputStatistics, x, w)) .symbolStats(x, stats -> stats .lowValue(xStats.getLowValue()) assertThat(computeSemiJoin(inputStatistics, inputStatistics, x, u)) .symbolStats(x, stats -> stats .lowValue(xStats.getLowValue()) assertThat(computeSemiJoin(inputStatistics, inputStatistics, unknown, u)) .symbolStats(unknown, stats -> stats .nullsFraction(0) assertThat(computeSemiJoin(inputStatistics, inputStatistics, x, unknown)) .symbolStats(x, stats -> stats .nullsFraction(0) assertThat(computeSemiJoin(inputStatistics, inputStatistics, emptyRange, emptyRange)) .outputRowsCount(0); assertThat(computeSemiJoin(inputStatistics, inputStatistics, fractionalNdv, fractionalNdv)) .outputRowsCount(1000) .symbolStats(fractionalNdv, stats -> stats
assertThat(computeAntiJoin(inputStatistics, inputStatistics, u, x)) .symbolStats(u, stats -> stats .lowValue(uStats.getLowValue()) assertThat(computeAntiJoin(inputStatistics, inputStatistics, x, u)) .symbolStats(x, stats -> stats .lowValue(xStats.getLowValue()) assertThat(computeAntiJoin(inputStatistics, inputStatistics, unknown, u)) .symbolStats(unknown, stats -> stats .nullsFraction(0) assertThat(computeAntiJoin(inputStatistics, inputStatistics, x, unknown)) .symbolStats(x, stats -> stats .nullsFraction(0) assertThat(computeAntiJoin(inputStatistics, inputStatistics, emptyRange, emptyRange)) .outputRowsCount(0); assertThat(computeAntiJoin(inputStatistics, inputStatistics, fractionalNdv, fractionalNdv)) .outputRowsCount(500) .symbolStats(fractionalNdv, stats -> stats