Search in sources :

Example 1 with CanalSerializationInfo

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

the class DebeziumToCanalITCase method test.

@Test(timeout = 60 * 1000)
public void test() throws Exception {
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.execute(() -> {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        try {
            DataStream<SerializedRecord> sourceStream = env.addSource(new TestSource());
            // Deserialize
            DeserializationSchema<Row> deserializationSchema = DeserializationSchemaFactory.build(fieldInfos, new DebeziumDeserializationInfo(false, "ISO_8601"));
            FieldMappingTransformer fieldMappingTransformer = new FieldMappingTransformer(new Configuration(), fieldInfos);
            DeserializationFunction function = new DeserializationFunction(deserializationSchema, fieldMappingTransformer, false);
            DataStream<Row> deserializedStream = sourceStream.process(function);
            // Serialize and output
            SerializationSchema<Row> serializationSchema = SerializationSchemaFactory.build(fieldInfos, new CanalSerializationInfo());
            deserializedStream.addSink(new TestSink(serializationSchema));
            env.execute();
        } catch (Exception e) {
            logger.error("Error occurred when executing flink test job: ", e);
        } finally {
            jobFinishedLatch.countDown();
        }
    });
    try {
        while (!verify()) {
            Thread.sleep(500);
        }
        verificationFinishedLatch.countDown();
        jobFinishedLatch.await();
    } finally {
        executorService.shutdown();
    }
    Thread.sleep(10000);
}
Also used : DeserializationFunction(org.apache.inlong.sort.singletenant.flink.deserialization.DeserializationFunction) Configuration(org.apache.inlong.sort.configuration.Configuration) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) ExecutorService(java.util.concurrent.ExecutorService) DebeziumDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.DebeziumDeserializationInfo) FieldMappingTransformer(org.apache.inlong.sort.singletenant.flink.deserialization.FieldMappingTransformer) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 2 with CanalSerializationInfo

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

the class WholeDBMigrationITCase method test.

@Test(timeout = 60 * 1000)
public void test() throws Exception {
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.execute(() -> {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        try {
            DataStream<SerializedRecord> sourceStream = env.addSource(new TestSource());
            // Deserialize
            DeserializationSchema<Row> deserializationSchema = DeserializationSchemaFactory.build(fieldInfos, new DebeziumDeserializationInfo(false, "ISO_8601", true));
            FieldMappingTransformer fieldMappingTransformer = new FieldMappingTransformer(new Configuration(), fieldInfos);
            DeserializationFunction function = new DeserializationFunction(deserializationSchema, fieldMappingTransformer, false);
            DataStream<Row> deserializedStream = sourceStream.process(function);
            // Serialize and output
            SerializationSchema<Row> serializationSchema = SerializationSchemaFactory.build(fieldInfos, new CanalSerializationInfo());
            deserializedStream.addSink(new TestSink(serializationSchema));
            env.execute();
        } catch (Exception e) {
            logger.error("Error occurred when executing flink test job: ", e);
        } finally {
            jobFinishedLatch.countDown();
        }
    });
    try {
        while (!verify()) {
            Thread.sleep(500);
        }
        verificationFinishedLatch.countDown();
        jobFinishedLatch.await();
    } finally {
        executorService.shutdown();
    }
    Thread.sleep(10000);
}
Also used : DeserializationFunction(org.apache.inlong.sort.singletenant.flink.deserialization.DeserializationFunction) Configuration(org.apache.inlong.sort.configuration.Configuration) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) ExecutorService(java.util.concurrent.ExecutorService) DebeziumDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.DebeziumDeserializationInfo) FieldMappingTransformer(org.apache.inlong.sort.singletenant.flink.deserialization.FieldMappingTransformer) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 3 with CanalSerializationInfo

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

the class RowToCanalKafkaSinkTest method prepareData.

@Override
protected void prepareData() throws IOException, ClassNotFoundException {
    topic = "test_kafka_row_to_canal";
    fieldInfos = new FieldInfo[] { new FieldInfo("f1", new StringFormatInfo()), new FieldInfo("f2", new IntFormatInfo()) };
    serializationSchema = SerializationSchemaFactory.build(fieldInfos, new CanalSerializationInfo());
    prepareTestData();
}
Also used : IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Example 4 with CanalSerializationInfo

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

the class CanalSerializationTest method test.

@Test
public void test() throws Exception {
    SerializationSchema<Row> canalJsonSerializationSchema = SerializationSchemaFactory.build(fieldInfos, new CanalSerializationInfo());
    canalJsonSerializationSchema.open(new InitializationContext() {

        @Override
        public MetricGroup getMetricGroup() {
            return null;
        }

        @Override
        public UserCodeClassLoader getUserCodeClassLoader() {
            return null;
        }
    });
    Row row = Row.of("name", 29, "database", "table", 123L, false, "INSERT");
    String result = new String(canalJsonSerializationSchema.serialize(row));
    String expectedResult = "{\"data\":[{\"name\":\"name\",\"age\":29}]," + "\"type\":\"INSERT\",\"database\":\"database\"," + "\"table\":\"table\",\"es\":123,\"isDdl\":false}";
    assertEquals(expectedResult, result);
}
Also used : UserCodeClassLoader(org.apache.flink.util.UserCodeClassLoader) InitializationContext(org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext) MetricGroup(org.apache.flink.metrics.MetricGroup) CanalSerializationInfo(org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 5 with CanalSerializationInfo

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

CanalSerializationInfo (org.apache.inlong.sort.protocol.serialization.CanalSerializationInfo)5 Row (org.apache.flink.types.Row)3 Test (org.junit.Test)3 ExecutorService (java.util.concurrent.ExecutorService)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 Configuration (org.apache.inlong.sort.configuration.Configuration)2 DebeziumDeserializationInfo (org.apache.inlong.sort.protocol.deserialization.DebeziumDeserializationInfo)2 DeserializationFunction (org.apache.inlong.sort.singletenant.flink.deserialization.DeserializationFunction)2 FieldMappingTransformer (org.apache.inlong.sort.singletenant.flink.deserialization.FieldMappingTransformer)2 InitializationContext (org.apache.flink.api.common.serialization.SerializationSchema.InitializationContext)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 UserCodeClassLoader (org.apache.flink.util.UserCodeClassLoader)1 DataTypeEnum (org.apache.inlong.common.enums.DataTypeEnum)1 BinlogSourceResponse (org.apache.inlong.manager.common.pojo.source.binlog.BinlogSourceResponse)1 IntFormatInfo (org.apache.inlong.sort.formats.common.IntFormatInfo)1 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)1 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)1 AvroSerializationInfo (org.apache.inlong.sort.protocol.serialization.AvroSerializationInfo)1 DebeziumSerializationInfo (org.apache.inlong.sort.protocol.serialization.DebeziumSerializationInfo)1 JsonSerializationInfo (org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo)1