Search in sources :

Example 1 with LongBigArray

use of io.prestosql.array.LongBigArray in project hetu-core by openlookeng.

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(io.prestosql.array.LongBigArray) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

Example 2 with LongBigArray

use of io.prestosql.array.LongBigArray in project hetu-core by openlookeng.

the class BigintGroupByHash method tryToIncreaseCapacity.

public boolean tryToIncreaseCapacity() {
    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 = toIntExact(newCapacityLong);
    // An estimate of how much extra memory is needed before we can go ahead and expand the hash table.
    // This includes the new capacity for values, groupIds, and valuesByGroupId as well as the size of the current page
    preallocatedMemoryInBytes = (newCapacity - hashCapacity) * (long) (Long.BYTES + Integer.BYTES) + (calculateMaxFill(newCapacity) - maxFill) * Long.BYTES + currentPageSizeInBytes;
    if (!updateMemory.update()) {
        // reserved memory but has exceeded the limit
        return false;
    }
    preallocatedMemoryInBytes = 0;
    expectedHashCollisions += estimateNumberOfHashCollisions(getGroupCount(), hashCapacity);
    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);
    return true;
}
Also used : LongBigArray(io.prestosql.array.LongBigArray) IntBigArray(io.prestosql.array.IntBigArray) PrestoException(io.prestosql.spi.PrestoException)

Aggregations

LongBigArray (io.prestosql.array.LongBigArray)2 IntBigArray (io.prestosql.array.IntBigArray)1 Page (io.prestosql.spi.Page)1 PrestoException (io.prestosql.spi.PrestoException)1 Block (io.prestosql.spi.block.Block)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1 OperationsPerInvocation (org.openjdk.jmh.annotations.OperationsPerInvocation)1