Search in sources :

Example 1 with KeyValueIterator

use of org.apache.flink.table.runtime.util.KeyValueIterator in project flink by apache.

the class BytesMultiMapTestBase method testBuildAndRetrieve.

// ------------------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------------------
@Test
public void testBuildAndRetrieve() throws Exception {
    final int numMemSegments = needNumMemSegments(NUM_ENTRIES, rowLength(RowType.of(VALUE_TYPES)), rowLength(RowType.of(KEY_TYPES)), PAGE_SIZE);
    int memorySize = numMemSegments * PAGE_SIZE;
    MemoryManager memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(numMemSegments * PAGE_SIZE).build();
    AbstractBytesMultiMap<K> table = createBytesMultiMap(memoryManager, memorySize, KEY_TYPES, VALUE_TYPES);
    K[] keys = generateRandomKeys(NUM_ENTRIES / 10);
    BinaryRowData[] values = genValues(NUM_VALUE_PER_KEY);
    for (K key : keys) {
        BytesMap.LookupInfo<K, Iterator<RowData>> lookupInfo;
        for (BinaryRowData value : values) {
            lookupInfo = table.lookup(key);
            table.append(lookupInfo, value);
        }
    }
    KeyValueIterator<K, Iterator<RowData>> iter = table.getEntryIterator(false);
    while (iter.advanceNext()) {
        int i = 0;
        Iterator<RowData> valueIter = iter.getValue();
        while (valueIter.hasNext()) {
            Assert.assertEquals(valueIter.next(), values[i++]);
        }
    }
}
Also used : MemoryManager(org.apache.flink.runtime.memory.MemoryManager) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) Iterator(java.util.Iterator) KeyValueIterator(org.apache.flink.table.runtime.util.KeyValueIterator) Test(org.junit.Test)

Aggregations

Iterator (java.util.Iterator)1 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)1 RowData (org.apache.flink.table.data.RowData)1 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)1 KeyValueIterator (org.apache.flink.table.runtime.util.KeyValueIterator)1 Test (org.junit.Test)1