@Override protected Trigger getContinuationTrigger(List<Trigger> continuationTriggers) { return Repeatedly.forever(new AfterFirst(continuationTriggers)); }
@Override public Trigger getContinuationTrigger() { return new AfterWatermarkEarlyAndLate( earlyTrigger.getContinuationTrigger(), lateTrigger == null ? null : lateTrigger.getContinuationTrigger()); }
private <T> PTransform<PCollection<T>, PCollection<T>> window() { return Window.into(new GlobalWindows()); }
@Test public void testContinuation() throws Exception { OnceTrigger trigger1 = AfterProcessingTime.pastFirstElementInPane(); OnceTrigger trigger2 = AfterWatermark.pastEndOfWindow(); Trigger afterEach = AfterEach.inOrder(trigger1, trigger2); assertEquals( Repeatedly.forever( AfterFirst.of(trigger1.getContinuationTrigger(), trigger2.getContinuationTrigger())), afterEach.getContinuationTrigger()); }
@Test public void testFireDeadline() throws Exception { BoundedWindow window = new IntervalWindow(new Instant(0), new Instant(10)); assertEquals( BoundedWindow.TIMESTAMP_MAX_VALUE, AfterAll.of(AfterWatermark.pastEndOfWindow(), AfterPane.elementCountAtLeast(1)) .getWatermarkThatGuaranteesFiring(window)); }
@Test public void testToStringExcludesNeverTrigger() { Trigger trigger = AfterWatermark.pastEndOfWindow() .withEarlyFirings(Never.ever()) .withLateFirings(Never.ever()); assertEquals("AfterWatermark.pastEndOfWindow()", trigger.toString()); } }
@Test public void testContinuation() throws Exception { OnceTrigger trigger1 = AfterProcessingTime.pastFirstElementInPane(); OnceTrigger trigger2 = AfterWatermark.pastEndOfWindow(); Trigger afterFirst = AfterFirst.of(trigger1, trigger2); assertEquals( AfterFirst.of(trigger1.getContinuationTrigger(), trigger2.getContinuationTrigger()), afterFirst.getContinuationTrigger()); }
@Test public void testContinuation() throws Exception { OnceTrigger trigger1 = AfterProcessingTime.pastFirstElementInPane(); OnceTrigger trigger2 = AfterWatermark.pastEndOfWindow(); Trigger afterAll = AfterAll.of(trigger1, trigger2); assertEquals( AfterAll.of(trigger1.getContinuationTrigger(), trigger2.getContinuationTrigger()), afterAll.getContinuationTrigger()); }
@Override public W getSideInputWindow(BoundedWindow mainWindow) { if (mainWindow instanceof GlobalWindow) { throw new IllegalArgumentException( "Attempted to get side input window for GlobalWindow from non-global WindowFn"); } return assignWindow(mainWindow.maxTimestamp()); } };
@Test public void testEarlyAndLateFiringsToString() { Trigger trigger = AfterWatermark.pastEndOfWindow() .withEarlyFirings(StubTrigger.named("t1")) .withLateFirings(StubTrigger.named("t2")); assertEquals( "AfterWatermark.pastEndOfWindow().withEarlyFirings(t1).withLateFirings(t2)", trigger.toString()); }
@Override public Collection<IntervalWindow> assignWindows(AssignContext c) { // Assign each element into a window from its timestamp until the end of // the global window. I'd rather assign to the end of time, but it appears // that any window that exceeds the global window is dropped from the output // received by PAssert. return Arrays.asList(new IntervalWindow(c.timestamp(), GlobalWindow.INSTANCE.maxTimestamp())); }
@Test public void testContinuation() throws Exception { Trigger trigger = AfterProcessingTime.pastFirstElementInPane(); Trigger repeatedly = Repeatedly.forever(trigger); assertEquals( Repeatedly.forever(trigger.getContinuationTrigger()), repeatedly.getContinuationTrigger()); assertEquals( Repeatedly.forever(trigger.getContinuationTrigger().getContinuationTrigger()), repeatedly.getContinuationTrigger().getContinuationTrigger()); }
@Test public void testLateFiringsToString() { Trigger trigger = AfterWatermark.pastEndOfWindow().withLateFirings(StubTrigger.named("t1")); assertEquals("AfterWatermark.pastEndOfWindow().withLateFirings(t1)", trigger.toString()); }
@Override public void verifyCompatibility(WindowFn<?, ?> other) throws IncompatibleWindowException { if (!this.isCompatible(other)) { throw new IncompatibleWindowException( other, "WindowOddEvenBuckets is only compatible with WindowOddEvenBuckets."); } }
@Test public void testDefaultWindowMappingFnGlobal() { MonthsWindows windowFn = CalendarWindows.months(2); WindowMappingFn<?> mapping = windowFn.getDefaultWindowMappingFn(); thrown.expect(IllegalArgumentException.class); mapping.getSideInputWindow(GlobalWindow.INSTANCE); }
@Override public Collection<IntervalWindow> assignWindows(AssignContext c) { return assignWindows(c.timestamp()); }
/** * <b><i>(Experimental)</i></b> Override the default {@link OnTimeBehavior}, to control whether to * output an empty on-time pane. */ @Experimental(Kind.TRIGGER) public Window<T> withOnTimeBehavior(OnTimeBehavior behavior) { return toBuilder().setOnTimeBehavior(behavior).build(); }
/** * Returns a trigger which never fires. Output will be produced from the using {@link GroupByKey} * when the {@link BoundedWindow} closes. */ public static NeverTrigger ever() { // NeverTrigger ignores all inputs and is Window-type independent. return new NeverTrigger(); }
/** * Create a composite trigger that repeatedly executes the trigger {@code repeated}, firing each * time it fires and ignoring any indications to finish. * * <p>Unless used with {@link Trigger#orFinally} the composite trigger will never finish. * * @param repeated the trigger to execute repeatedly. */ public static Repeatedly forever(Trigger repeated) { return new Repeatedly(repeated); }
/** * Returns a {@link WindowFn} that windows elements into periods measured by months. * * <p>For example, {@code CalendarWindows.months(8).withStartingMonth(2014, 1).beginningOnDay(10)} * will window elements into 8 month windows where that start on the 10th day of month, and the * first window begins in January 2014. */ public static MonthsWindows months(int number) { return new MonthsWindows(number, 1, DEFAULT_START_DATE, DateTimeZone.UTC); }