Search in sources :

Example 1 with IntBigArray

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

the class BigintGroupByHash method rehash.

private void rehash() {
    expectedHashCollisions += estimateNumberOfHashCollisions(getGroupCount(), hashCapacity);
    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;
    LongBigArray newValues = new LongBigArray();
    newValues.ensureCapacity(newCapacity);
    IntBigArray newGroupIds = new IntBigArray(-1);
    newGroupIds.ensureCapacity(newCapacity);
    for (int groupId = 0; groupId < nextGroupId; groupId++) {
        if (groupId == nullGroupId) {
            continue;
        }
        long value = valuesByGroupId.get(groupId);
        // find an empty slot for the address
        long hashPosition = getHashPosition(value, newMask);
        while (newGroupIds.get(hashPosition) != -1) {
            hashPosition = (hashPosition + 1) & newMask;
            hashCollisions++;
        }
        // record the mapping
        newValues.set(hashPosition, value);
        newGroupIds.set(hashPosition, groupId);
    }
    mask = newMask;
    hashCapacity = newCapacity;
    maxFill = calculateMaxFill(hashCapacity);
    values = newValues;
    groupIds = newGroupIds;
    this.valuesByGroupId.ensureCapacity(maxFill);
}
Also used : LongBigArray(com.facebook.presto.array.LongBigArray) IntBigArray(com.facebook.presto.array.IntBigArray) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with IntBigArray

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

the class InMemoryHashAggregationBuilder method hashSortedGroupIds.

private IntIterator hashSortedGroupIds() {
    IntBigArray groupIds = new IntBigArray();
    groupIds.ensureCapacity(groupByHash.getGroupCount());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        groupIds.set(i, i);
    }
    groupIds.sort(0, groupByHash.getGroupCount(), (leftGroupId, rightGroupId) -> Long.compare(groupByHash.getRawHash(leftGroupId), groupByHash.getRawHash(rightGroupId)));
    return new AbstractIntIterator() {

        private final int totalPositions = groupByHash.getGroupCount();

        private int position = 0;

        @Override
        public boolean hasNext() {
            return position < totalPositions;
        }

        @Override
        public int nextInt() {
            return groupIds.get(position++);
        }
    };
}
Also used : AbstractIntIterator(it.unimi.dsi.fastutil.ints.AbstractIntIterator) IntBigArray(com.facebook.presto.array.IntBigArray)

Example 3 with IntBigArray

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

the class TypedHistogram method rehash.

private void rehash(int size) {
    int newSize = arraySize(size + 1, FILL_RATIO);
    int newMask = newSize - 1;
    IntBigArray newHashPositions = new IntBigArray(-1);
    newHashPositions.ensureCapacity(newSize);
    for (int i = 0; i < values.getPositionCount(); i++) {
        // find an empty slot for the address
        int hashPosition = getHashPosition(TypeUtils.hashPosition(type, values, i), newMask);
        while (newHashPositions.get(hashPosition) != -1) {
            hashPosition = (hashPosition + 1) & newMask;
        }
        // record the mapping
        newHashPositions.set(hashPosition, i);
    }
    mask = newMask;
    maxFill = calculateMaxFill(newSize);
    hashPositions = newHashPositions;
    this.counts.ensureCapacity(maxFill);
}
Also used : IntBigArray(com.facebook.presto.array.IntBigArray)

Aggregations

IntBigArray (com.facebook.presto.array.IntBigArray)3 LongBigArray (com.facebook.presto.array.LongBigArray)1 PrestoException (com.facebook.presto.spi.PrestoException)1 AbstractIntIterator (it.unimi.dsi.fastutil.ints.AbstractIntIterator)1