Search in sources :

Example 26 with BIGINT

use of io.prestosql.spi.type.BigintType.BIGINT in project hetu-core by openlookeng.

the class TestBTreeIndex method testLessThanEqualTo.

@Test
public void testLessThanEqualTo() throws IOException, IndexLookUpException {
    BTreeIndex index = new BTreeIndex();
    for (int i = 0; i < 100; i++) {
        List<Pair> pairs = new ArrayList<>();
        Long key = Long.valueOf(100 + i);
        String value = "value" + i;
        pairs.add(new Pair(key, value));
        Pair pair = new Pair("dummyCol", pairs);
        index.addKeyValues(Collections.singletonList(pair));
    }
    File file = getFile();
    index.serialize(new FileOutputStream(file));
    BTreeIndex readIndex = new BTreeIndex();
    readIndex.deserialize(new FileInputStream(file));
    RowExpression comparisonExpression = simplePredicate(OperatorType.LESS_THAN_OR_EQUAL, "dummyCol", BIGINT, 120L);
    Iterator<String> result = readIndex.lookUp(comparisonExpression);
    assertNotNull(result, "Result shouldn't be null");
    assertTrue(result.hasNext());
    Object[] arr = IntStream.iterate(0, n -> n + 1).limit(21).mapToObj(i -> "value" + i).toArray();
    Arrays.sort(arr);
    for (int i = 0; i <= 20; i++) {
        assertEquals(arr[i], result.next());
    }
    assertFalse(result.hasNext());
    index.close();
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ArrayList(java.util.ArrayList) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) OperatorType(io.prestosql.spi.function.OperatorType) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) SpecialForm(io.prestosql.spi.relation.SpecialForm) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) Iterator(java.util.Iterator) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) Assert.assertNotNull(org.testng.Assert.assertNotNull) Pair(io.prestosql.spi.heuristicindex.Pair) File(java.io.File) List(java.util.List) HeuristicIndexTestUtils.simplePredicate(io.hetu.core.HeuristicIndexTestUtils.simplePredicate) RowExpression(io.prestosql.spi.relation.RowExpression) Assert.assertTrue(org.testng.Assert.assertTrue) IndexLookUpException(io.prestosql.spi.heuristicindex.IndexLookUpException) Index(io.prestosql.spi.heuristicindex.Index) Collections(java.util.Collections) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 27 with BIGINT

use of io.prestosql.spi.type.BigintType.BIGINT in project hetu-core by openlookeng.

the class TestValuesNodeStats method testStatsForValuesNode.

@Test
public void testStatsForValuesNode() {
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("a", BIGINT), pb.symbol("b", DOUBLE)), ImmutableList.of(ImmutableList.of(pb.binaryOperation(OperatorType.ADD, constant(3L, BIGINT), constant(3L, BIGINT)), constant(13.5e0, DOUBLE)), ImmutableList.of(constant(55L, BIGINT), constantNull(DOUBLE)), ImmutableList.of(constant(6L, BIGINT), constant(13.5e0, DOUBLE))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(3).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0).setLowValue(6).setHighValue(55).setDistinctValuesCount(2).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setNullsFraction(0.33333333333333333).setLowValue(13.5).setHighValue(13.5).setDistinctValuesCount(1).build()).build()));
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("v", createVarcharType(30))), ImmutableList.of(constantExpressions(VARCHAR, utf8Slice("Alice")), constantExpressions(VARCHAR, utf8Slice("has")), constantExpressions(VARCHAR, utf8Slice("a cat")), ImmutableList.of(constantNull(VARCHAR))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(4).addSymbolStatistics(new Symbol("v"), SymbolStatsEstimate.builder().setNullsFraction(0.25).setDistinctValuesCount(3).build()).build()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder.constantExpressions(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) Test(org.testng.annotations.Test) Expressions.constantNull(io.prestosql.sql.relational.Expressions.constantNull) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) OperatorType(io.prestosql.spi.function.OperatorType) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) UNKNOWN(io.prestosql.spi.type.UnknownType.UNKNOWN) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 28 with BIGINT

use of io.prestosql.spi.type.BigintType.BIGINT in project hetu-core by openlookeng.

the class TestJoinStatsRule method testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction.

