use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method anyNullTest.
@Test
public void anyNullTest() {
{
BinaryRowData row = new BinaryRowData(3);
BinaryRowWriter writer = new BinaryRowWriter(row);
assertFalse(row.anyNull());
// test header should not compute by anyNull
row.setRowKind(RowKind.UPDATE_BEFORE);
assertFalse(row.anyNull());
writer.setNullAt(2);
assertTrue(row.anyNull());
writer.setNullAt(0);
assertTrue(row.anyNull(new int[] { 0, 1, 2 }));
assertFalse(row.anyNull(new int[] { 1 }));
writer.setNullAt(1);
assertTrue(row.anyNull());
}
int numFields = 80;
for (int i = 0; i < numFields; i++) {
BinaryRowData row = new BinaryRowData(numFields);
BinaryRowWriter writer = new BinaryRowWriter(row);
row.setRowKind(RowKind.DELETE);
assertFalse(row.anyNull());
writer.setNullAt(i);
assertTrue(row.anyNull());
}
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testBinaryArray.
@Test
public void testBinaryArray() {
// 1. array test
BinaryArrayData array = new BinaryArrayData();
BinaryArrayWriter arrayWriter = new BinaryArrayWriter(array, 3, BinaryArrayData.calculateFixLengthPartSize(DataTypes.INT().getLogicalType()));
arrayWriter.writeInt(0, 6);
arrayWriter.setNullInt(1);
arrayWriter.writeInt(2, 666);
arrayWriter.complete();
assertEquals(array.getInt(0), 6);
assertTrue(array.isNullAt(1));
assertEquals(array.getInt(2), 666);
// 2. test write array to binary row
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
ArrayDataSerializer serializer = new ArrayDataSerializer(DataTypes.INT().getLogicalType());
rowWriter.writeArray(0, array, serializer);
rowWriter.complete();
BinaryArrayData array2 = (BinaryArrayData) row.getArray(0);
assertEquals(array, array2);
assertEquals(6, array2.getInt(0));
assertTrue(array2.isNullAt(1));
assertEquals(666, array2.getInt(2));
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testGenericArray.
@Test
public void testGenericArray() {
// 1. array test
Integer[] javaArray = { 6, null, 666 };
GenericArrayData array = new GenericArrayData(javaArray);
assertEquals(array.getInt(0), 6);
assertTrue(array.isNullAt(1));
assertEquals(array.getInt(2), 666);
// 2. test write array to binary row
BinaryRowData row2 = new BinaryRowData(1);
BinaryRowWriter writer2 = new BinaryRowWriter(row2);
ArrayDataSerializer serializer = new ArrayDataSerializer(DataTypes.INT().getLogicalType());
writer2.writeArray(0, array, serializer);
writer2.complete();
ArrayData array2 = row2.getArray(0);
assertEquals(6, array2.getInt(0));
assertTrue(array2.isNullAt(1));
assertEquals(666, array2.getInt(2));
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testPagesSer.
@Test
public void testPagesSer() throws IOException {
MemorySegment[] memorySegments = new MemorySegment[5];
ArrayList<MemorySegment> memorySegmentList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
memorySegments[i] = MemorySegmentFactory.wrap(new byte[64]);
memorySegmentList.add(memorySegments[i]);
}
{
// multi memorySegments
String str = "啦啦啦啦啦我是快乐的粉刷匠,啦啦啦啦啦我是快乐的粉刷匠," + "啦啦啦啦啦我是快乐的粉刷匠。";
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, fromString(str));
writer.complete();
RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64);
BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(1);
serializer.serializeToPages(row, out);
BinaryRowData mapRow = serializer.createInstance();
mapRow = serializer.mapFromPages(mapRow, new RandomAccessInputView(memorySegmentList, 64));
writer.reset();
writer.writeString(0, mapRow.getString(0));
writer.complete();
assertEquals(str, row.getString(0).toString());
BinaryRowData deserRow = serializer.deserializeFromPages(new RandomAccessInputView(memorySegmentList, 64));
writer.reset();
writer.writeString(0, deserRow.getString(0));
writer.complete();
assertEquals(str, row.getString(0).toString());
}
{
// multi memorySegments
String str1 = "啦啦啦啦啦我是快乐的粉刷匠,啦啦啦啦啦我是快乐的粉刷匠," + "啦啦啦啦啦我是快乐的粉刷匠。";
String str2 = "啦啦啦啦啦我是快乐的粉刷匠。";
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, fromString(str1));
writer.writeString(1, fromString(str2));
writer.complete();
RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64);
out.skipBytesToWrite(40);
BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(2);
serializer.serializeToPages(row, out);
RandomAccessInputView in = new RandomAccessInputView(memorySegmentList, 64);
in.skipBytesToRead(40);
BinaryRowData mapRow = serializer.createInstance();
mapRow = serializer.mapFromPages(mapRow, in);
writer.reset();
writer.writeString(0, mapRow.getString(0));
writer.writeString(1, mapRow.getString(1));
writer.complete();
assertEquals(str1, row.getString(0).toString());
assertEquals(str2, row.getString(1).toString());
in = new RandomAccessInputView(memorySegmentList, 64);
in.skipBytesToRead(40);
BinaryRowData deserRow = serializer.deserializeFromPages(in);
writer.reset();
writer.writeString(0, deserRow.getString(0));
writer.writeString(1, deserRow.getString(1));
writer.complete();
assertEquals(str1, row.getString(0).toString());
assertEquals(str2, row.getString(1).toString());
}
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testBinaryMap.
@Test
public void testBinaryMap() {
BinaryArrayData array1 = new BinaryArrayData();
BinaryArrayWriter writer1 = new BinaryArrayWriter(array1, 4, BinaryArrayData.calculateFixLengthPartSize(DataTypes.INT().getLogicalType()));
writer1.writeInt(0, 6);
writer1.writeInt(1, 5);
writer1.writeInt(2, 666);
writer1.writeInt(3, 0);
writer1.complete();
BinaryArrayData array2 = new BinaryArrayData();
BinaryArrayWriter writer2 = new BinaryArrayWriter(array2, 4, BinaryArrayData.calculateFixLengthPartSize(DataTypes.STRING().getLogicalType()));
writer2.writeString(0, fromString("6"));
writer2.writeString(1, fromString("5"));
writer2.writeString(2, fromString("666"));
writer2.setNullAt(3, DataTypes.STRING().getLogicalType());
writer2.complete();
BinaryMapData binaryMap = BinaryMapData.valueOf(array1, array2);
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
MapDataSerializer serializer = new MapDataSerializer(DataTypes.STRING().getLogicalType(), DataTypes.INT().getLogicalType());
rowWriter.writeMap(0, binaryMap, serializer);
rowWriter.complete();
BinaryMapData map = (BinaryMapData) row.getMap(0);
BinaryArrayData key = map.keyArray();
BinaryArrayData value = map.valueArray();
assertEquals(binaryMap, map);
assertEquals(array1, key);
assertEquals(array2, value);
assertEquals(5, key.getInt(1));
assertEquals(fromString("5"), value.getString(1));
assertEquals(0, key.getInt(3));
assertTrue(value.isNullAt(3));
}
Aggregations