Here is a simple code example to illustrate my question:
case class Record( key: String, value: Int )
object Job extends App
{
val env = StreamExecutionEn
I think you can implement this use case using ProcessFunction
In which you have count property and windowEnd property. Using that you can decide when to collect the data.
public class TimeCountWindowProcessFunction extends ProcessFunction {
protected long windowStart;
protected long windowEnd;
protected long count;
private ValueState state;
public TimeCountWindowProcessFunction(long windowSize, long count) {
this.windowSize = windowSize;
this.count = count;
}
@Override
public void open(Configuration parameters) {
TypeInformation typeInformation = TypeInformation.of(new TypeHint() {
});
ValueStateDescriptor descriptor = new ValueStateDescriptor("test", typeInformation);
state = getRuntimeContext().getState(descriptor);
}
@Override
public void processElement(CountPojo input, Context ctx, Collector out)
throws Exception {
long timestamp = ctx.timestamp();
windowStart = timestamp - (timestamp % windowSize);
windowEnd = windowStart + windowSize;
// retrieve the current count
CountPojo current = (CountPojo) state.value();
if (current == null) {
current = new CountPojo();
current.count = 1;
ctx.timerService().registerEventTimeTimer(windowEnd);
} else {
current.count += 1;
}
if(current.count >= count) {
out.collect(current);
}
// set the state's timestamp to the record's assigned event time timestamp
current.setLastModified(ctx.timestamp());
// write the state back
state.update(current);
}
@Override
public void onTimer(long timestamp, OnTimerContext ctx, Collector out)
throws Exception {
if (windowEnd == timestamp) {
out.collect(state.value());
}
state.clear();
}
}
I hope this will helpful to you.