@Test
public void testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction() {
    double innerJoinRowCount = // driver join clause
    LEFT_ROWS_COUNT * RIGHT_ROWS_COUNT / LEFT_JOIN_COLUMN_2_NDV * LEFT_JOIN_COLUMN_2_NON_NULLS * RIGHT_JOIN_COLUMN_2_NON_NULLS * // auxiliary join clause
    UNKNOWN_FILTER_COEFFICIENT * // LEFT_JOIN_COLUMN < 10 non equality filter
    0.3333333333;
    PlanNodeStatsEstimate innerJoinStats = planNodeStats(innerJoinRowCount, symbolStatistics(LEFT_JOIN_COLUMN, 5.0, 10.0, 0.0, RIGHT_JOIN_COLUMN_NDV * 0.3333333333), symbolStatistics(RIGHT_JOIN_COLUMN, 5.0, 20.0, 0.0, RIGHT_JOIN_COLUMN_NDV), symbolStatistics(LEFT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV), symbolStatistics(RIGHT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV));
    tester().assertStatsFor(pb -> {
        Symbol leftJoinColumnSymbol = pb.symbol(LEFT_JOIN_COLUMN, BIGINT);
        Symbol rightJoinColumnSymbol = pb.symbol(RIGHT_JOIN_COLUMN, DOUBLE);
        Symbol leftJoinColumnSymbol2 = pb.symbol(LEFT_JOIN_COLUMN_2, BIGINT);
        Symbol rightJoinColumnSymbol2 = pb.symbol(RIGHT_JOIN_COLUMN_2, DOUBLE);
        ComparisonExpression leftJoinColumnLessThanTen = new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN, toSymbolReference(leftJoinColumnSymbol), new LongLiteral("10"));
        return pb.join(INNER, pb.values(leftJoinColumnSymbol, leftJoinColumnSymbol2), pb.values(rightJoinColumnSymbol, rightJoinColumnSymbol2), ImmutableList.of(new EquiJoinClause(leftJoinColumnSymbol2, rightJoinColumnSymbol2), new EquiJoinClause(leftJoinColumnSymbol, rightJoinColumnSymbol)), ImmutableList.of(leftJoinColumnSymbol, leftJoinColumnSymbol2, rightJoinColumnSymbol, rightJoinColumnSymbol2), Optional.of(castToRowExpression(leftJoinColumnLessThanTen)));
    }).withSourceStats(0, planNodeStats(LEFT_ROWS_COUNT, LEFT_JOIN_COLUMN_STATS, LEFT_JOIN_COLUMN_2_STATS)).withSourceStats(1, planNodeStats(RIGHT_ROWS_COUNT, RIGHT_JOIN_COLUMN_STATS, RIGHT_JOIN_COLUMN_2_STATS)).check(stats -> stats.equalTo(innerJoinStats));
}
Also used : EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) TypeProvider(io.prestosql.sql.planner.TypeProvider) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanNodeStatsAssertion.assertThat(io.prestosql.cost.PlanNodeStatsAssertion.assertThat) ImmutableList(com.google.common.collect.ImmutableList) NaN(java.lang.Double.NaN) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) UNKNOWN_FILTER_COEFFICIENT(io.prestosql.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) ImmutableMap(com.google.common.collect.ImmutableMap) FULL(io.prestosql.spi.plan.JoinNode.Type.FULL) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Metadata(io.prestosql.metadata.Metadata) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) RIGHT(io.prestosql.spi.plan.JoinNode.Type.RIGHT) LongLiteral(io.prestosql.sql.tree.LongLiteral) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) LEFT(io.prestosql.spi.plan.JoinNode.Type.LEFT) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) LongLiteral(io.prestosql.sql.tree.LongLiteral) Symbol(io.prestosql.spi.plan.Symbol) EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) Test(org.testng.annotations.Test)

Example 29 with BIGINT

use of io.prestosql.spi.type.BigintType.BIGINT in project hetu-core by openlookeng.

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.prestosql.spi.plan.Symbol) ImmutableList(com.google.common.collect.ImmutableList) Optional(java.util.Optional) Test(org.testng.annotations.Test) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 30 with BIGINT

use of io.prestosql.spi.type.BigintType.BIGINT in project hetu-core by openlookeng.

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(), 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.prestosql.spi.plan.Symbol) Optional(java.util.Optional) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Test(org.testng.annotations.Test) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Aggregations

BIGINT (io.prestosql.spi.type.BigintType.BIGINT)62 ImmutableList (com.google.common.collect.ImmutableList)54 Optional (java.util.Optional)50 Test (org.testng.annotations.Test)49 ImmutableMap (com.google.common.collect.ImmutableMap)45 Symbol (io.prestosql.spi.plan.Symbol)36 List (java.util.List)31 Type (io.prestosql.spi.type.Type)24 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)21 PlanMatchPattern.values (io.prestosql.sql.planner.assertions.PlanMatchPattern.values)21 ArrayList (java.util.ArrayList)20 Assignments (io.prestosql.spi.plan.Assignments)19 VARCHAR (io.prestosql.spi.type.VarcharType.VARCHAR)19 Assert.assertTrue (org.testng.Assert.assertTrue)19 Assert.assertEquals (org.testng.Assert.assertEquals)18 Metadata (io.prestosql.metadata.Metadata)16 DOUBLE (io.prestosql.spi.type.DoubleType.DOUBLE)16 BeforeClass (org.testng.annotations.BeforeClass)16 Assert.assertFalse (org.testng.Assert.assertFalse)15 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)14