简体   繁体   English

如何在 Apache Flink 中 flatMap 到数据库?

[英]How to flatMap to database in Apache Flink?

I am using Apache Flink trying to get JSON records from Kafka to InfluxDB, splitting them from one JSON record into multiple InfluxDB points in the process.我正在使用 Apache Flink 尝试从 Kafka 获取 JSON 记录到 InfluxDB,在此过程中将它们从一个 JSON 记录拆分为多个 InfluxDB 点。

I found the flatMap transform and it feels like it fits the purpose.我找到了flatMap变换,感觉它符合目的。 Core code looks like this:核心代码如下所示:

DataStream<InfluxDBPoint> dataStream = stream.flatMap(new FlatMapFunction<JsonConsumerRecord, InfluxDBPoint>() {
    @Override
    public void flatMap(JsonConsumerRecord record, Collector<InfluxDBPoint> out) throws Exception {
        Iterator<Entry<String, JsonNode>> iterator = //...

        while (iterator.hasNext()) {
            // extract point from input
            InfluxDBPoint point = //...

            out.collect(point);
        }
    }
});

For some reason, I only get one of those collected points streamed into the database.出于某种原因,我只将收集到的点之一流式传输到数据库中。

Even when I print out all mapped entries, it seems to work just fine: dataStream.print() yields:即使我打印出所有映射条目,它似乎也能正常工作: dataStream.print()产生:

org.apache.flink.streaming.connectors.influxdb.InfluxDBPoint@144fd091
org.apache.flink.streaming.connectors.influxdb.InfluxDBPoint@57256d1
org.apache.flink.streaming.connectors.influxdb.InfluxDBPoint@28c38504
org.apache.flink.streaming.connectors.influxdb.InfluxDBPoint@2d3a66b3

Am I misunderstanding flatMap or might there be some bug in the Influx connector?我误解了flatMap还是 Influx 连接器中可能存在一些错误?

问题实际上与 Influx 中的一个系列(由其标签集和测量定义,如下所示每次只能有一个点有关,因此即使我的字段不同,最后一点用相同的时间覆盖了所有以前的点价值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM