Lets say this is my sample stream like so:
SingleOutputStreamOperator<Tuple2<String, SampleClass>> sampleStream = previousStream
.keyBy(value -> value.f1.getId())
.window(TumblingProcessingTimeWindows.of(Time.seconds(1)))
SampleClass has two fields id and time. It also has two getter methods getId() and getTime that gets those respective fields.
Goal: Now I want to perform the maxBy operation on the above stream with the time as my condition for maximiziation. Basically, I want the latest element in the front of the window.
How do I achieve my goal?
maxBy works on position of parameter and not on nested field inside it. For example:
.maxBy(positionToMaxBy = 1, first = true)
Here positionToMaxBy would consider the second parameter from the stream parameters, which is the object. But how do I get it to use the getTime() method to be used instead of the whole object?
A few solutions:
Tuple2<String, SampleClass>toSampleClassreduceinstead ofmaxByComparableonSampleClassand have thecompareTomethod only check the time field