Search in sources :

Example 1 with StoragePageSink

use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.

the class TestShardCompactor method createShards.

private static List<ShardInfo> createShards(StorageManager storageManager, List<Long> columnIds, List<Type> columnTypes, int shardCount) {
    StoragePageSink sink = createStoragePageSink(storageManager, columnIds, columnTypes);
    for (int i = 0; i < shardCount; i++) {
        sink.appendPages(createPages(columnTypes));
        sink.flush();
    }
    return getFutureValue(sink.commit());
}
Also used : StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink)

Example 2 with StoragePageSink

use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.

the class ShardCompactor method compact.

public List<ShardInfo> compact(long transactionId, boolean tableSupportsDeltaDelete, OptionalInt bucketNumber, Map<UUID, Optional<UUID>> uuidsMap, List<ColumnInfo> columns) throws IOException {
    long start = System.nanoTime();
    List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
    List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
    StoragePageSink storagePageSink = storageManager.createStoragePageSink(DEFAULT_RAPTOR_CONTEXT, transactionId, bucketNumber, columnIds, columnTypes, false);
    List<ShardInfo> shardInfos;
    try {
        shardInfos = compact(storagePageSink, tableSupportsDeltaDelete, bucketNumber, uuidsMap, columnIds, columnTypes);
    } catch (IOException | RuntimeException e) {
        storagePageSink.rollback();
        throw e;
    }
    int deltaCount = uuidsMap.values().stream().filter(Optional::isPresent).collect(toSet()).size();
    updateStats(uuidsMap.size(), deltaCount, shardInfos.size(), nanosSince(start).toMillis());
    return shardInfos;
}
Also used : Optional(java.util.Optional) StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) IOException(java.io.IOException) Type(com.facebook.presto.common.type.Type) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 3 with StoragePageSink

use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.

the class ShardCompactor method compactSorted.

public List<ShardInfo> compactSorted(long transactionId, OptionalInt bucketNumber, Set<UUID> uuids, List<ColumnInfo> columns, List<Long> sortColumnIds, List<SortOrder> sortOrders) throws IOException {
    checkArgument(sortColumnIds.size() == sortOrders.size(), "sortColumnIds and sortOrders must be of the same size");
    long start = System.nanoTime();
    List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
    List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
    checkArgument(columnIds.containsAll(sortColumnIds), "sortColumnIds must be a subset of columnIds");
    List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
    Queue<SortedRowSource> rowSources = new PriorityQueue<>();
    StoragePageSink outputPageSink = storageManager.createStoragePageSink(transactionId, bucketNumber, columnIds, columnTypes, false);
    try {
        for (UUID uuid : uuids) {
            ConnectorPageSource pageSource = storageManager.getPageSource(uuid, bucketNumber, columnIds, columnTypes, TupleDomain.all(), readerAttributes);
            SortedRowSource rowSource = new SortedRowSource(pageSource, columnTypes, sortIndexes, sortOrders);
            rowSources.add(rowSource);
        }
        while (!rowSources.isEmpty()) {
            SortedRowSource rowSource = rowSources.poll();
            if (!rowSource.hasNext()) {
                // rowSource is empty, close it
                rowSource.close();
                continue;
            }
            outputPageSink.appendRow(rowSource.next());
            if (outputPageSink.isFull()) {
                outputPageSink.flush();
            }
            rowSources.add(rowSource);
        }
        outputPageSink.flush();
        List<ShardInfo> shardInfos = getFutureValue(outputPageSink.commit());
        updateStats(uuids.size(), shardInfos.size(), nanosSince(start).toMillis());
        return shardInfos;
    } catch (IOException | RuntimeException e) {
        outputPageSink.rollback();
        throw e;
    } finally {
        rowSources.forEach(SortedRowSource::closeQuietly);
    }
}
Also used : StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) IOException(java.io.IOException) PriorityQueue(java.util.PriorityQueue) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) Type(com.facebook.presto.spi.type.Type) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 4 with StoragePageSink

