use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class BinaryArrayDataTest method testBinary.
@Test
public void testBinary() {
BinaryArrayData array = new BinaryArrayData();
BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
byte[] bytes1 = new byte[] { 1, -1, 5 };
byte[] bytes2 = new byte[] { 1, -1, 5, 5, 1, 5, 1, 5 };
writer.writeBinary(0, bytes1);
writer.writeBinary(1, bytes2);
writer.complete();
Assert.assertArrayEquals(bytes1, array.getBinary(0));
Assert.assertArrayEquals(bytes2, array.getBinary(1));
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class ArrayObjectArrayConverter method open.
@Override
public void open(ClassLoader classLoader) {
reuseArray = new BinaryArrayData();
reuseWriter = new BinaryArrayWriter(reuseArray, 0, elementSize);
elementConverter.open(classLoader);
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class ArrayDataSerializer method toBinaryArray.
public BinaryArrayData toBinaryArray(ArrayData from) {
if (from instanceof BinaryArrayData) {
return (BinaryArrayData) from;
}
int numElements = from.size();
if (reuseArray == null) {
reuseArray = new BinaryArrayData();
}
if (reuseWriter == null || reuseWriter.getNumElements() != numElements) {
reuseWriter = new BinaryArrayWriter(reuseArray, numElements, BinaryArrayData.calculateFixLengthPartSize(eleType));
} else {
reuseWriter.reset();
}
for (int i = 0; i < numElements; i++) {
if (from.isNullAt(i)) {
reuseWriter.setNullAt(i, eleType);
} else {
BinaryWriter.write(reuseWriter, i, elementGetter.getElementOrNull(from, i), eleType, eleSer);
}
}
reuseWriter.complete();
return reuseArray;
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class MapDataSerializerTest method createArray.
private static BinaryArrayData createArray(int... vs) {
BinaryArrayData array = new BinaryArrayData();
BinaryArrayWriter writer = new BinaryArrayWriter(array, vs.length, 4);
for (int i = 0; i < vs.length; i++) {
writer.writeInt(i, vs[i]);
}
writer.complete();
return array;
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class RowDataSerializerTest method createArray.
// ----------------------------------------------------------------------------------------------
private static BinaryArrayData createArray(int... ints) {
BinaryArrayData array = new BinaryArrayData();
BinaryArrayWriter writer = new BinaryArrayWriter(array, ints.length, 4);
for (int i = 0; i < ints.length; i++) {
writer.writeInt(i, ints[i]);
}
writer.complete();
return array;
}
Aggregations