use of org.apache.flink.api.java.tuple.Tuple4 in project flink by apache.
the class EventTimeAllWindowCheckpointingITCase method testPreAggregatedTumblingTimeWindow.
@Test
public void testPreAggregatedTumblingTimeWindow() {
final int numElementsPerKey = 3000;
final int windowSize = 100;
final int numKeys = 1;
try {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(PARALLELISM);
env.enableCheckpointing(100);
env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 0));
env.addSource(new FailingSource(new EventTimeWindowCheckpointingITCase.KeyedEventTimeGenerator(numKeys, windowSize), numElementsPerKey)).rebalance().windowAll(TumblingEventTimeWindows.of(Time.milliseconds(windowSize))).reduce(new ReduceFunction<Tuple2<Long, IntType>>() {
@Override
public Tuple2<Long, IntType> reduce(Tuple2<Long, IntType> a, Tuple2<Long, IntType> b) {
return new Tuple2<>(a.f0, new IntType(a.f1.value + b.f1.value));
}
}, new RichAllWindowFunction<Tuple2<Long, IntType>, Tuple4<Long, Long, Long, IntType>, TimeWindow>() {
private boolean open = false;
@Override
public void open(Configuration parameters) {
assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks());
open = true;
}
@Override
public void apply(TimeWindow window, Iterable<Tuple2<Long, IntType>> input, Collector<Tuple4<Long, Long, Long, IntType>> out) {
// validate that the function has been opened properly
assertTrue(open);
for (Tuple2<Long, IntType> in : input) {
out.collect(new Tuple4<>(in.f0, window.getStart(), window.getEnd(), in.f1));
}
}
}).addSink(new ValidatingSink<>(new EventTimeWindowCheckpointingITCase.SinkValidatorUpdateFun(numElementsPerKey), new EventTimeWindowCheckpointingITCase.SinkValidatorCheckFun(numKeys, numElementsPerKey, windowSize))).setParallelism(1);
env.execute("Tumbling Window Test");
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.apache.flink.api.java.tuple.Tuple4 in project mangolaa-streams-processing-flink by Adsizzlerlabs.
the class AggregatedBidReqKey method getKey.
@Override
public Tuple4<Integer, Integer, Integer, ZonedDateTime> getKey(final BidReq bidReq) throws Exception {
val advId = bidReq.getAdvId();
val sourceId = bidReq.getSourceId();
val clientId = bidReq.getClientId();
val minute = TimeUtil.roundOffToMinute(bidReq.getTimestamp());
return new Tuple4<>(advId, sourceId, clientId, minute);
}
Aggregations