Search in sources :

Example 6 with StoragePageSink

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);
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) StorageManager(com.facebook.presto.raptor.storage.StorageManager) TestOrcStorageManager.createOrcStorageManager(com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager) Page(com.facebook.presto.common.Page) StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Aggregations

StoragePageSink (com.facebook.presto.raptor.storage.StoragePageSink)6 ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)5 IOException (java.io.IOException)4 Type (com.facebook.presto.common.type.Type)3 Optional (java.util.Optional)3 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)2 Type (com.facebook.presto.spi.type.Type)2 PriorityQueue (java.util.PriorityQueue)2 UUID (java.util.UUID)2 Page (com.facebook.presto.common.Page)1 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)1 StorageManager (com.facebook.presto.raptor.storage.StorageManager)1 TestOrcStorageManager.createOrcStorageManager (com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1