Search in sources :

Example 1 with BytePrimitiveArrayComparator

use of org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArrayComparator in project flink by apache.

the class HashTableTest method testSpillingWhenBuildingTableWithoutOverflow.

/**
	 * Tests that the MutableHashTable spills its partitions when creating the initial table
	 * without overflow segments in the partitions. This means that the records are large.
	 */
@Test
public void testSpillingWhenBuildingTableWithoutOverflow() throws Exception {
    final IOManager ioMan = new IOManagerAsync();
    final TypeSerializer<byte[]> serializer = BytePrimitiveArraySerializer.INSTANCE;
    final TypeComparator<byte[]> buildComparator = new BytePrimitiveArrayComparator(true);
    final TypeComparator<byte[]> probeComparator = new BytePrimitiveArrayComparator(true);
    @SuppressWarnings("unchecked") final TypePairComparator<byte[], byte[]> pairComparator = new GenericPairComparator<>(new BytePrimitiveArrayComparator(true), new BytePrimitiveArrayComparator(true));
    final int pageSize = 128;
    final int numSegments = 33;
    List<MemorySegment> memory = getMemory(numSegments, pageSize);
    MutableHashTable<byte[], byte[]> table = new MutableHashTable<byte[], byte[]>(serializer, serializer, buildComparator, probeComparator, pairComparator, memory, ioMan, 1, false);
    int numElements = 9;
    table.open(new CombiningIterator<byte[]>(new ByteArrayIterator(numElements, 128, (byte) 0), new ByteArrayIterator(numElements, 128, (byte) 1)), new CombiningIterator<byte[]>(new ByteArrayIterator(1, 128, (byte) 0), new ByteArrayIterator(1, 128, (byte) 1)));
    while (table.nextRecord()) {
        MutableObjectIterator<byte[]> iterator = table.getBuildSideIterator();
        int counter = 0;
        while (iterator.next() != null) {
            counter++;
        }
        // check that we retrieve all our elements
        Assert.assertEquals(numElements, counter);
    }
    table.close();
}
Also used : IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) MemorySegment(org.apache.flink.core.memory.MemorySegment) BytePrimitiveArrayComparator(org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArrayComparator) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) GenericPairComparator(org.apache.flink.api.common.typeutils.GenericPairComparator) Test(org.junit.Test)

Aggregations

GenericPairComparator (org.apache.flink.api.common.typeutils.GenericPairComparator)1 BytePrimitiveArrayComparator (org.apache.flink.api.common.typeutils.base.array.BytePrimitiveArrayComparator)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 IOManager (org.apache.flink.runtime.io.disk.iomanager.IOManager)1 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)1 Test (org.junit.Test)1