Search in sources :

Example 86 with BinaryRowData

use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.

the class BytesMapTestBase method createRow.

protected BinaryRowData createRow(Integer f0, String f1, Double f2, Long f3, Boolean f4, Float f5, Short f6) {
    BinaryRowData row = new BinaryRowData(7);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    // int, string, double, long, boolean
    if (f0 == null) {
        writer.setNullAt(0);
    } else {
        writer.writeInt(0, f0);
    }
    if (f1 == null) {
        writer.setNullAt(1);
    } else {
        writer.writeString(1, StringData.fromString(f1));
    }
    if (f2 == null) {
        writer.setNullAt(2);
    } else {
        writer.writeDouble(2, f2);
    }
    if (f3 == null) {
        writer.setNullAt(3);
    } else {
        writer.writeLong(3, f3);
    }
    if (f4 == null) {
        writer.setNullAt(4);
    } else {
        writer.writeBoolean(4, f4);
    }
    if (f5 == null) {
        writer.setNullAt(5);
    } else {
        writer.writeFloat(5, f5);
    }
    if (f6 == null) {
        writer.setNullAt(6);
    } else {
        writer.writeShort(6, f6);
    }
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 87 with BinaryRowData

use of org.apache.flink.table.data.binary.BinaryRowData 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)

Example 88 with BinaryRowData

use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.

the class WindowBytesMultiMapTest method generateRandomKeys.

@Override
public WindowKey[] generateRandomKeys(int num) {
    final Random rnd = new Random(RANDOM_SEED);
    BinaryRowData[] keys = getRandomizedInputs(num, rnd, true);
    WindowKey[] windowKeys = new WindowKey[num];
    for (int i = 0; i < num; i++) {
        windowKeys[i] = new WindowKey(rnd.nextLong(), keys[i]);
    }
    return windowKeys;
}
Also used : Random(java.util.Random) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) WindowKey(org.apache.flink.table.runtime.util.WindowKey)

Example 89 with BinaryRowData

use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.

the class WindowKeySerializerTest method createRow.

private static BinaryRowData createRow(String f0, int f1) {
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, StringData.fromString(f0));
    writer.writeInt(1, f1);
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 90 with BinaryRowData

use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.

the class ResettableExternalBufferTest method testUpdateIteratorSpill.

private <T extends RowData> void testUpdateIteratorSpill(BinaryRowDataSerializer serializer, Class<T> clazz, boolean isRowAllInFixedPart) throws Exception {
    ResettableExternalBuffer buffer = newBuffer(DEFAULT_PAGE_SIZE * 2, serializer, isRowAllInFixedPart);
    int number = 100;
    int step = 20;
    int iters = 3;
    List<RowData> expected = new ArrayList<>();
    List<RowData> smallExpected = new ArrayList<>();
    List<ResettableExternalBuffer.BufferIterator> iterators = new ArrayList<>();
    for (int i = 0; i < iters; i++) {
        iterators.add(buffer.newIterator());
    }
    for (int i = 0; i < number; i++) {
        smallExpected.clear();
        for (int j = 0; j < step; j++) {
            RowData data = clazz.newInstance();
            data.insertIntoBuffer(buffer);
            expected.add(data);
            smallExpected.add(data);
        }
        for (int j = 0; j < step; j++) {
            for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
                assertTrue(iterator.advanceNext());
                BinaryRowData row = iterator.getRow();
                smallExpected.get(j).checkSame(row);
            }
        }
        for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
            assertFalse(iterator.advanceNext());
        }
    }
    for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
        iterator.reset();
    }
    for (int i = 0; i < number * step; i++) {
        for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
            assertTrue(iterator.advanceNext());
            BinaryRowData row = iterator.getRow();
            expected.get(i).checkSame(row);
        }
    }
    for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
        iterator.close();
    }
    assertMultiColumnRandomAccess(expected, buffer);
    buffer.close();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ArrayList(java.util.ArrayList) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData)

Aggregations

BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)173 Test (org.junit.Test)81 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)54 RowData (org.apache.flink.table.data.RowData)31 ArrayList (java.util.ArrayList)30 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)22 UniformBinaryRowGenerator (org.apache.flink.table.runtime.util.UniformBinaryRowGenerator)21 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)16 MemorySegment (org.apache.flink.core.memory.MemorySegment)15 MutableObjectIterator (org.apache.flink.util.MutableObjectIterator)14 GenericRowData (org.apache.flink.table.data.GenericRowData)13 Random (java.util.Random)12 BinaryRowDataSerializer (org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)12 HashMap (java.util.HashMap)9 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)9 Map (java.util.Map)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)7 RandomAccessInputView (org.apache.flink.runtime.io.disk.RandomAccessInputView)6 StreamRecord (org.apache.flink.streaming.runtime.streamrecord.StreamRecord)6