@Override public TriggerResult onElement(long time, TimeInterval window, TriggerContext ctx) { ValueStorage<Long> fireStamp = ctx.getValueStorage(FIRE_TIME_DESCR); if (fireStamp.get() == Long.MAX_VALUE) { // register first timer aligned with window start long start = window.getStartMillis() - (window.getStartMillis() % interval); long nextFireTimestamp = start + interval; LOG.trace("Registering PeriodicTimeTrigger for time {}", nextFireTimestamp); ctx.registerTimer(nextFireTimestamp, window); fireStamp.set(nextFireTimestamp); } return TriggerResult.NOOP; }
@Override public TriggerResult onElement(long time, TimeInterval window, TriggerContext ctx) { ValueStorage<Long> fireStamp = ctx.getValueStorage(FIRE_TIME_DESCR); if (fireStamp.get() == Long.MAX_VALUE) { // register first timer aligned with window start long start = window.getStartMillis() - (window.getStartMillis() % interval); long nextFireTimestamp = start + interval; LOG.trace("Registering PeriodicTimeTrigger for time {}", nextFireTimestamp); ctx.registerTimer(nextFireTimestamp, window); fireStamp.set(nextFireTimestamp); } return TriggerResult.NOOP; }
private void assertSessionWindow( TimeInterval window, long expectedStartMillis, long expectedEndMillis) { assertNotNull(window); assertEquals(expectedStartMillis, window.getStartMillis()); assertEquals(expectedEndMillis, window.getEndMillis()); }
long windowBegin = ((TimeInterval) out.getWindow()).getStartMillis(); long windowEnd = ((TimeInterval) out.getWindow()).getEndMillis(); out.collect(Triple.of(
long windowBegin = ((TimeInterval) out.getWindow()).getStartMillis(); long windowEnd = ((TimeInterval) out.getWindow()).getEndMillis(); out.collect(Triple.of(
b -> b.windowBy(GlobalWindowing.get(), w -> ""), b -> b.windowBy( Time.of(Duration.ofMinutes(5)), w -> String.valueOf(w.getStartMillis()))) .build());
.of(aggregated) .using(((Pair<String, Long> elem, Collector<String> context) -> { Date d = new Date(((TimeInterval) context.getWindow()).getStartMillis());
List<Pair<Long, Long>> ordered = output.getOutputs() .stream() .sorted(Comparator.comparing(e -> e.getFirst().getStartMillis())) .map(e -> Pair.of(e.getFirst().getStartMillis(), e.getSecond())) .collect(Collectors.toList()); assertEquals(asList(
@Test public void testTimeSlidingLabelAssignment() { TimeSliding<Long> windowing = TimeSliding .of(Duration.ofHours(1), Duration.ofMinutes(20)); UnaryFunction<Long, Long> eventTimeAssigner = e -> e * 1000L; long[] data = { 3590, 3600, 3610, 3800, 7190, 7200, 7210 }; for (long event : data) { Iterable<TimeInterval> labels = windowing .assignWindowsToElement(new Elem<>( GlobalWindowing.Window.get(), event, eventTimeAssigner.apply(event))); // verify window count assertEquals(3, Iterables.size(labels)); // verify that each window contains the original event for (TimeInterval l : labels) { long stamp = event * 1000L; assertTrue(stamp >= l.getStartMillis()); assertTrue(stamp <= l.getEndMillis()); } } }
.keyBy(e -> e.getFirst().getStartMillis()) .valueBy(new ToHashMap<>(Triple::getSecond, Triple::getThird)) .combineBy(new MergeMaps<>()) Pair.of(new TimeInterval(5, 10), toMap(Pair.of("one", 3L), Pair.of("two", 2L)))) .stream() .map(p -> Triple.of(p.getFirst(), p.getFirst().getStartMillis(), p.getSecond())) .collect(Collectors.toList()));
.using((UnaryFunctor<String, String>) (elem, c) -> { TimeInterval w = (TimeInterval) c.getWindow(); c.collect(w.getStartMillis() / 1000L + ": " + elem); }) .output();