Search in sources :

Example 1 with JsonSerializationInfo

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

the class RowToJsonKafkaSinkTest method prepareData.

@Override
protected void prepareData() throws IOException, ClassNotFoundException {
    topic = "test_kafka_row_to_json";
    serializationSchema = SerializationSchemaFactory.build(new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new MapFormatInfo(new StringFormatInfo(), new DoubleFormatInfo())), new FieldInfo("f3", new ArrayFormatInfo(new IntFormatInfo())) }, new JsonSerializationInfo());
    prepareTestRows();
}
Also used : MapFormatInfo(org.apache.inlong.sort.formats.common.MapFormatInfo) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) ArrayFormatInfo(org.apache.inlong.sort.formats.common.ArrayFormatInfo) DoubleFormatInfo(org.apache.inlong.sort.formats.common.DoubleFormatInfo) JsonSerializationInfo(org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 2 with JsonSerializationInfo

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

the class KafkaSinkInfoTest method init.

@Override
public void init() {
    expectedObject = new KafkaSinkInfo(new FieldInfo[] { new FieldInfo("field1", new StringFormatInfo()) }, "testAddress", "testTopic", new JsonSerializationInfo());
    expectedJson = "{\n" + "    \"type\":\"kafka\",\n" + "    \"fields\":[\n" + "        {\n" + "            \"type\":\"base\",\n" + "            \"name\":\"field1\",\n" + "            \"format_info\":{\n" + "                \"type\":\"string\"\n" + "            }\n" + "        }\n" + "    ],\n" + "    \"address\":\"testAddress\",\n" + "    \"topic\":\"testTopic\",\n" + "    \"serialization_info\":{\n" + "        \"type\":\"json\"\n" + "    }\n" + "}";
    equalObj1 = expectedObject;
    equalObj2 = new KafkaSinkInfo(new FieldInfo[] { new FieldInfo("field1", new StringFormatInfo()) }, "testAddress", "testTopic", new JsonSerializationInfo());
    unequalObj = new KafkaSinkInfo(new FieldInfo[] { new FieldInfo("field1", new StringFormatInfo()) }, "testAddress", "testTopic2", new JsonSerializationInfo());
}
Also used : KafkaSinkInfo(org.apache.inlong.sort.protocol.sink.KafkaSinkInfo) JsonSerializationInfo(org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 3 with JsonSerializationInfo

use of org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo 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

JsonSerializationInfo (org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo)3 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)2 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)2 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 DoubleFormatInfo (org.apache.inlong.sort.formats.common.DoubleFormatInfo)1 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)1 MapFormatInfo (org.apache.inlong.sort.formats.common.MapFormatInfo)1 AvroSerializationInfo (org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo)1 CanalSerializationInfo (org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo)1 DebeziumSerializationInfo (org.apache.inlong.sort.protocol.serialization.DebeziumSerializationInfo)1 KafkaSinkInfo (org.apache.inlong.sort.protocol.sink.KafkaSinkInfo)1