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);
}
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);
}
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);
}
}
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");
}
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");
}
Aggregations