use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.

the class ShardCompactor method compact.

public List<ShardInfo> compact(long transactionId, OptionalInt bucketNumber, Set<UUID> uuids, List<ColumnInfo> columns) throws IOException {
    long start = System.nanoTime();
    List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
    List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
    StoragePageSink storagePageSink = storageManager.createStoragePageSink(transactionId, bucketNumber, columnIds, columnTypes, false);
    List<ShardInfo> shardInfos;
    try {
        shardInfos = compact(storagePageSink, bucketNumber, uuids, columnIds, columnTypes);
    } catch (IOException | RuntimeException e) {
        storagePageSink.rollback();
        throw e;
    }
    updateStats(uuids.size(), shardInfos.size(), nanosSince(start).toMillis());
    return shardInfos;
}
Also used : Type(com.facebook.presto.spi.type.Type) StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) IOException(java.io.IOException) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

Example 5 with StoragePageSink

use of com.facebook.presto.raptor.storage.StoragePageSink in project presto by prestodb.

the class ShardCompactor method compactSorted.

public List<ShardInfo> compactSorted(long transactionId, boolean tableSupportsDeltaDelete, OptionalInt bucketNumber, Map<UUID, Optional<UUID>> uuidsMap, List<ColumnInfo> columns, List<Long> sortColumnIds, List<SortOrder> sortOrders) throws IOException {
    checkArgument(sortColumnIds.size() == sortOrders.size(), "sortColumnIds and sortOrders must be of the same size");
    long start = System.nanoTime();
    List<Long> columnIds = columns.stream().map(ColumnInfo::getColumnId).collect(toList());
    List<Type> columnTypes = columns.stream().map(ColumnInfo::getType).collect(toList());
    checkArgument(columnIds.containsAll(sortColumnIds), "sortColumnIds must be a subset of columnIds");
    List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
    Queue<SortedPageSource> rowSources = new PriorityQueue<>();
    StoragePageSink outputPageSink = storageManager.createStoragePageSink(DEFAULT_RAPTOR_CONTEXT, transactionId, bucketNumber, columnIds, columnTypes, false);
    try {
        uuidsMap.forEach((uuid, deltaUuid) -> {
            ConnectorPageSource pageSource = storageManager.getPageSource(DEFAULT_RAPTOR_CONTEXT, DEFAULT_HIVE_FILE_CONTEXT, uuid, deltaUuid, tableSupportsDeltaDelete, bucketNumber, columnIds, columnTypes, TupleDomain.all(), readerAttributes);
            SortedPageSource rowSource = new SortedPageSource(pageSource, columnTypes, sortIndexes, sortOrders);
            rowSources.add(rowSource);
        });
        while (!rowSources.isEmpty()) {
            SortedPageSource rowSource = rowSources.poll();
            if (!rowSource.hasNext()) {
                // rowSource is empty, close it
                rowSource.close();
                continue;
            }
            outputPageSink.appendPages(ImmutableList.of(rowSource.next()));
            if (outputPageSink.isFull()) {
                outputPageSink.flush();
            }
            rowSources.add(rowSource);
        }
        outputPageSink.flush();
        List<ShardInfo> shardInfos = getFutureValue(outputPageSink.commit());
        int deltaCount = uuidsMap.values().stream().filter(Optional::isPresent).collect(toSet()).size();
        updateStats(uuidsMap.size(), deltaCount, shardInfos.size(), nanosSince(start).toMillis());
        return shardInfos;
    } catch (IOException | RuntimeException e) {
        outputPageSink.rollback();
        throw e;
    } finally {
        rowSources.forEach(SortedPageSource::closeQuietly);
    }
}
Also used : Optional(java.util.Optional) StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) IOException(java.io.IOException) PriorityQueue(java.util.PriorityQueue) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) Type(com.facebook.presto.common.type.Type) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo)

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