use of io.trino.spi.type.BigintType.BIGINT 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.spi.type.BigintType.BIGINT 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.spi.type.BigintType.BIGINT 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.spi.type.BigintType.BIGINT 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()));
}
use of io.trino.spi.type.BigintType.BIGINT in project trino by trinodb.
the class TestSemiJoinStatsRule method testSemiJoinPropagatesSourceStats.
@Test
public void testSemiJoinPropagatesSourceStats() {
SymbolStatsEstimate stats = SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0.3).build();
tester().assertStatsFor(pb -> {
Symbol a = pb.symbol("a", BIGINT);
Symbol b = pb.symbol("b", BIGINT);
Symbol c = pb.symbol("c", BIGINT);
Symbol semiJoinOutput = pb.symbol("sjo", BOOLEAN);
return pb.semiJoin(pb.values(a, b), pb.values(c), a, c, semiJoinOutput, Optional.empty(), Optional.empty(), Optional.empty());
}).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("a"), stats).addSymbolStatistics(new Symbol("b"), stats).build()).withSourceStats(1, PlanNodeStatsEstimate.builder().setOutputRowCount(20).addSymbolStatistics(new Symbol("c"), stats).build()).check(check -> check.outputRowsCount(10).symbolStats("a", assertion -> assertion.isEqualTo(stats)).symbolStats("b", assertion -> assertion.isEqualTo(stats)).symbolStatsUnknown("c").symbolStatsUnknown("sjo"));
}
Aggregations