Search in sources :

Example 1 with RawValueDataSerializer

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);
}
Also used : RandomAccessInputView(org.apache.flink.runtime.io.disk.RandomAccessInputView) ArrayList(java.util.ArrayList) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) RandomAccessOutputView(org.apache.flink.runtime.io.disk.RandomAccessOutputView) GenericTypeInfo(org.apache.flink.api.java.typeutils.GenericTypeInfo) MemorySegment(org.apache.flink.core.memory.MemorySegment) RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) MyObj(org.apache.flink.table.data.util.DataFormatTestUtil.MyObj) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer) Test(org.junit.Test)

Example 2 with RawValueDataSerializer

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));
}
Also used : RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) StringData.fromString(org.apache.flink.table.data.StringData.fromString) Test(org.junit.Test)

Example 3 with RawValueDataSerializer

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);
}
Also used : Types(org.apache.flink.api.common.typeinfo.Types) TypeInformationRawType(org.apache.flink.table.types.logical.TypeInformationRawType) IntStream(java.util.stream.IntStream) RecordEqualiser(org.apache.flink.table.runtime.generated.RecordEqualiser) TimestampData(org.apache.flink.table.data.TimestampData) Assert.assertTrue(org.junit.Assert.assertTrue) VarCharType(org.apache.flink.table.types.logical.VarCharType) Test(org.junit.Test) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) Function(java.util.function.Function) TimestampData.fromEpochMillis(org.apache.flink.table.data.TimestampData.fromEpochMillis) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) StringData(org.apache.flink.table.data.StringData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) TimestampType(org.apache.flink.table.types.logical.TimestampType) RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) GenericRowData(org.apache.flink.table.data.GenericRowData) LogicalType(org.apache.flink.table.types.logical.LogicalType) RawValueData(org.apache.flink.table.data.RawValueData) Assert(org.junit.Assert) RecordEqualiser(org.apache.flink.table.runtime.generated.RecordEqualiser) RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) RawValueData(org.apache.flink.table.data.RawValueData) Test(org.junit.Test)

Example 4 with RawValueDataSerializer

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));
}
Also used : RawValueDataSerializer(org.apache.flink.table.runtime.typeutils.RawValueDataSerializer) BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) StringData.fromString(org.apache.flink.table.data.StringData.fromString) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) Test(org.junit.Test)

Aggregations

RawValueDataSerializer (org.apache.flink.table.runtime.typeutils.RawValueDataSerializer)4 Test (org.junit.Test)4 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)3 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)3 StringData.fromString (org.apache.flink.table.data.StringData.fromString)2 ArrayList (java.util.ArrayList)1 Function (java.util.function.Function)1 IntStream (java.util.stream.IntStream)1 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)1 Types (org.apache.flink.api.common.typeinfo.Types)1 IntSerializer (org.apache.flink.api.common.typeutils.base.IntSerializer)1 GenericTypeInfo (org.apache.flink.api.java.typeutils.GenericTypeInfo)1 MemorySegment (org.apache.flink.core.memory.MemorySegment)1 RandomAccessInputView (org.apache.flink.runtime.io.disk.RandomAccessInputView)1 RandomAccessOutputView (org.apache.flink.runtime.io.disk.RandomAccessOutputView)1 GenericRowData (org.apache.flink.table.data.GenericRowData)1 RawValueData (org.apache.flink.table.data.RawValueData)1 StringData (org.apache.flink.table.data.StringData)1 TimestampData (org.apache.flink.table.data.TimestampData)1 TimestampData.fromEpochMillis (org.apache.flink.table.data.TimestampData.fromEpochMillis)1