Search in sources :

Example 1 with ShardInfo

use of com.facebook.presto.raptor.metadata.ShardInfo in project presto by prestodb.

the class OrcStorageManager method shardDelta.

private static Collection<Slice> shardDelta(UUID oldShardUuid, Optional<ShardInfo> shardInfo) {
    List<ShardInfo> newShards = shardInfo.map(ImmutableList::of).orElse(ImmutableList.of());
    ShardDelta delta = new ShardDelta(ImmutableList.of(oldShardUuid), newShards);
    return ImmutableList.of(Slices.wrappedBuffer(SHARD_DELTA_CODEC.toJsonBytes(delta)));
}
Also used : ShardDelta(com.facebook.presto.raptor.metadata.ShardDelta) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 2 with ShardInfo

use of com.facebook.presto.raptor.metadata.ShardInfo in project presto by prestodb.

the class OrcStorageManager method rewriteShard.

@VisibleForTesting
Collection<Slice> rewriteShard(long transactionId, OptionalInt bucketNumber, UUID shardUuid, BitSet rowsToDelete) {
    if (rowsToDelete.isEmpty()) {
        return ImmutableList.of();
    }
    UUID newShardUuid = UUID.randomUUID();
    File input = storageService.getStorageFile(shardUuid);
    File output = storageService.getStagingFile(newShardUuid);
    OrcFileInfo info = rewriteFile(input, output, rowsToDelete);
    long rowCount = info.getRowCount();
    if (rowCount == 0) {
        return shardDelta(shardUuid, Optional.empty());
    }
    shardRecorder.recordCreatedShard(transactionId, newShardUuid);
    // submit for backup and wait until it finishes
    getFutureValue(backupManager.submit(newShardUuid, output));
    Set<String> nodes = ImmutableSet.of(nodeId);
    long uncompressedSize = info.getUncompressedSize();
    ShardInfo shard = createShardInfo(newShardUuid, bucketNumber, output, nodes, rowCount, uncompressedSize);
    writeShard(newShardUuid);
    return shardDelta(shardUuid, Optional.of(shard));
}
Also used : OrcFileInfo(com.facebook.presto.raptor.storage.OrcFileRewriter.OrcFileInfo) UUID(java.util.UUID) File(java.io.File) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ShardInfo

use of com.facebook.presto.raptor.metadata.ShardInfo in project presto by prestodb.

the class OrganizationJob method runJob.

private void runJob(long transactionId, OptionalInt bucketNumber, long tableId, Set<UUID> shardUuids) throws IOException {
    TableMetadata metadata = getTableMetadata(tableId);
    List<ShardInfo> newShards = performCompaction(transactionId, bucketNumber, shardUuids, metadata);
    log.info("Compacted shards %s into %s", shardUuids, newShards.stream().map(ShardInfo::getShardUuid).collect(toList()));
    shardManager.replaceShardUuids(transactionId, tableId, metadata.getColumns(), shardUuids, newShards, OptionalLong.empty());
}
Also used : TableMetadata(com.facebook.presto.raptor.metadata.TableMetadata) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 4 with ShardInfo

use of com.facebook.presto.raptor.metadata.ShardInfo in project presto by prestodb.

the class TestShardCompactor method testShardCompactorSorted.

@Test(dataProvider = "useOptimizedOrcWriter")
public void testShardCompactorSorted(boolean useOptimizedOrcWriter) throws Exception {
    StorageManager storageManager = createOrcStorageManager(dbi, temporary, MAX_SHARD_ROWS);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), DATE, TIMESTAMP, DOUBLE);
    List<Long> columnIds = ImmutableList.of(3L, 7L, 2L, 1L, 5L);
    List<Long> sortColumnIds = ImmutableList.of(1L, 2L, 3L, 5L, 7L);
    List<SortOrder> sortOrders = nCopies(sortColumnIds.size(), ASC_NULLS_FIRST);
    List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
    List<ShardInfo> inputShards = createSortedShards(storageManager, columnIds, columnTypes, sortIndexes, sortOrders, 2);
    assertEquals(inputShards.size(), 2);
    long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
    long expectedOutputShards = computeExpectedOutputShards(totalRows);
    Map<UUID, Optional<UUID>> inputUuids = new HashMap<>();
    for (ShardInfo shardInfo : inputShards) {
        inputUuids.put(shardInfo.getShardUuid(), Optional.empty());
    }
    long transactionId = 1;
    ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
    List<ShardInfo> outputShards = compactor.compactSorted(transactionId, false, OptionalInt.empty(), inputUuids, getColumnInfo(columnIds, columnTypes), sortColumnIds, sortOrders);
    List<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toList());
    assertEquals(outputShards.size(), expectedOutputShards);
    assertShardEqualsSorted(storageManager, inputUuids.keySet(), outputUuids, columnIds, columnTypes, sortIndexes, sortOrders);
}
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) SortOrder(com.facebook.presto.common.block.SortOrder) 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)

Example 5 with ShardInfo

use of com.facebook.presto.raptor.metadata.ShardInfo in project presto by prestodb.

the class TestShardCompactor method testShardCompactor.

@Test(dataProvider = "useOptimizedOrcWriter")
public void testShardCompactor(boolean useOptimizedOrcWriter) 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);
    long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
    long expectedOutputShards = computeExpectedOutputShards(totalRows);
    Map<UUID, Optional<UUID>> inputUuids = new HashMap<>();
    for (ShardInfo shardInfo : inputShards) {
        inputUuids.put(shardInfo.getShardUuid(), Optional.empty());
    }
    long transactionId = 1;
    ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
    List<ShardInfo> outputShards = compactor.compact(transactionId, false, OptionalInt.empty(), inputUuids, getColumnInfo(columnIds, columnTypes));
    assertEquals(outputShards.size(), expectedOutputShards);
    Set<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toSet());
    assertShardEqualsIgnoreOrder(storageManager, inputUuids.keySet(), 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) 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

ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)25 UUID (java.util.UUID)12 Type (com.facebook.presto.common.type.Type)11 Test (org.testng.annotations.Test)11 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)8 Optional (java.util.Optional)7 Page (com.facebook.presto.common.Page)6 LocalOrcDataEnvironment (com.facebook.presto.raptor.filesystem.LocalOrcDataEnvironment)6 Slice (io.airlift.slice.Slice)6 File (java.io.File)6 RaptorLocalFileSystem (com.facebook.presto.raptor.filesystem.RaptorLocalFileSystem)5 StoragePageSink (com.facebook.presto.raptor.storage.StoragePageSink)5 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)5 ShardDeleteDelta (com.facebook.presto.raptor.metadata.ShardDeleteDelta)4 ShardDelta (com.facebook.presto.raptor.metadata.ShardDelta)4 RecordedShard (com.facebook.presto.raptor.storage.InMemoryShardRecorder.RecordedShard)4 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)4 IOException (java.io.IOException)4 OptionalLong (java.util.OptionalLong)4 FileSystem (org.apache.hadoop.fs.FileSystem)4