Search in sources :

Example 1 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestDatabaseShardManager method testShardPruningTruncatedValues.

@Test
public void testShardPruningTruncatedValues() throws Exception {
    String prefix = repeat("x", MAX_BINARY_INDEX_SIZE);
    ColumnStats stats = new ColumnStats(1, prefix + "a", prefix + "z");
    ShardInfo shard = shardInfo(UUID.randomUUID(), "node", ImmutableList.of(stats));
    List<ShardInfo> shards = ImmutableList.of(shard);
    List<ColumnInfo> columns = ImmutableList.of(new ColumnInfo(1, createVarcharType(10)));
    RaptorColumnHandle c1 = new RaptorColumnHandle("raptor", "c1", 1, createVarcharType(10));
    long tableId = createTable("test");
    shardManager.createTable(tableId, columns, false, OptionalLong.empty());
    long transactionId = shardManager.beginTransaction();
    shardManager.commitShards(transactionId, tableId, columns, shards, Optional.empty(), 0);
    shardAssertion(tableId).expected(shards);
    shardAssertion(tableId).equal(c1, createVarcharType(10), utf8Slice(prefix)).expected(shards);
    shardAssertion(tableId).equal(c1, createVarcharType(10), utf8Slice(prefix + "c")).expected(shards);
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice(prefix + "c"))).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice(prefix + "zzz"))).expected(shards);
    shardAssertion(tableId).between(c1, createVarcharType(10), utf8Slice("w"), utf8Slice("y")).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice("x"))).expected(shards);
    shardAssertion(tableId).between(c1, createVarcharType(10), utf8Slice("x"), utf8Slice("x")).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice("w"))).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), utf8Slice("x"))).expected();
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), utf8Slice("y"))).expected();
    Slice shorter = utf8Slice(prefix.substring(0, prefix.length() - 1));
    shardAssertion(tableId).equal(c1, createVarcharType(10), shorter).expected();
    shardAssertion(tableId).range(c1, lessThan(createVarcharType(10), shorter)).expected();
    shardAssertion(tableId).range(c1, greaterThan(createVarcharType(10), shorter)).expected(shards);
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) Test(org.testng.annotations.Test)

Example 2 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestDatabaseShardManager method testShardPruning.

