Search in sources :

Example 1 with IntPairComparator

use of org.apache.flink.runtime.operators.testutils.types.IntPairComparator in project flink by apache.

the class FixedLengthRecordSorterTest method beforeTest.

@Before
public void beforeTest() {
    this.memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(MEMORY_SIZE).setPageSize(MEMORY_PAGE_SIZE).build();
    this.ioManager = new IOManagerAsync();
    this.serializer = new IntPairSerializer();
    this.comparator = new IntPairComparator();
}
Also used : IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) IntPairComparator(org.apache.flink.runtime.operators.testutils.types.IntPairComparator) IntPairSerializer(org.apache.flink.runtime.operators.testutils.types.IntPairSerializer) Before(org.junit.Before)

Example 2 with IntPairComparator

use of org.apache.flink.runtime.operators.testutils.types.IntPairComparator in project flink by apache.

the class InPlaceMutableHashTableTest method testWithIntPair.

@Test
public void testWithIntPair() throws Exception {
    Random rnd = new Random(RANDOM_SEED);
    // varying the keyRange between 1000 and 1000000 can make a 5x speed difference
    // (because of cache misses (also in the segment arrays))
    final int keyRange = 1000000;
    final int valueRange = 10;
    final int numRecords = 1000000;
    final IntPairSerializer serializer = new IntPairSerializer();
    final TypeComparator<IntPair> comparator = new IntPairComparator();
    final ReduceFunction<IntPair> reducer = new SumReducer();
    // Create the InPlaceMutableHashTableWithJavaHashMap, which will provide the correct output.
    List<IntPair> expectedOutput = new ArrayList<>();
    InPlaceMutableHashTableWithJavaHashMap<IntPair, Integer> reference = new InPlaceMutableHashTableWithJavaHashMap<>(serializer, comparator, reducer, new CopyingListCollector<>(expectedOutput, serializer));
    // Create the InPlaceMutableHashTable to test
    final int numMemPages = keyRange * 32 / // memory use is proportional to the number of different keys
    PAGE_SIZE;
    List<IntPair> actualOutput = new ArrayList<>();
    InPlaceMutableHashTable<IntPair> table = new InPlaceMutableHashTable<>(serializer, comparator, getMemory(numMemPages, PAGE_SIZE));
    InPlaceMutableHashTable<IntPair>.ReduceFacade reduceFacade = table.new ReduceFacade(reducer, new CopyingListCollector<>(actualOutput, serializer), true);
    table.open();
    // Generate some input
    final List<IntPair> input = new ArrayList<>();
    for (int i = 0; i < numRecords; i++) {
        input.add(new IntPair(rnd.nextInt(keyRange), rnd.nextInt(valueRange)));
    }
    // System.out.println("start");
    // long start = System.currentTimeMillis();
    // Process the generated input
    final int numIntermingledEmits = 5;
    for (IntPair record : input) {
        reduceFacade.updateTableEntryWithReduce(serializer.copy(record));
        reference.updateTableEntryWithReduce(serializer.copy(record), record.getKey());
        if (rnd.nextDouble() < 1.0 / ((double) numRecords / numIntermingledEmits)) {
            // this will fire approx. numIntermingledEmits times
            reference.emitAndReset();
            reduceFacade.emitAndReset();
        }
    }
    reference.emitAndReset();
    reduceFacade.emit();
    table.close();
    // long end = System.currentTimeMillis();
    // System.out.println("stop, time: " + (end - start));
    // Check results
    assertEquals(expectedOutput.size(), actualOutput.size());
    Integer[] expectedValues = new Integer[expectedOutput.size()];
    for (int i = 0; i < expectedOutput.size(); i++) {
        expectedValues[i] = expectedOutput.get(i).getValue();
    }
    Integer[] actualValues = new Integer[actualOutput.size()];
    for (int i = 0; i < actualOutput.size(); i++) {
        actualValues[i] = actualOutput.get(i).getValue();
    }
    Arrays.sort(expectedValues, Ordering.<Integer>natural());
    Arrays.sort(actualValues, Ordering.<Integer>natural());
    assertArrayEquals(expectedValues, actualValues);
}
Also used : ArrayList(java.util.ArrayList) IntPair(org.apache.flink.runtime.operators.testutils.types.IntPair) Random(java.util.Random) IntPairComparator(org.apache.flink.runtime.operators.testutils.types.IntPairComparator) IntPairSerializer(org.apache.flink.runtime.operators.testutils.types.IntPairSerializer) Test(org.junit.Test)

Example 3 with IntPairComparator

use of org.apache.flink.runtime.operators.testutils.types.IntPairComparator in project flink by apache.

the class HashTableITCase method setup.

@Before
public void setup() {
    final int[] keyPos = new int[] { 0 };
    @SuppressWarnings("unchecked") final Class<? extends Value>[] keyType = (Class<? extends Value>[]) new Class[] { IntValue.class };
    this.recordBuildSideAccesssor = RecordSerializer.get();
    this.recordProbeSideAccesssor = RecordSerializer.get();
    this.recordBuildSideComparator = new RecordComparator(keyPos, keyType);
    this.recordProbeSideComparator = new RecordComparator(keyPos, keyType);
    this.pactRecordComparator = new RecordPairComparatorFirstInt();
    this.pairBuildSideAccesssor = new IntPairSerializer();
    this.pairProbeSideAccesssor = new IntPairSerializer();
    this.pairBuildSideComparator = new IntPairComparator();
    this.pairProbeSideComparator = new IntPairComparator();
    this.pairComparator = new IntPairPairComparator();
    this.memManager = MemoryManagerBuilder.newBuilder().setMemorySize(32 * 1024 * 1024).build();
    this.ioManager = new IOManagerAsync();
}
Also used : IntPairPairComparator(org.apache.flink.runtime.operators.testutils.types.IntPairPairComparator) IntPairComparator(org.apache.flink.runtime.operators.testutils.types.IntPairComparator) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) IntValue(org.apache.flink.types.IntValue) Value(org.apache.flink.types.Value) IntPairSerializer(org.apache.flink.runtime.operators.testutils.types.IntPairSerializer) RecordComparator(org.apache.flink.runtime.testutils.recordutils.RecordComparator) Before(org.junit.Before)

Aggregations

IntPairComparator (org.apache.flink.runtime.operators.testutils.types.IntPairComparator)3 IntPairSerializer (org.apache.flink.runtime.operators.testutils.types.IntPairSerializer)3 IOManagerAsync (org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 IntPair (org.apache.flink.runtime.operators.testutils.types.IntPair)1 IntPairPairComparator (org.apache.flink.runtime.operators.testutils.types.IntPairPairComparator)1 RecordComparator (org.apache.flink.runtime.testutils.recordutils.RecordComparator)1 IntValue (org.apache.flink.types.IntValue)1 Value (org.apache.flink.types.Value)1 Test (org.junit.Test)1