use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.
the class TestDatabaseShardManager method testShardPruningNoStats.
@Test
public void testShardPruningNoStats() throws Exception {
ShardInfo shard = shardInfo(UUID.randomUUID(), "node");
List<ShardInfo> shards = ImmutableList.of(shard);
long tableId = createTable("test");
List<ColumnInfo> columns = ImmutableList.of(new ColumnInfo(1, BIGINT));
RaptorColumnHandle c1 = new RaptorColumnHandle("raptor", "c1", 1, BIGINT);
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(shards);
}
use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.
the class ShardPredicate method create.
public static ShardPredicate create(TupleDomain<RaptorColumnHandle> tupleDomain, boolean bucketed) {
StringJoiner predicate = new StringJoiner(" AND ").setEmptyValue("true");
ImmutableList.Builder<JDBCType> types = ImmutableList.builder();
ImmutableList.Builder<Object> values = ImmutableList.builder();
for (Entry<RaptorColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
Domain domain = entry.getValue();
if (domain.isNullAllowed() || domain.isAll()) {
continue;
}
RaptorColumnHandle handle = entry.getKey();
Type type = handle.getColumnType();
JDBCType jdbcType = jdbcType(type);
if (jdbcType == null) {
continue;
}
if (handle.isShardUuid()) {
predicate.add(createShardPredicate(types, values, domain, jdbcType));
continue;
}
if (!domain.getType().isOrderable()) {
continue;
}
Ranges ranges = domain.getValues().getRanges();
// TODO: support multiple ranges
if (ranges.getRangeCount() != 1) {
continue;
}
Range range = getOnlyElement(ranges.getOrderedRanges());
Object minValue = null;
Object maxValue = null;
if (range.isSingleValue()) {
minValue = range.getSingleValue();
maxValue = range.getSingleValue();
} else {
if (!range.getLow().isLowerUnbounded()) {
minValue = range.getLow().getValue();
}
if (!range.getHigh().isUpperUnbounded()) {
maxValue = range.getHigh().getValue();
}
}
String min;
String max;
if (handle.isBucketNumber()) {
if (!bucketed) {
predicate.add("false");
continue;
}
min = "bucket_number";
max = "bucket_number";
} else {
min = minColumn(handle.getColumnId());
max = maxColumn(handle.getColumnId());
}
if (minValue != null) {
predicate.add(format("(%s >= ? OR %s IS NULL)", max, max));
types.add(jdbcType);
values.add(minValue);
}
if (maxValue != null) {
predicate.add(format("(%s <= ? OR %s IS NULL)", min, min));
types.add(jdbcType);
values.add(maxValue);
}
}
return new ShardPredicate(predicate.toString(), types.build(), values.build());
}
use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.
the class TestShardPredicate method testDiscreteShardUuidPredicate.
@Test
public void testDiscreteShardUuidPredicate() throws Exception {
Slice uuid0 = utf8Slice(randomUUID().toString());
Slice uuid1 = utf8Slice(randomUUID().toString());
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(), "shard_uuid = ? OR shard_uuid = ?");
assertEquals(shardPredicate.getTypes(), ImmutableList.of(VARBINARY, VARBINARY));
assertEquals(ImmutableSet.copyOf(shardPredicate.getValues()), ImmutableSet.of(uuidStringToBytes(uuid0), uuidStringToBytes(uuid1)));
}
use of com.facebook.presto.raptor.RaptorColumnHandle in project presto by prestodb.
the class TestRaptorMetadata method testCreateTable.
@Test
public void testCreateTable() {
assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
metadata.createTable(SESSION, getOrdersTable());
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
assertInstanceOf(tableHandle, RaptorTableHandle.class);
assertEquals(((RaptorTableHandle) tableHandle).getTableId(), 1);
ConnectorTableMetadata table = metadata.getTableMetadata(SESSION, tableHandle);
assertTableEqual(table, getOrdersTable());
ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
assertInstanceOf(columnHandle, RaptorColumnHandle.class);
assertEquals(((RaptorColumnHandle) columnHandle).getColumnId(), 1);
ColumnMetadata columnMetadata = metadata.getColumnMetadata(SESSION, tableHandle, columnHandle);
assertNotNull(columnMetadata);
assertEquals(columnMetadata.getName(), "orderkey");
assertEquals(columnMetadata.getType(), BIGINT);
}
Aggregations