@Test
public void testShardPruning() throws Exception {
    ShardInfo shard1 = shardInfo(UUID.randomUUID(), "node1", ImmutableList.<ColumnStats>builder().add(new ColumnStats(1, 5, 10)).add(new ColumnStats(2, -20.0, 20.0)).add(new ColumnStats(3, date(2013, 5, 11), date(2013, 6, 13))).add(new ColumnStats(4, timestamp(2013, 5, 11, 4, 5, 6), timestamp(2013, 6, 13, 7, 8, 9))).add(new ColumnStats(5, "hello", "world")).add(new ColumnStats(6, false, true)).build());
    ShardInfo shard2 = shardInfo(UUID.randomUUID(), "node2", ImmutableList.<ColumnStats>builder().add(new ColumnStats(1, 2, 8)).add(new ColumnStats(2, null, 50.0)).add(new ColumnStats(3, date(2012, 1, 1), date(2012, 12, 31))).add(new ColumnStats(4, timestamp(2012, 1, 1, 2, 3, 4), timestamp(2012, 12, 31, 5, 6, 7))).add(new ColumnStats(5, "cat", "dog")).add(new ColumnStats(6, true, true)).build());
    ShardInfo shard3 = shardInfo(UUID.randomUUID(), "node3", ImmutableList.<ColumnStats>builder().add(new ColumnStats(1, 15, 20)).add(new ColumnStats(2, null, null)).add(new ColumnStats(3, date(2013, 4, 1), date(2013, 6, 1))).add(new ColumnStats(4, timestamp(2013, 4, 1, 8, 7, 6), timestamp(2013, 6, 1, 6, 5, 4))).add(new ColumnStats(5, "grape", "orange")).add(new ColumnStats(6, false, false)).build());
    List<ShardInfo> shards = ImmutableList.<ShardInfo>builder().add(shard1).add(shard2).add(shard3).build();
    List<ColumnInfo> columns = ImmutableList.<ColumnInfo>builder().add(new ColumnInfo(1, BIGINT)).add(new ColumnInfo(2, DOUBLE)).add(new ColumnInfo(3, DATE)).add(new ColumnInfo(4, TIMESTAMP)).add(new ColumnInfo(5, createVarcharType(10))).add(new ColumnInfo(6, BOOLEAN)).add(new ColumnInfo(7, VARBINARY)).build();
    RaptorColumnHandle c1 = new RaptorColumnHandle("raptor", "c1", 1, BIGINT);
    RaptorColumnHandle c2 = new RaptorColumnHandle("raptor", "c2", 2, DOUBLE);
    RaptorColumnHandle c3 = new RaptorColumnHandle("raptor", "c3", 3, DATE);
    RaptorColumnHandle c4 = new RaptorColumnHandle("raptor", "c4", 4, TIMESTAMP);
    RaptorColumnHandle c5 = new RaptorColumnHandle("raptor", "c5", 5, createVarcharType(10));
    RaptorColumnHandle c6 = new RaptorColumnHandle("raptor", "c6", 6, BOOLEAN);
    long tableId = createTable("test");
    shardManager.createTable(tableId, columns, false, OptionalLong.empty());
    long transactionId = shardManager.beginTransaction();
    shardManager.commitShards(transactionId, tableId, columns, shards, Optional.empty(), 0);
    shardAssertion(tableId).expected(shards);
    shardAssertion(tableId).equal(c1, BIGINT, 3L).expected(shard2);
    shardAssertion(tableId).equal(c1, BIGINT, 8L).expected(shard1, shard2);
    shardAssertion(tableId).equal(c1, BIGINT, 9L).expected(shard1);
    shardAssertion(tableId).equal(c1, BIGINT, 13L).expected();
    shardAssertion(tableId).between(c1, BIGINT, 8L, 14L).expected(shard1, shard2);
    shardAssertion(tableId).between(c1, BIGINT, 8L, 15L).expected(shards);
    shardAssertion(tableId).between(c1, BIGINT, 8L, 16L).expected(shards);
    shardAssertion(tableId).between(c1, BIGINT, 12L, 14L).expected();
    shardAssertion(tableId).between(c1, BIGINT, 5L, 10L).expected(shard1, shard2);
    shardAssertion(tableId).between(c1, BIGINT, 16L, 18L).expected(shard3);
    shardAssertion(tableId).between(c1, BIGINT, 1L, 25L).expected(shards);
    shardAssertion(tableId).between(c1, BIGINT, 4L, 12L).expected(shard1, shard2);
    shardAssertion(tableId).range(c1, lessThan(BIGINT, 5L)).expected(shard1, shard2);
    shardAssertion(tableId).range(c1, lessThan(BIGINT, 4L)).expected(shard2);
    shardAssertion(tableId).range(c1, lessThan(BIGINT, 11L)).expected(shard1, shard2);
    shardAssertion(tableId).range(c1, lessThan(BIGINT, 25L)).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(BIGINT, 1L)).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(BIGINT, 8L)).expected(shards);
    shardAssertion(tableId).range(c1, greaterThan(BIGINT, 9L)).expected(shard1, shard3);
    shardAssertion(tableId).between(c1, BIGINT, -25L, 25L).between(c2, DOUBLE, -1000.0, 1000.0).between(c3, BIGINT, 0L, 50000L).between(c4, TIMESTAMP, 0L, timestamp(2015, 1, 2, 3, 4, 5)).between(c5, createVarcharType(10), utf8Slice("a"), utf8Slice("zzzzz")).between(c6, BOOLEAN, false, true).expected(shards);
    shardAssertion(tableId).between(c1, BIGINT, 4L, 12L).between(c3, DATE, date(2013, 3, 3), date(2013, 5, 25)).expected(shard1);
    shardAssertion(tableId).equal(c2, DOUBLE, 25.0).expected(shard2, shard3);
    shardAssertion(tableId).equal(c2, DOUBLE, 50.1).expected(shard3);
    shardAssertion(tableId).equal(c3, DATE, date(2013, 5, 12)).expected(shard1, shard3);
    shardAssertion(tableId).range(c4, greaterThan(TIMESTAMP, timestamp(2013, 1, 1, 0, 0, 0))).expected(shard1, shard3);
    shardAssertion(tableId).between(c5, createVarcharType(10), utf8Slice("cow"), utf8Slice("milk")).expected(shards);
    shardAssertion(tableId).equal(c5, createVarcharType(10), utf8Slice("fruit")).expected();
    shardAssertion(tableId).equal(c5, createVarcharType(10), utf8Slice("pear")).expected(shard1);
    shardAssertion(tableId).equal(c5, createVarcharType(10), utf8Slice("cat")).expected(shard2);
    shardAssertion(tableId).range(c5, greaterThan(createVarcharType(10), utf8Slice("gum"))).expected(shard1, shard3);
    shardAssertion(tableId).range(c5, lessThan(createVarcharType(10), utf8Slice("air"))).expected();
    shardAssertion(tableId).equal(c6, BOOLEAN, true).expected(shard1, shard2);
    shardAssertion(tableId).equal(c6, BOOLEAN, false).expected(shard1, shard3);
    shardAssertion(tableId).range(c6, greaterThanOrEqual(BOOLEAN, false)).expected(shards);
    shardAssertion(tableId).range(c6, lessThan(BOOLEAN, true)).expected(shards);
    shardAssertion(tableId).range(c6, lessThan(BOOLEAN, false)).expected(shard1, shard3);
    // TODO: support multiple ranges
    shardAssertion(tableId).domain(c1, createDomain(lessThan(BIGINT, 0L), greaterThan(BIGINT, 25L))).expected(shards);
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) Test(org.testng.annotations.Test)

