[英]error when using fold function in flink
the code is below: 代码如下:
env
.addSource(...)
.map(r => (0, r))
.keyBy(0)
.timeWindow(Time.seconds(30), Time.seconds(1))
.fold(mutable.HashSet[String](),(a:(Int,String),b:mutable.HashSet[String])=>a)
error occurs during compilation,the error message is: 编译期间发生错误,错误消息是:
Error: missing arguments for method fold in class WindowedStream;
错误:在WindowedStream类中缺少方法折叠的参数; follow this method with `_' if you want to treat it as a partially applied function timeWindow(Time.seconds(30), Time.seconds(1)).fold(mutable.HashSetString,
如果你想把它作为一个部分应用的函数timeWindow(Time.seconds(30),Time.seconds(1))来处理这个方法,请使用`_'.fold(mutable.HashSetString,
but the function defined in class WindowedStream is: 但是WindowedStream类中定义的函数是:
public fold(R initialValue, FoldFunction function)
公共折叠(R initialValue,FoldFunction函数)
The problem is twofold: First of all, the fold
function expects the FoldFunction
to be passed in a second parameter list if you're using Scala. 问题是双重的:首先,如果你使用的是Scala,则
fold
函数需要在第二个参数列表中传递FoldFunction
。 Secondly, the first parameter of the FoldFunction
should be of the aggregating type. 其次,
FoldFunction
的第一个参数应该是聚合类型。 Thus, in your case it should be of type mutable.HashSet[String]
. 因此,在您的情况下,它应该是
mutable.HashSet[String]
类型。 The following snippet should do the trick: 以下代码片段可以解决这个问题:
env
.addSource(...)
.map(r => (0, r))
.keyBy(0)
.timeWindow(Time.seconds(30), Time.seconds(1))
.fold(mutable.HashSet[String]()){
(a: mutable HashSet[String], b: (Int, String)) => a
}
Be aware that the Flink's fold
API call is deprecated. 请注意,不推荐使用Flink的
fold
API调用。 It's now recommend to use the aggregate
API call. 现在建议使用
aggregate
API调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.