我刚开始使用apache flink。我从apachekafka源代码读取数据,需要转换 DataStream
.
在最后一步中,我尝试应用 WindowFunction
:
DataStream<Tuple8<Double, Double, String, Double, Double, Double, Double, Double>> dataStream =
env
.addSource(new FlinkKafkaConsumer08<>(
parameterTool.getRequired("topic"),
new SimpleStringSchema(),
parameterTool.getProperties()))
.flatMap(new SplitIntoRecordsString())
.flatMap(new SplitIntoTuples())
.keyBy(1)
.countWindow(5)
.apply(new windowApplyFunction());
public class windowApplyFunction implements WindowFunction<
Tuple8<Double, Double, String, Double, Double, Double, Double, Double>,
String,
Double,
Window>{
public void apply(Double key, Window window,
Iterable<Tuple8<Double, Double, String, Double, Double, Double, Double, Double>> values,
Collector<String> out)
throws Exception {
out.collect("MyResult");
}
}
不幸的是,我遇到了以下错误,不知道如何修复它:
The method apply(WindowFunction<Tuple8<Double,Double,String,Double,Double,Double,Double,Double>,R,Tuple,GlobalWindow>) in the type WindowedStream<Tuple8<Double,Double,String,Double,Double,Double,Double,Double>,Tuple,GlobalWindow> is not applicable for the arguments (FlinkManager.windowApplyFunction)
如果我换新的,一切正常 apply(new windowApplyFunction())
具有预定义的功能,例如。 sum(1)
.
2条答案
按热度按时间iezvtpos1#
你的
WindowFunction
应该是类型lhcgjxsq2#
谢谢你的提示!在纠正了这个错误后,我又换了一个小东西,现在可以用了!正确的代码: