use of org.apache.flink.table.runtime.typeutils.RawValueDataSerializer in project flink by apache.
the class BinaryRowDataTest method testGenericObject.
@Test
public void testGenericObject() throws Exception {
GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
RawValueDataSerializer<MyObj> binarySerializer = new RawValueDataSerializer<>(genericSerializer);
BinaryRowData row = new BinaryRowData(4);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeInt(0, 0);
RawValueData<MyObj> myObj1 = RawValueData.fromObject(new MyObj(0, 1));
writer.writeRawValue(1, myObj1, binarySerializer);
RawValueData<MyObj> myObj2 = RawValueData.fromObject(new MyObj(123, 5.0));
writer.writeRawValue(2, myObj2, binarySerializer);
RawValueData<MyObj> myObj3 = RawValueData.fromObject(new MyObj(1, 1));
writer.writeRawValue(3, myObj3, binarySerializer);
writer.complete();
assertTestGenericObjectRow(row, genericSerializer);
// getBytes from var-length memorySegments.
BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(4);
MemorySegment[] memorySegments = new MemorySegment[3];
ArrayList<MemorySegment> memorySegmentList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
memorySegments[i] = MemorySegmentFactory.wrap(new byte[64]);
memorySegmentList.add(memorySegments[i]);
}
RandomAccessOutputView out = new RandomAccessOutputView(memorySegments, 64);
serializer.serializeToPages(row, out);
BinaryRowData mapRow = serializer.createInstance();
mapRow = serializer.mapFromPages(mapRow, new RandomAccessInputView(memorySegmentList, 64));
assertTestGenericObjectRow(mapRow, genericSerializer);
}
use of org.apache.flink.table.runtime.typeutils.RawValueDataSerializer in project flink by apache.
the class BinaryRowDataTest method testRawValueData.
@Test
public void testRawValueData() {
BinaryRowData row = new BinaryRowData(3);
BinaryRowWriter writer = new BinaryRowWriter(row);
RawValueDataSerializer<String> binarySerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
RawValueData<String> hahah = RawValueData.fromObject("hahah");
writer.writeRawValue(0, hahah, binarySerializer);
writer.setNullAt(1);
writer.writeRawValue(2, hahah, binarySerializer);
writer.complete();
RawValueData<String> generic0 = row.getRawValue(0);
assertThat(generic0, equivalent(hahah, binarySerializer));
assertTrue(row.isNullAt(1));
RawValueData<String> generic2 = row.getRawValue(2);
assertThat(generic2, equivalent(hahah, binarySerializer));
}
use of org.apache.flink.table.runtime.typeutils.RawValueDataSerializer in project flink by apache.
the class EqualiserCodeGeneratorTest method testRaw.
@Test
public void testRaw() {
RecordEqualiser equaliser = new EqualiserCodeGenerator(new LogicalType[] { new TypeInformationRawType<>(Types.INT) }).generateRecordEqualiser("RAW").newInstance(Thread.currentThread().getContextClassLoader());
Function<RawValueData<?>, BinaryRowData> func = o -> {
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeRawValue(0, o, new RawValueDataSerializer<>(IntSerializer.INSTANCE));
writer.complete();
return row;
};
assertBoolean(equaliser, func, RawValueData.fromObject(1), RawValueData.fromObject(1), true);
assertBoolean(equaliser, func, RawValueData.fromObject(1), RawValueData.fromObject(2), false);
}
use of org.apache.flink.table.runtime.typeutils.RawValueDataSerializer 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));
}
Aggregations