Search in sources :

Example 26 with BIGINT

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));
}
Also used : DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) Symbol(io.trino.sql.planner.Symbol) POSITIVE_INFINITY(java.lang.Double.POSITIVE_INFINITY) BIGINT(io.trino.spi.type.BigintType.BIGINT) Test(org.testng.annotations.Test) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Example 27 with BIGINT

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);
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) Test(org.testng.annotations.Test) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Example 28 with BIGINT

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);
}
Also used : Symbol(io.trino.sql.planner.Symbol) ImmutableList(com.google.common.collect.ImmutableList) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) Test(org.testng.annotations.Test) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Example 29 with BIGINT

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()));
}
Also used : DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) Symbol(io.trino.sql.planner.Symbol) POSITIVE_INFINITY(java.lang.Double.POSITIVE_INFINITY) BIGINT(io.trino.spi.type.BigintType.BIGINT) SampleNode(io.trino.sql.planner.plan.SampleNode) Test(org.testng.annotations.Test) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Example 30 with BIGINT

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"));
}
Also used : Symbol(io.trino.sql.planner.Symbol) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) Test(org.testng.annotations.Test) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Aggregations

BIGINT (io.trino.spi.type.BigintType.BIGINT)106 ImmutableList (com.google.common.collect.ImmutableList)99 Optional (java.util.Optional)87 Test (org.testng.annotations.Test)86 ImmutableMap (com.google.common.collect.ImmutableMap)84 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)44 List (java.util.List)44 Map (java.util.Map)44 ColumnHandle (io.trino.spi.connector.ColumnHandle)38 Type (io.trino.spi.type.Type)38 Symbol (io.trino.sql.planner.Symbol)38 QualifiedName (io.trino.sql.tree.QualifiedName)38 ImmutableSet (com.google.common.collect.ImmutableSet)37 TupleDomain (io.trino.spi.predicate.TupleDomain)36 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)36 TableHandle (io.trino.metadata.TableHandle)35 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)35 Session (io.trino.Session)34 PlanMatchPattern.filter (io.trino.sql.planner.assertions.PlanMatchPattern.filter)33 PlanBuilder.expression (io.trino.sql.planner.iterative.rule.test.PlanBuilder.expression)32