简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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