Search in sources :

Example 76 with BinaryRowData

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

the class HeapWindowsGroupingTest method processTriggerWindow.

private void processTriggerWindow(List<List<Long>> actual, List<TimeWindow> windows, HeapWindowsGrouping grouping) {
    while (grouping.hasTriggerWindow()) {
        RowIterator<BinaryRowData> iter = grouping.buildTriggerWindowElementsIterator();
        TimeWindow window = grouping.getTriggerWindow();
        List<Long> buffer = new ArrayList<>();
        while (iter.advanceNext()) {
            buffer.add(iter.getRow().getLong(0));
        }
        if (!buffer.isEmpty()) {
            actual.add(buffer);
            windows.add(window);
        }
    }
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ArrayList(java.util.ArrayList) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow)

Example 77 with BinaryRowData

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

the class StreamRecordUtils method binaryRecord.

/**
 * Creates n new {@link StreamRecord} of {@link BinaryRowData} based on the given fields array
 * and the given RowKind.
 */
public static StreamRecord<RowData> binaryRecord(RowKind rowKind, Object... fields) {
    BinaryRowData row = binaryrow(fields);
    row.setRowKind(rowKind);
    return new StreamRecord<>(row);
}
Also used : StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData)

Example 78 with BinaryRowData

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

the class UniformBinaryRowGenerator method next.

@Override
public BinaryRowData next() {
    key = new IntValue();
    value = new IntValue();
    return next(new BinaryRowData(2));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) IntValue(org.apache.flink.types.IntValue)

Example 79 with BinaryRowData

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

the class BytesHashMapTestBase method testBuildAndRetrieve.

@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(memorySize).build();
    AbstractBytesHashMap<K> table = createBytesHashMap(memoryManager, memorySize, KEY_TYPES, VALUE_TYPES);
    K[] keys = generateRandomKeys(NUM_ENTRIES);
    List<BinaryRowData> expected = new ArrayList<>(NUM_ENTRIES);
    verifyInsert(keys, expected, table);
    verifyRetrieve(table, keys, expected);
    table.free();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ArrayList(java.util.ArrayList) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Test(org.junit.Test)

Example 80 with BinaryRowData

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

the class BytesHashMapTestBase method verifyInsertAndUpdate.

private void verifyInsertAndUpdate(K[] keys, List<BinaryRowData> inserted, AbstractBytesHashMap<K> table) throws IOException {
    final Random rnd = new Random(RANDOM_SEED);
    for (int i = 0; i < NUM_ENTRIES; i++) {
        K groupKey = keys[i];
        // look up and insert
        BytesMap.LookupInfo<K, BinaryRowData> lookupInfo = table.lookup(groupKey);
        Assert.assertFalse(lookupInfo.isFound());
        BinaryRowData entry = table.append(lookupInfo, defaultValue);
        Assert.assertNotNull(entry);
        // mock multiple updates
        for (int j = 0; j < NUM_REWRITES; j++) {
            updateOutputBuffer(entry, rnd);
        }
        inserted.add(entry.copy());
    }
    Assert.assertEquals(NUM_ENTRIES, table.getNumElements());
}
Also used : Random(java.util.Random) 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