Search in sources :

Example 1 with AvroSerializationInfo

use of org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo in project incubator-inlong by apache.

the class RowToAvroKafkaSinkTest method prepareData.

@Override
protected void prepareData() throws IOException, ClassNotFoundException {
    fieldInfos = new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new IntFormatInfo()), new FieldInfo("f3", new NullFormatInfo()), new FieldInfo("f4", new BinaryFormatInfo()), new FieldInfo("f5", new MapFormatInfo(new StringFormatInfo(), new RowFormatInfo(new String[] { "f51", "f52" }, new FormatInfo[] { new IntFormatInfo(), new ArrayFormatInfo(new DoubleFormatInfo()) }))) };
    topic = "test_kafka_row_to_avro";
    serializationSchema = SerializationSchemaFactory.build(fieldInfos, new AvroSerializationInfo());
    prepareTestRows();
}
Also used : NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) NullFormatInfo(org.apache.inlong.sort.formats.common.NullFormatInfo) MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) AvroSerializationInfo(org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) BinaryFormatInfo(org.apache.inlong.sort.formats.common.BinaryFormatInfo)

Example 2 with AvroSerializationInfo

use of org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo in project incubator-inlong by apache.

the class AvroDeserializationTest method testAvroDeserializationSchema.

@Test
public void testAvroDeserializationSchema() throws IOException, ClassNotFoundException {
    SerializationSchema<Row> serializationSchema = SerializationSchemaFactory.build(fieldInfos, new AvroSerializationInfo());
    Row expectedRow = generateTestRow();
    byte[] bytes = serializationSchema.serialize(expectedRow);
    DeserializationSchema<Row> deserializationSchema = DeserializationSchemaFactory.build(fieldInfos, new AvroDeserializationInfo());
    Row actualRow = deserializationSchema.deserialize(bytes);
    assertEquals(expectedRow, actualRow);
}
Also used : AvroDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.AvroDeserializationInfo) Row(org.apache.flink.types.Row) AvroSerializationInfo(org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo) Test(org.junit.Test)

Example 3 with AvroSerializationInfo

use of org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo in project incubator-inlong by apache.

the class SerializationUtils method serializeForKafka.

/**
 * Get serialization info for Kafka
 */
private static SerializationInfo serializeForKafka(SourceResponse sourceResponse, KafkaSinkResponse sinkResponse) {
    String serializationType = sinkResponse.getSerializationType();
    DataTypeEnum dataType = DataTypeEnum.forName(serializationType);
    switch(dataType) {
        case AVRO:
            return new AvroSerializationInfo();
        case JSON:
            return new JsonSerializationInfo();
        case CANAL:
            return new CanalSerializationInfo();
        case DEBEZIUM_JSON:
            Assert.isInstanceOf(BinlogSourceResponse.class, sourceResponse, "Unsupported serializationType for Kafka");
            BinlogSourceResponse binlogSource = (BinlogSourceResponse) sourceResponse;
            return new DebeziumSerializationInfo(binlogSource.getTimestampFormatStandard(), "FAIL", "", false);
        default:
            throw new IllegalArgumentException(String.format("Unsupported serializationType for Kafka sink: %s", serializationType));
    }
}
Also used : DebeziumSerializationInfo(org.apache.inlong.sort.protocol.serialization.DebeziumSerializationInfo) DataTypeEnum(org.apache.inlong.common.enums.DataTypeEnum) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) BinlogSourceResponse(org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceResponse) AvroSerializationInfo(org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo) JsonSerializationInfo(org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo)

Aggregations

AvroSerializationInfo (org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo)3 Row (org.apache.flink.types.Row)1 DataTypeEnum (org.apache.inlong.common.enums.DataTypeEnum)1 BinlogSourceResponse (org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceResponse)1 ArrayFormatInfo (org.apache.inlong.sort.formats.common.ArrayFormatInfo)1 BinaryFormatInfo (org.apache.inlong.sort.formats.common.BinaryFormatInfo)1 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)1 FormatInfo (org.apache.inlong.sort.formats.common.FormatInfo)1 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)1 MapFormatInfo (org.apache.inlong.sort.formats.common.MapFormatInfo)1 NullFormatInfo (org.apache.inlong.sort.formats.common.NullFormatInfo)1 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)1 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)1 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)1 AvroDeserializationInfo (org.apache.inlong.sort.protocol.deserialization.AvroDeserializationInfo)1 CanalSerializationInfo (org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo)1 DebeziumSerializationInfo (org.apache.inlong.sort.protocol.serialization.DebeziumSerializationInfo)1 JsonSerializationInfo (org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo)1 Test (org.junit.Test)1