Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flink 在Flink Java API中如何在keyBy()之后获取数据流密钥_Apache Flink_Flink Streaming - Fatal编程技术网

Apache flink 在Flink Java API中如何在keyBy()之后获取数据流密钥

Apache flink 在Flink Java API中如何在keyBy()之后获取数据流密钥,apache-flink,flink-streaming,Apache Flink,Flink Streaming,我正在读Flink流媒体应用程序中的卡夫卡集群。在获得源流之后,我想通过复合键和timeEvent tumbling窗口聚合事件,然后将结果写入表。 问题是,在应用aggregateFunction(只计算clientId的点击次数)之后,我没有找到获取每个输出记录的键的方法,因为api返回的是累积结果的实例,而不是相应的键 DataStream<Event> stream = environment.addSource(mySource) stream.keyBy

我正在读Flink流媒体应用程序中的卡夫卡集群。在获得源流之后,我想通过复合键和timeEvent tumbling窗口聚合事件,然后将结果写入表。 问题是,在应用aggregateFunction(只计算clientId的点击次数)之后,我没有找到获取每个输出记录的键的方法,因为api返回的是累积结果的实例,而不是相应的键

    DataStream<Event> stream = environment.addSource(mySource)

    stream.keyBy(new KeySelector<Event,Integer>() {
    public Integer getKey(Event event) { return event.getClientId(); })
.window(TumblingEventTimeWindows.of(Time.minutes(1))).aggregate(new MyAggregateFunction)
DataStream-stream=environment.addSource(mySource)
stream.keyBy(新的KeySelector(){
公共整数getKey(事件事件){return Event.getClientId();})
.window(TumblingEventTimeWindows.of(Time.minutes(1)).aggregate(新的MyAggregateFunction)
如何获取之前指定的密钥?我没有将输入事件的密钥注入累加器,因为我觉得这样做不好。

而不是

.aggregate(new MyAggregateFunction)
你可以用

.aggregate(new MyAggregateFunction, new MyProcessWindowFunction)
在这种情况下,ProcessWindowFunction的process方法将被传递密钥,以及AggregateFunction的预聚合结果和具有其他潜在相关信息的上下文对象。有关更多详细信息,请参阅文档中的部分