【发布时间】:2015-05-26 14:44:42
【问题描述】:
我尝试增强显示流使用的 Flink 示例。
我的目标是使用窗口功能(请参阅window 函数调用)。
我假设下面的代码输出流的最后 3 个数字的总和。
(由于 ubuntu 上的nc -lk 9999,该流已打开)
实际上,输出总结了所有输入的数字。切换到时间窗口产生相同的结果,即不产生窗口。
这是一个错误吗? (使用的版本:github上最新的master)
object SocketTextStreamWordCount {
def main(args: Array[String]) {
val hostName = args(0)
val port = args(1).toInt
val env = StreamExecutionEnvironment.getExecutionEnvironment
// Create streams for names and ages by mapping the inputs to the corresponding objects
val text = env.socketTextStream(hostName, port)
val currentMap = text.flatMap { (x:String) => x.toLowerCase.split("\\W+") }
.filter { (x:String) => x.nonEmpty }
.window(Count.of(3)).every(Time.of(1, TimeUnit.SECONDS))
// .window(Time.of(5, TimeUnit.SECONDS)).every(Time.of(1, TimeUnit.SECONDS))
.map { (x:String) => ("not used; just to have a tuple for the sum", x.toInt) }
val numberOfItems = currentMap.count
numberOfItems print
val counts = currentMap.sum( 1 )
counts print
env.execute("Scala SocketTextStreamWordCount Example")
}
}
【问题讨论】:
标签: apache-flink