use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class MapDataSerializerTest method getTestData.
@Override
protected MapData[] getTestData() {
Map<Object, Object> first = new HashMap<>();
first.put(1L, -100.1F);
BinaryArrayData keyBinary = BinaryArrayData.fromPrimitiveArray(new long[] { 10L, 20L });
BinaryArrayData valueBinary = new BinaryArrayData();
BinaryArrayWriter writer = new BinaryArrayWriter(valueBinary, 2, 4);
BinaryArrayWriter.NullSetter nullSetter = BinaryArrayWriter.createNullSetter(FLOAT);
writer.writeFloat(0, 10.2F);
nullSetter.setNull(writer, 1);
writer.complete();
return new MapData[] { new GenericMapData(first), BinaryMapData.valueOf(keyBinary, valueBinary) };
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter 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.BinaryArrayWriter 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));
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class BinaryArrayDataTest method testGeneric.
@Test
public void testGeneric() {
BinaryArrayData array = new BinaryArrayData();
BinaryArrayWriter writer = new BinaryArrayWriter(array, 2, 8);
RawValueData<String> generic = RawValueData.fromObject("hahah");
RawValueDataSerializer<String> serializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
writer.writeRawValue(0, generic, serializer);
writer.setNullAt(1);
writer.complete();
RawValueData<String> newGeneric = array.getRawValue(0);
assertThat(newGeneric, equivalent(generic, serializer));
assertTrue(array.isNullAt(1));
}
use of org.apache.flink.table.data.writer.BinaryArrayWriter in project flink by apache.
the class BinaryArrayDataTest method testMap.
@Test
public void testMap() {
BinaryArrayData array1 = new BinaryArrayData();
BinaryArrayWriter writer1 = new BinaryArrayWriter(array1, 3, 4);
writer1.writeInt(0, 6);
writer1.writeInt(1, 5);
writer1.writeInt(2, 666);
writer1.complete();
BinaryArrayData array2 = new BinaryArrayData();
BinaryArrayWriter writer2 = new BinaryArrayWriter(array2, 3, 8);
writer2.writeString(0, fromString("6"));
writer2.writeString(1, fromString("5"));
writer2.writeString(2, fromString("666"));
writer2.complete();
BinaryMapData binaryMap = BinaryMapData.valueOf(array1, array2);
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter rowWriter = new BinaryRowWriter(row);
rowWriter.writeMap(0, binaryMap, new MapDataSerializer(DataTypes.INT().getLogicalType(), DataTypes.INT().getLogicalType()));
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(key.getInt(1), 5);
assertEquals(value.getString(1), fromString("5"));
}
Aggregations