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));
}
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;
}
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;
}
}
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();
}
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);
}
Aggregations