Search in sources :

Example 6 with IntBigArray

use of com.facebook.presto.common.array.IntBigArray in project presto by prestodb.

the class StreamSummary method compact.

private synchronized void compact() {
    BlockBuilder newHeapBlockBuilder = type.createBlockBuilder(null, heapBlockBuilder.getPositionCount());
    // since block positions are changed, we need to update all data structures which are using block position as reference
    LongBigArray newBlockPositionToCount = new LongBigArray();
    hashCapacity = arraySize(heapCapacity, FILL_RATIO);
    maxFill = calculateMaxFill(hashCapacity);
    newBlockPositionToCount.ensureCapacity(hashCapacity);
    IntBigArray newBlockToHeapIndex = new IntBigArray();
    newBlockToHeapIndex.ensureCapacity(hashCapacity);
    for (int heapPosition = 0; heapPosition < getHeapSize(); heapPosition++) {
        int newBlockPos = newHeapBlockBuilder.getPositionCount();
        StreamDataEntity heapEntry = minHeap.get(heapPosition);
        int oldBlockPosition = getBlockPosition(heapEntry);
        type.appendTo(heapBlockBuilder, oldBlockPosition, newHeapBlockBuilder);
        newBlockPositionToCount.set(newBlockPos, blockPositionToCount.get(oldBlockPosition));
        newBlockToHeapIndex.set(newBlockPos, heapPosition);
        hashToBlockPosition.set(heapEntry.getHashPosition(), newBlockPos);
    }
    blockPositionToCount = newBlockPositionToCount;
    heapBlockBuilder = newHeapBlockBuilder;
    blockToHeapIndex = newBlockToHeapIndex;
    rehash();
}
Also used : LongBigArray(com.facebook.presto.common.array.LongBigArray) IntBigArray(com.facebook.presto.common.array.IntBigArray) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 7 with IntBigArray

use of com.facebook.presto.common.array.IntBigArray in project presto by prestodb.

the class StreamSummary method rehash.

private void rehash() {
    long newCapacityLong = hashCapacity * 2L;
    if (newCapacityLong > Integer.MAX_VALUE) {
        throw new PrestoException(GENERIC_INSUFFICIENT_RESOURCES, "Size of hash table cannot exceed 1 billion entries");
    }
    int newCapacity = (int) newCapacityLong;
    int newMask = newCapacity - 1;
    IntBigArray newHashToBlockPosition = new IntBigArray(EMPTY);
    newHashToBlockPosition.ensureCapacity(newCapacity);
    for (int heapPosition = 0; heapPosition < getHeapSize(); heapPosition++) {
        StreamDataEntity heapEntry = minHeap.get(heapPosition);
        int blockPosition = getBlockPosition(heapEntry);
        // find an empty slot for the address
        int hashPosition = getBucketId(TypeUtils.hashPosition(type, heapBlockBuilder, blockPosition), newMask);
        while (newHashToBlockPosition.get(hashPosition) != EMPTY) {
            hashPosition = (hashPosition + 1) & newMask;
        }
        // record the mapping
        newHashToBlockPosition.set(hashPosition, blockPosition);
        heapEntry.setHashPosition(hashPosition);
    }
    hashCapacity = newCapacity;
    mask = newMask;
    maxFill = calculateMaxFill(newCapacity);
    this.hashToBlockPosition = newHashToBlockPosition;
    this.blockPositionToCount.ensureCapacity(maxFill);
    this.blockToHeapIndex.ensureCapacity(maxFill);
}
Also used : IntBigArray(com.facebook.presto.common.array.IntBigArray) PrestoException(com.facebook.presto.spi.PrestoException)

Aggregations

IntBigArray (com.facebook.presto.common.array.IntBigArray)7 PrestoException (com.facebook.presto.spi.PrestoException)5 LongBigArray (com.facebook.presto.common.array.LongBigArray)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AbstractIntIterator (it.unimi.dsi.fastutil.ints.AbstractIntIterator)1