Search in sources :

Example 1 with LongBigArray

use of com.facebook.presto.array.LongBigArray 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 LongBigArray

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

the class TypedHistogram method addAll.

public void addAll(TypedHistogram other) {
    Block otherValues = other.getValues();
    LongBigArray otherCounts = other.getCounts();
    for (int i = 0; i < otherValues.getPositionCount(); i++) {
        long count = otherCounts.get(i);
        if (count > 0) {
            add(i, otherValues, count);
        }
    }
}
Also used : LongBigArray(com.facebook.presto.array.LongBigArray) Block(com.facebook.presto.spi.block.Block)

Example 3 with LongBigArray

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

the class BenchmarkGroupByHash method baselineBigArray.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public long baselineBigArray(BaselinePagesData data) {
    int hashSize = arraySize(GROUP_COUNT, 0.9f);
    int mask = hashSize - 1;
    LongBigArray table = new LongBigArray(-1);
    table.ensureCapacity(hashSize);
    long groupIds = 0;
    for (Page page : data.getPages()) {
        Block block = page.getBlock(0);
        int positionCount = block.getPositionCount();
        for (int position = 0; position < positionCount; position++) {
            long value = BIGINT.getLong(block, position);
            int tablePosition = (int) XxHash64.hash(value) & mask;
            while (table.get(tablePosition) != -1 && table.get(tablePosition) != value) {
                tablePosition++;
            }
            if (table.get(tablePosition) == -1) {
                table.set(tablePosition, value);
                groupIds++;
            }
        }
    }
    return groupIds;
}
Also used : LongBigArray(com.facebook.presto.array.LongBigArray) Block(com.facebook.presto.spi.block.Block) Page(com.facebook.presto.spi.Page) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Aggregations

LongBigArray (com.facebook.presto.array.LongBigArray)3 Block (com.facebook.presto.spi.block.Block)2 IntBigArray (com.facebook.presto.array.IntBigArray)1 Page (com.facebook.presto.spi.Page)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 OperationsPerInvocation (org.openjdk.jmh.annotations.OperationsPerInvocation)1