Search in sources :

Example 1 with KafkaSinkInfo

use of org.apache.inlong.sort.protocol.sink.KafkaSinkInfo in project incubator-inlong by apache.

the class Entrance method buildSinkStream.

private static void buildSinkStream(DataStream<Row> sourceStream, Configuration config, SinkInfo sinkInfo, Map<String, Object> properties, long dataflowId) throws IOException, ClassNotFoundException {
    final String sinkType = checkNotNull(config.getString(Constants.SINK_TYPE));
    final int sinkParallelism = config.getInteger(Constants.SINK_PARALLELISM);
    switch(sinkType) {
        case Constants.SINK_TYPE_CLICKHOUSE:
            checkState(sinkInfo instanceof ClickHouseSinkInfo);
            ClickHouseSinkInfo clickHouseSinkInfo = (ClickHouseSinkInfo) sinkInfo;
            sourceStream.addSink(new ClickhouseRowSinkFunction(clickHouseSinkInfo)).uid(Constants.SINK_UID).name("Clickhouse Sink").setParallelism(sinkParallelism);
            break;
        case Constants.SINK_TYPE_HIVE:
            checkState(sinkInfo instanceof HiveSinkInfo);
            HiveSinkInfo hiveSinkInfo = (HiveSinkInfo) sinkInfo;
            if (hiveSinkInfo.getPartitions().length == 0) {
                // The committer operator is not necessary if partition is not existent.
                sourceStream.process(new HiveWriter(config, dataflowId, hiveSinkInfo)).uid(Constants.SINK_UID).name("Hive Sink").setParallelism(sinkParallelism);
            } else {
                sourceStream.process(new HiveWriter(config, dataflowId, hiveSinkInfo)).uid(Constants.SINK_UID).name("Hive Sink").setParallelism(sinkParallelism).addSink(new HiveCommitter(config, hiveSinkInfo)).name("Hive Committer").setParallelism(1);
            }
            break;
        case Constants.SINK_TYPE_ICEBERG:
            checkState(sinkInfo instanceof IcebergSinkInfo);
            IcebergSinkInfo icebergSinkInfo = (IcebergSinkInfo) sinkInfo;
            TableLoader tableLoader = TableLoader.fromHadoopTable(icebergSinkInfo.getTableLocation(), new org.apache.hadoop.conf.Configuration());
            FlinkSink.forRow(sourceStream, CommonUtils.getTableSchema(sinkInfo.getFields())).tableLoader(tableLoader).writeParallelism(sinkParallelism).build();
            break;
        case Constants.SINK_TYPE_KAFKA:
            checkState(sinkInfo instanceof KafkaSinkInfo);
            SerializationSchema<Row> schema = SerializationSchemaFactory.build(sinkInfo.getFields(), ((KafkaSinkInfo) sinkInfo).getSerializationInfo());
            sourceStream.addSink(buildKafkaSink((KafkaSinkInfo) sinkInfo, properties, schema, config)).uid(Constants.SINK_UID).name("Kafka Sink").setParallelism(sinkParallelism);
            break;
        default:
            throw new IllegalArgumentException("Unsupported sink type " + sinkType);
    }
}
Also used : HiveWriter(org.apache.inlong.sort.flink.hive.HiveWriter) IcebergSinkInfo(org.apache.inlong.sort.protocol.sink.IcebergSinkInfo) ClickhouseRowSinkFunction(org.apache.inlong.sort.singletenant.flink.clickhouse.ClickhouseRowSinkFunction) ClickHouseSinkInfo(org.apache.inlong.sort.protocol.sink.ClickHouseSinkInfo) HiveCommitter(org.apache.inlong.sort.flink.hive.HiveCommitter) HiveSinkInfo(org.apache.inlong.sort.protocol.sink.HiveSinkInfo) KafkaSinkInfo(org.apache.inlong.sort.protocol.sink.KafkaSinkInfo) Row(org.apache.flink.types.Row) TableLoader(org.apache.iceberg.flink.TableLoader)

Example 2 with KafkaSinkInfo

use of org.apache.inlong.sort.protocol.sink.KafkaSinkInfo in project incubator-inlong by apache.

the class KafkaSinkTestBase method testKafkaSink.

@Test(timeout = 3 * 60 * 1000)
public void testKafkaSink() throws Exception {
    TestingSource testingSource = createTestingSource();
    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    CountDownLatch testFinishedCountDownLatch = new CountDownLatch(1);
    executorService.execute(() -> {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        try {
            env.addSource(testingSource).addSink(buildKafkaSink(new KafkaSinkInfo(new FieldInfo[] {}, brokerConnStr, topic, null), new HashMap<>(), serializationSchema, new Configuration()));
            env.execute();
            testFinishedCountDownLatch.await();
        } catch (Exception e) {
            logger.error("Error occurred when executing flink test job: ", e);
        }
    });
    verify();
    testFinishedCountDownLatch.countDown();
}
Also used : Configuration(org.apache.inlong.sort.configuration.Configuration) HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) KafkaSinkInfo(org.apache.inlong.sort.protocol.sink.KafkaSinkInfo) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with KafkaSinkInfo

use of org.apache.inlong.sort.protocol.sink.KafkaSinkInfo 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 4 with KafkaSinkInfo

use of org.apache.inlong.sort.protocol.sink.KafkaSinkInfo in project incubator-inlong by apache.

the class SinkInfoUtils method createKafkaSinkInfo.

private static KafkaSinkInfo createKafkaSinkInfo(SourceResponse sourceResponse, KafkaSinkResponse sinkResponse, List<FieldInfo> sinkFields) {
    String addressUrl = sinkResponse.getAddress();
    String topicName = sinkResponse.getTopicName();
    SerializationInfo serializationInfo = SerializationUtils.createSerialInfo(sourceResponse, sinkResponse);
    return new KafkaSinkInfo(sinkFields.toArray(new FieldInfo[0]), addressUrl, topicName, serializationInfo);
}
Also used : KafkaSinkInfo(org.apache.inlong.sort.protocol.sink.KafkaSinkInfo) SerializationInfo(org.apache.inlong.sort.protocol.serialization.SerializationInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo)

Aggregations

KafkaSinkInfo (org.apache.inlong.sort.protocol.sink.KafkaSinkInfo)4 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 Row (org.apache.flink.types.Row)1 TableLoader (org.apache.iceberg.flink.TableLoader)1 Configuration (org.apache.inlong.sort.configuration.Configuration)1 HiveCommitter (org.apache.inlong.sort.flink.hive.HiveCommitter)1 HiveWriter (org.apache.inlong.sort.flink.hive.HiveWriter)1 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)1 JsonSerializationInfo (org.apache.inlong.sort.protocol.serialization.JsonSerializationInfo)1 SerializationInfo (org.apache.inlong.sort.protocol.serialization.SerializationInfo)1 ClickHouseSinkInfo (org.apache.inlong.sort.protocol.sink.ClickHouseSinkInfo)1 HiveSinkInfo (org.apache.inlong.sort.protocol.sink.HiveSinkInfo)1 IcebergSinkInfo (org.apache.inlong.sort.protocol.sink.IcebergSinkInfo)1