Meghashyam Sandeep V
Meghashyam Sandeep V

Reputation: 232

Is there a flink equivalent for takeOrdered to filter top k items from a window in a datastream?

DataStream<Tuple2<String, Long>> result = mappedStream
                .timeWindow(Time.seconds(30))
                .fold(new Tuple2<>("", 0L), new FoldFunction<Pojo, Tuple2<String, Long>>() {
                    @Override
                    public Tuple2<String, Long> fold(Tuple2<String, Long> acc, Pojo event) {
                        acc.f0 = event.getEt();
                        acc.f1 += 1;
                        return acc;
                    }
                });

I have a datastream where I have the counts for each keyedstream. I would now want to filter only the top 'k' items based on the count.

Upvotes: 0

Views: 235

Answers (1)

Robert Metzger
Robert Metzger

Reputation: 4542

You have to implement the sorting and top k operation yourself within the window apply function.

Upvotes: 1

Related Questions