Search in sources :

Example 1 with ByteValue

use of org.apache.flink.types.ByteValue in project flink by apache.

the class HashTableTest method testSpillingFreesOnlyOverflowSegments.

/**
	 * This tests the case where no additional partition buffers are used at the point when spilling
	 * is triggered, testing that overflow bucket buffers are taken into account when deciding which
	 * partition to spill.
	 */
@Test
public void testSpillingFreesOnlyOverflowSegments() {
    final IOManager ioMan = new IOManagerAsync();
    final TypeSerializer<ByteValue> serializer = ByteValueSerializer.INSTANCE;
    final TypeComparator<ByteValue> buildComparator = new ValueComparator<>(true, ByteValue.class);
    final TypeComparator<ByteValue> probeComparator = new ValueComparator<>(true, ByteValue.class);
    @SuppressWarnings("unchecked") final TypePairComparator<ByteValue, ByteValue> pairComparator = Mockito.mock(TypePairComparator.class);
    try {
        final int pageSize = 32 * 1024;
        final int numSegments = 34;
        List<MemorySegment> memory = getMemory(numSegments, pageSize);
        MutableHashTable<ByteValue, ByteValue> table = new MutableHashTable<>(serializer, serializer, buildComparator, probeComparator, pairComparator, memory, ioMan, 1, false);
        table.open(new ByteValueIterator(100000000), new ByteValueIterator(1));
        table.close();
        checkNoTempFilesRemain(ioMan);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        ioMan.shutdown();
    }
}
Also used : ByteValue(org.apache.flink.types.ByteValue) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) ValueComparator(org.apache.flink.api.java.typeutils.runtime.ValueComparator) MemorySegment(org.apache.flink.core.memory.MemorySegment) IOException(java.io.IOException) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) Test(org.junit.Test)

Example 2 with ByteValue

use of org.apache.flink.types.ByteValue in project flink by apache.

the class ByteValueComparatorTest method getSortedTestData.

@Override
protected ByteValue[] getSortedTestData() {
    Random rnd = new Random(874597969123412338L);
    int rndByte = rnd.nextInt(Byte.MAX_VALUE);
    if (rndByte < 0) {
        rndByte = -rndByte;
    }
    if (rndByte == Byte.MAX_VALUE) {
        rndByte -= 3;
    }
    if (rndByte <= 2) {
        rndByte += 3;
    }
    return new ByteValue[] { new ByteValue(Byte.MIN_VALUE), new ByteValue(Integer.valueOf(-rndByte).byteValue()), new ByteValue(Integer.valueOf(-1).byteValue()), new ByteValue(Integer.valueOf(0).byteValue()), new ByteValue(Integer.valueOf(1).byteValue()), new ByteValue(Integer.valueOf(2).byteValue()), new ByteValue(Integer.valueOf(rndByte).byteValue()), new ByteValue(Byte.MAX_VALUE) };
}
Also used : ByteValue(org.apache.flink.types.ByteValue) Random(java.util.Random)

Example 3 with ByteValue

use of org.apache.flink.types.ByteValue in project flink by apache.

the class ByteValueComparator method compareToReference.

@Override
public int compareToReference(TypeComparator<ByteValue> referencedComparator) {
    ByteValue otherRef = ((ByteValueComparator) referencedComparator).reference;
    int comp = otherRef.compareTo(reference);
    return ascendingComparison ? comp : -comp;
}
Also used : ByteValue(org.apache.flink.types.ByteValue)

Example 4 with ByteValue

use of org.apache.flink.types.ByteValue in project flink by apache.

the class ByteValueSerializerTest method getTestData.

@Override
protected ByteValue[] getTestData() {
    Random rnd = new Random(874597969123412341L);
    byte[] byteArray = new byte[1];
    rnd.nextBytes(byteArray);
    return new ByteValue[] { new ByteValue((byte) 0), new ByteValue((byte) 1), new ByteValue((byte) -1), new ByteValue(Byte.MAX_VALUE), new ByteValue(Byte.MIN_VALUE), new ByteValue(byteArray[0]), new ByteValue((byte) -byteArray[0]) };
}
Also used : ByteValue(org.apache.flink.types.ByteValue) Random(java.util.Random)

Aggregations

ByteValue (org.apache.flink.types.ByteValue)4 Random (java.util.Random)2 IOException (java.io.IOException)1 ValueComparator (org.apache.flink.api.java.typeutils.runtime.ValueComparator)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