use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BinaryRowDataTest method testSetAndGet.
@Test
public void testSetAndGet() {
MemorySegment segment = MemorySegmentFactory.wrap(new byte[80]);
BinaryRowData row = new BinaryRowData(9);
row.pointTo(segment, 0, 80);
row.setNullAt(0);
row.setInt(1, 11);
row.setLong(2, 22);
row.setDouble(3, 33);
row.setBoolean(4, true);
row.setShort(5, (short) 55);
row.setByte(6, (byte) 66);
row.setFloat(7, 77f);
assertEquals(33d, (long) row.getDouble(3), 0);
assertEquals(11, row.getInt(1));
assertTrue(row.isNullAt(0));
assertEquals(55, row.getShort(5));
assertEquals(22, row.getLong(2));
assertTrue(row.getBoolean(4));
assertEquals((byte) 66, row.getByte(6));
assertEquals(77f, row.getFloat(7), 0);
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BinaryRowDataTest method testGenericMap.
@Test
public void testGenericMap() {
Map<Object, Object> javaMap = new HashMap<>();
javaMap.put(6, fromString("6"));
javaMap.put(5, fromString("5"));
javaMap.put(666, fromString("666"));
javaMap.put(0, null);
GenericMapData genericMap = new GenericMapData(javaMap);
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
MapDataSerializer serializer = new MapDataSerializer(DataTypes.INT().getLogicalType(), DataTypes.STRING().getLogicalType());
rowWriter.writeMap(0, genericMap, serializer);
rowWriter.complete();
Map<Object, Object> map = convertToJavaMap(row.getMap(0), DataTypes.INT().getLogicalType(), DataTypes.STRING().getLogicalType());
assertEquals(fromString("6"), map.get(6));
assertEquals(fromString("5"), map.get(5));
assertEquals(fromString("666"), map.get(666));
assertTrue(map.containsKey(0));
assertNull(map.get(0));
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BinaryRowDataTest method testSerializeVariousSize.
@Test
public void testSerializeVariousSize() throws IOException {
// in this test, we are going to start serializing from the i-th byte (i in 0...`segSize`)
// and the size of the row we're going to serialize is j bytes
// (j in `rowFixLength` to the maximum length we can write)
int segSize = 64;
int segTotalNumber = 3;
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter writer = new BinaryRowWriter(row);
Random random = new Random();
byte[] bytes = new byte[1024];
random.nextBytes(bytes);
writer.writeBinary(0, bytes);
writer.complete();
MemorySegment[] memorySegments = new MemorySegment[segTotalNumber];
Map<MemorySegment, Integer> msIndex = new HashMap<>();
for (int i = 0; i < segTotalNumber; i++) {
memorySegments[i] = MemorySegmentFactory.wrap(new byte[segSize]);
msIndex.put(memorySegments[i], i);
}
BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(1);
int rowSizeInt = 4;
// note that as there is only one field in the row, the fixed-length part is 16 bytes
// (header + 1 field)
int rowFixLength = 16;
for (int i = 0; i < segSize; i++) {
// this is the maximum row size we can serialize
// if we are going to serialize from the i-th byte of the input view
int maxRowSize = (segSize * segTotalNumber) - i - rowSizeInt;
if (segSize - i < rowFixLength + rowSizeInt) {
// oops, we can't write the whole fixed-length part in the first segment
// because the remaining space is too small, so we have to start serializing from
// the second segment.
// when serializing, we need to first write the length of the row,
// then write the fixed-length part of the row.
maxRowSize -= segSize - i;
}
for (int j = rowFixLength; j < maxRowSize; j++) {
// ok, now we're going to serialize a row of j bytes
testSerialize(row, memorySegments, msIndex, serializer, i, j);
}
}
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BinaryRowDataTest method testHeader.
@Test
public void testHeader() {
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeInt(0, 10);
writer.setNullAt(1);
writer.writeRowKind(RowKind.UPDATE_BEFORE);
writer.complete();
BinaryRowData newRow = row.copy();
assertEquals(row, newRow);
assertEquals(RowKind.UPDATE_BEFORE, newRow.getRowKind());
newRow.setRowKind(RowKind.DELETE);
assertEquals(RowKind.DELETE, newRow.getRowKind());
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BinaryRowDataTest method testSerializerPages.
@Test
public void testSerializerPages() throws IOException {
// Boundary tests
BinaryRowData row24 = DataFormatTestUtil.get24BytesBinaryRow();
BinaryRowData row160 = DataFormatTestUtil.get160BytesBinaryRow();
testSerializerPagesInternal(row24, row160);
testSerializerPagesInternal(row24, DataFormatTestUtil.getMultiSeg160BytesBinaryRow(row160));
}
Aggregations