use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.
the class TestShardCompactor method testShardCompactorWithDelta.
@Test
public void testShardCompactorWithDelta() throws Exception {
StorageManager storageManager = createOrcStorageManager(dbi, temporary, MAX_SHARD_ROWS);
List<Long> columnIds = ImmutableList.of(3L, 7L, 2L, 1L, 5L);
List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), DOUBLE, DATE, TIMESTAMP);
List<ShardInfo> inputShards = createShards(storageManager, columnIds, columnTypes, 3);
assertEquals(inputShards.size(), 3);
List<Long> deltaColumnIds = ImmutableList.of(1L);
List<Type> deltaColumnTypes = ImmutableList.of(BIGINT);
StoragePageSink deltaSink = createStoragePageSink(storageManager, deltaColumnIds, deltaColumnTypes);
List<Page> deltaPages = rowPagesBuilder(deltaColumnTypes).row(1L).row(2L).build();
deltaSink.appendPages(deltaPages);
List<ShardInfo> deltaShards = getFutureValue(deltaSink.commit());
long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
long expectedOutputShardsCount = computeExpectedOutputShards(totalRows - 2);
Map<UUID, Optional<UUID>> inputUuidsMap = new HashMap<>();
inputUuidsMap.put(inputShards.get(0).getShardUuid(), Optional.of(deltaShards.get(0).getShardUuid()));
inputUuidsMap.put(inputShards.get(1).getShardUuid(), Optional.empty());
inputUuidsMap.put(inputShards.get(2).getShardUuid(), Optional.empty());
long transactionId = 1;
ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
List<ShardInfo> outputShards = compactor.compact(transactionId, true, OptionalInt.empty(), inputUuidsMap, getColumnInfo(columnIds, columnTypes));
assertEquals(outputShards.size(), expectedOutputShardsCount);
Set<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toSet());
assertShardEqualsIgnoreOrder(storageManager, inputUuidsMap, outputUuids, columnIds, columnTypes);
}
Aggregations