Search in sources :

Example 71 with BinaryRowData

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

the class NestedRowDataTest method testNestedRowDataWithOneSegment.

@Test
public void testNestedRowDataWithOneSegment() {
    BinaryRowData row = getBinaryRowData();
    GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
    TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
    RowData nestedRow = row.getRow(0, 5);
    assertEquals(nestedRow.getInt(0), 1);
    assertEquals(nestedRow.getLong(1), 5L);
    assertEquals(nestedRow.getString(2), StringData.fromString("12345678"));
    assertTrue(nestedRow.isNullAt(3));
    assertEquals(new MyObj(15, 5), nestedRow.<MyObj>getRawValue(4).toObject(genericSerializer));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) NestedRowData(org.apache.flink.table.data.binary.NestedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MyObj(org.apache.flink.table.data.util.DataFormatTestUtil.MyObj) GenericTypeInfo(org.apache.flink.api.java.typeutils.GenericTypeInfo) Test(org.junit.Test)

Example 72 with BinaryRowData

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

the class DataFormatTestUtil method get160BytesBinaryRow.

/**
 * Get a binary row of 160 bytes long.
 */
public static BinaryRowData get160BytesBinaryRow() {
    // header (8 bytes) +
    // 72 byte length string (8 bytes in fixed-length, 72 bytes in variable-length) +
    // 64 byte length string (8 bytes in fixed-length, 64 bytes in variable-length)
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, StringData.fromString(RandomStringUtils.randomNumeric(72)));
    writer.writeString(1, StringData.fromString(RandomStringUtils.randomNumeric(64)));
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter)

Example 73 with BinaryRowData

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

the class AbstractBytesHashMap method append.

// ----------------------- Public interface -----------------------
/**
 * Append an value into the hash map's record area.
 *
 * @return An BinaryRowData mapping to the memory segments in the map's record area belonging to
 *     the newly appended value.
 * @throws EOFException if the map can't allocate much more memory.
 */
public BinaryRowData append(LookupInfo<K, BinaryRowData> lookupInfo, BinaryRowData value) throws IOException {
    try {
        if (numElements >= growthThreshold) {
            growAndRehash();
            // update info's bucketSegmentIndex and bucketOffset
            lookup(lookupInfo.key);
        }
        BinaryRowData toAppend = hashSetMode ? reusedValue : value;
        int pointerToAppended = recordArea.appendRecord(lookupInfo, toAppend);
        bucketSegments.get(lookupInfo.bucketSegmentIndex).putInt(lookupInfo.bucketOffset, pointerToAppended);
        bucketSegments.get(lookupInfo.bucketSegmentIndex).putInt(lookupInfo.bucketOffset + ELEMENT_POINT_LENGTH, lookupInfo.keyHashCode);
        numElements++;
        recordArea.setReadPosition(pointerToAppended);
        ((RecordArea) recordArea).skipKey();
        return recordArea.readValue(reusedValue);
    } catch (EOFException e) {
        numSpillFiles++;
        spillInBytes += recordArea.getSegmentsSize();
        throw e;
    }
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) EOFException(java.io.EOFException)

Example 74 with BinaryRowData

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

the class HeapWindowsGroupingTest method testInvalidWindowTrigger.

@Test(expected = IllegalStateException.class)
public void testInvalidWindowTrigger() throws IOException {
    Long[] ts = new Long[] { 8L };
    RowIterator<BinaryRowData> iterator = new HeapWindowsGroupingTest.TestInputIterator(ts);
    HeapWindowsGrouping grouping = new HeapWindowsGrouping(5000, 0L, 8L, 4L, 0, false);
    grouping.addInputToBuffer(iterator.getRow());
    System.out.println("valid window trigger");
    RowIterator<BinaryRowData> iter = grouping.buildTriggerWindowElementsIterator();
    TimeWindow window = grouping.getTriggerWindow();
    List<Long> buffer = new ArrayList<>();
    while (iter.advanceNext()) {
        buffer.add(iter.getRow().getLong(0));
    }
    assertEquals(TimeWindow.of(0, 8L), window);
    assertEquals(Collections.emptyList(), buffer);
    System.out.println("try invalid window trigger");
    grouping.buildTriggerWindowElementsIterator();
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ArrayList(java.util.ArrayList) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow) Test(org.junit.Test)

Example 75 with BinaryRowData

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

the class HeapWindowsGroupingTest method verify.

private void verify(int limit, Long[] ts, long windowSize, long slideSize, List<List<Long>> expected, List<TimeWindow> expectedWindows) throws IOException {
    List<List<Long>> actual = new ArrayList<>();
    List<TimeWindow> windows = new ArrayList<>();
    HeapWindowsGrouping grouping = new HeapWindowsGrouping(limit, 0L, windowSize, slideSize, 0, false);
    RowIterator<BinaryRowData> iterator = new HeapWindowsGroupingTest.TestInputIterator(ts);
    while (iterator.advanceNext()) {
        BinaryRowData input = iterator.getRow();
        grouping.addInputToBuffer(input);
        processTriggerWindow(actual, windows, grouping);
    }
    grouping.advanceWatermarkToTriggerAllWindows();
    processTriggerWindow(actual, windows, grouping);
    assertEquals(expectedWindows, windows);
    assertEquals(expected, actual);
}
Also used : ArrayList(java.util.ArrayList) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow)

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