Example 3 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestOrcStorageManager method testReader.

@Test
public void testReader() throws Exception {
    OrcStorageManager manager = createOrcStorageManager();
    List<Long> columnIds = ImmutableList.of(2L, 4L, 6L, 7L, 8L, 9L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DATE, BOOLEAN, DOUBLE);
    byte[] bytes1 = octets(0x00, 0xFE, 0xFF);
    byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80);
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    Object[][] doubles = { { 881L, "-inf", null, null, null, Double.NEGATIVE_INFINITY }, { 882L, "+inf", null, null, null, Double.POSITIVE_INFINITY }, { 883L, "nan", null, null, null, Double.NaN }, { 884L, "min", null, null, null, Double.MIN_VALUE }, { 885L, "max", null, null, null, Double.MAX_VALUE }, { 886L, "pzero", null, null, null, 0.0 }, { 887L, "nzero", null, null, null, -0.0 } };
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello", wrappedBuffer(bytes1), sqlDate(2001, 8, 22).getDays(), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", wrappedBuffer(bytes3), sqlDate(2005, 4, 22).getDays(), false, 987.65).rows(doubles).build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shards.size(), 1);
    UUID uuid = Iterables.getOnlyElement(shards).getShardUuid();
    MaterializedResult expected = resultBuilder(SESSION, columnTypes).row(123L, "hello", sqlBinary(bytes1), sqlDate(2001, 8, 22), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", sqlBinary(bytes3), sqlDate(2005, 4, 22), false, 987.65).rows(doubles).build();
    // no tuple domain (all)
    TupleDomain<RaptorColumnHandle> tupleDomain = TupleDomain.all();
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
        assertEquals(result, expected);
    }
    // tuple domain within the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 124L)).build());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
    }
    // tuple domain outside the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 122L)).build());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), 0);
    }
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) NullableValue(com.facebook.presto.spi.predicate.NullableValue) Page(com.facebook.presto.spi.Page) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Type(com.facebook.presto.spi.type.Type) OptionalLong(java.util.OptionalLong) UUID(java.util.UUID) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 4 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestShardPredicate method testInvalidUuid.

@Test
public void testInvalidUuid() throws Exception {
    Slice uuid0 = utf8Slice("test1");
    Slice uuid1 = utf8Slice("test2");
    TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(shardUuidColumnHandle("test"), create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
    ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain, bucketed);
    assertEquals(shardPredicate.getPredicate(), "true");
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Test(org.testng.annotations.Test)

Example 5 with RaptorColumnHandle

use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.

the class TestShardPredicate method testRangeShardUuidPredicate.

@Test
public void testRangeShardUuidPredicate() throws Exception {
    Slice uuid0 = utf8Slice(randomUUID().toString());
    TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(shardUuidColumnHandle("test"), create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(greaterThanOrEqual(VARCHAR, uuid0))), false)));
    ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain, bucketed);
    assertEquals(shardPredicate.getPredicate(), "true");
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Test(org.testng.annotations.Test)

Aggregations

RaptorColumnHandle (com.facebook.presto.raptor.RaptorColumnHandle)9 Test (org.testng.annotations.Test)8 Slice (io.airlift.slice.Slice)4 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)4 Type (com.facebook.presto.spi.type.Type)2 ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)1 ColumnIndexStatsUtils.jdbcType (com.facebook.presto.raptor.storage.ColumnIndexStatsUtils.jdbcType)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)1 Page (com.facebook.presto.spi.Page)1 Domain (com.facebook.presto.spi.predicate.Domain)1 NullableValue (com.facebook.presto.spi.predicate.NullableValue)1 Range (com.facebook.presto.spi.predicate.Range)1 Ranges (com.facebook.presto.spi.predicate.Ranges)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1