简体   繁体   English

Flink窗口功能折叠

[英]Flink WindowFunction Fold

I create a sliding window and hope to recursively pack all the elements enter that window period, This is chunk of the code 我创建了一个滑动窗口,希望递归打包进入该窗口期间的所有元素,这是代码的一部分

.map(x => ((x.pickup.get.latitude, x.pickup.get.longitude), (x.dropoff.get.latitude, x.dropoff.get.longitude)))
        .windowAll(SlidingEventTimeWindows.of(Time.minutes(10), Time.minutes(1)))
        .fold(List[((Double, Double), (Double, Double))]) {(acc, v) => acc :+ ((v._1._1, v._1._2), (v._2._1, v._2._2))}

I hope to create a List in which the elements are tuple , but this does not work. 我希望创建一个其中元素为tupleList ,但这不起作用。

I tried this and it works: 我试过了,它有效:

val l2 : List[((Int, Int), (Int, Int))] = List(((1, 1), (2, 2)))
val newl2 = l2 :+ ((3, 3), (4, 4))

How can I do this? 我怎样才能做到这一点? Thanks so much 非常感谢

The first argument of the fold function needs to be the initial value and not the type. fold函数的第一个参数必须是初始值,而不是类型。 Changing the last line into: 将最后一行更改为:

.fold(List.empty[((Long, Long), (Long, Long))]) {(acc, v) => acc :+ ((v._1._1, v._1._2), (v._2._1, v._2._2))}

should do the trick. 应该可以。

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

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