use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestJoinStatsRule method testLeftJoinComplementStatsWithMultipleClauses.
@Test
public void testLeftJoinComplementStatsWithMultipleClauses() {
PlanNodeStatsEstimate expected = planNodeStats(LEFT_ROWS_COUNT * (LEFT_JOIN_COLUMN_NULLS + LEFT_JOIN_COLUMN_NON_NULLS / 4), symbolStatistics(LEFT_JOIN_COLUMN, 0.0, 20.0, LEFT_JOIN_COLUMN_NULLS / (LEFT_JOIN_COLUMN_NULLS + LEFT_JOIN_COLUMN_NON_NULLS / 4), 5), LEFT_OTHER_COLUMN_STATS).mapOutputRowCount(rowCount -> rowCount / UNKNOWN_FILTER_COEFFICIENT);
PlanNodeStatsEstimate actual = JOIN_STATS_RULE.calculateJoinComplementStats(Optional.empty(), ImmutableList.of(new EquiJoinClause(new Symbol(LEFT_JOIN_COLUMN), new Symbol(RIGHT_JOIN_COLUMN)), new EquiJoinClause(new Symbol(LEFT_OTHER_COLUMN), new Symbol(RIGHT_OTHER_COLUMN))), LEFT_STATS, RIGHT_STATS, TYPES);
assertEquals(actual, expected);
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestOutputNodeStats method testStatsForOutputNode.
@Test
public void testStatsForOutputNode() {
PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().setOutputRowCount(100).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0.3).setLowValue(1).setHighValue(30).setDistinctValuesCount(20).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setNullsFraction(0.6).setLowValue(13.5).setHighValue(POSITIVE_INFINITY).setDistinctValuesCount(40).build()).build();
tester().assertStatsFor(pb -> pb.output(outputBuilder -> {
Symbol a = pb.symbol("a", BIGINT);
Symbol b = pb.symbol("b", DOUBLE);
outputBuilder.source(pb.values(a, b)).column(a, "a1").column(a, "a2").column(b, "b");
})).withSourceStats(stats).check(outputStats -> outputStats.equalTo(stats));
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestRowNumberStatsRule method testSingleGroupingKey.
@Test
public void testSingleGroupingKey() {
// grouping on a key with 0 nulls fraction without max rows per partition limit
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT)), Optional.empty(), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(check -> check.outputRowsCount(10).symbolStats("x", assertion -> assertion.isEqualTo(xStats)).symbolStats("y", assertion -> assertion.isEqualTo(yStats)).symbolStats("z", assertion -> assertion.lowValue(1).distinctValuesCount(2).nullsFraction(0).averageRowSize(BIGINT.getFixedSize())));
// grouping on a key with 0 nulls fraction with max rows per partition limit
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT)), Optional.of(1), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(check -> check.outputRowsCount(5).symbolStats("z", assertion -> assertion.lowValue(1).distinctValuesCount(1).nullsFraction(0).averageRowSize(BIGINT.getFixedSize())));
// grouping on a key with non zero nulls fraction
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("y", BIGINT)), Optional.empty(), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(60).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(check -> check.outputRowsCount(60).symbolStats("z", assertion -> assertion.lowValue(1).distinctValuesCount(10).nullsFraction(0).averageRowSize(BIGINT.getFixedSize())));
// unknown input row count
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT)), Optional.of(1), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(PlanNodeStatsAssertion::outputRowsCountUnknown);
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestRowNumberStatsRule method testMultipleGroupingKeys.
@Test
public void testMultipleGroupingKeys() {
// grouping on multiple keys with the number of estimated groups less than the row count
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)), Optional.empty(), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(60).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(check -> check.outputRowsCount(60).symbolStats("z", assertion -> assertion.lowValue(1).distinctValuesCount(2).nullsFraction(0).averageRowSize(BIGINT.getFixedSize())));
// grouping on multiple keys with the number of estimated groups greater than the row count
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)), Optional.empty(), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(20).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), yStats).build()).check(check -> check.outputRowsCount(20).symbolStats("z", assertion -> assertion.lowValue(1).distinctValuesCount(1).nullsFraction(0).averageRowSize(BIGINT.getFixedSize())));
// grouping on multiple keys with stats for one of the keys are unknown
tester().assertStatsFor(pb -> pb.rowNumber(ImmutableList.of(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)), Optional.empty(), pb.symbol("z", BIGINT), pb.values(pb.symbol("x", BIGINT), pb.symbol("y", BIGINT)))).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(20).addSymbolStatistics(new Symbol("x"), xStats).addSymbolStatistics(new Symbol("y"), SymbolStatsEstimate.unknown()).build()).check(PlanNodeStatsAssertion::outputRowsCountUnknown);
}
use of io.trino.sql.planner.Symbol in project trino by trinodb.
the class TestSampleStatsRule method testStatsForSampleNode.
@Test
public void testStatsForSampleNode() {
tester().assertStatsFor(pb -> {
Symbol a = pb.symbol("a", BIGINT);
Symbol b = pb.symbol("b", DOUBLE);
return pb.sample(.33, SampleNode.Type.BERNOULLI, pb.values(a, b));
}).withSourceStats(PlanNodeStatsEstimate.builder().setOutputRowCount(100).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setDistinctValuesCount(20).setNullsFraction(0.3).setLowValue(1).setHighValue(30).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setDistinctValuesCount(40).setNullsFraction(0.6).setLowValue(13.5).setHighValue(POSITIVE_INFINITY).build()).build()).check(check -> check.outputRowsCount(33).symbolStats("a", assertion -> assertion.dataSizeUnknown().distinctValuesCount(20).nullsFraction(0.3).lowValue(1).highValue(30)).symbolStats("b", assertion -> assertion.dataSizeUnknown().distinctValuesCount(23.1).nullsFraction(0.3).lowValue(13.5).highValueUnknown()));
}
Aggregations