Class Trigger
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AfterEach,AfterWatermark.AfterWatermarkEarlyAndLate,DefaultTrigger,OrFinallyTrigger,Repeatedly,ReshuffleTrigger,Trigger.OnceTrigger
Window transform and its associated WindowFn, and then passed to the associated Trigger to determine if the Window's contents should be output.
See GroupByKey and Window for more information about how grouping with windows
works.
The elements that are assigned to a window since the last time it was fired (or since the window was created) are placed into the current window pane. Triggers are evaluated against the elements as they are added. When the root trigger fires, the elements in the current pane will be output. When the root trigger finishes (indicating it will never fire again), the window is closed and any new elements assigned to that window are discarded.
Several predefined triggers are provided:
AfterWatermarkfor firing when the watermark passes a timestamp determined from either the end of the window or the arrival of the first element in a pane.AfterProcessingTimefor firing after some amount of processing time has elapsed (typically since the first element in a pane).AfterPanefor firing off a property of the elements in the current pane, such as the number of elements that have been assigned to the current pane.
In addition, triggers can be combined in a variety of ways:
Repeatedly.forever(org.apache.beam.sdk.transforms.windowing.Trigger)to create a trigger that executes forever. Any time its argument finishes it gets reset and starts over. Can be combined withorFinally(org.apache.beam.sdk.transforms.windowing.Trigger.OnceTrigger)to specify a condition that causes the repetition to stop.AfterEach.inOrder(org.apache.beam.sdk.transforms.windowing.Trigger...)to execute each trigger in sequence, firing each (and every) time that a trigger fires, and advancing to the next trigger in the sequence when it finishes.AfterFirst.of(org.apache.beam.sdk.transforms.windowing.Trigger.OnceTrigger...)to create a trigger that fires after at least one of its arguments fires. AnAfterFirsttrigger finishes after it fires once.AfterAll.of(org.apache.beam.sdk.transforms.windowing.Trigger.OnceTrigger...)to create a trigger that fires after all least one of its arguments have fired at least once. AnAfterAlltrigger finishes after it fires once.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFor internal use only; no backwards-compatibility guarantees. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn a trigger to use after aGroupByKeyto preserve the intention of this trigger.protected abstract TriggergetContinuationTrigger(List<Trigger> continuationTriggers) Subclasses should override this to return thegetContinuationTrigger()of thisTrigger.abstract InstantFor internal use only; no backwards-compatibility guarantees.inthashCode()booleanisCompatible(Trigger other) For internal use only; no backwards-compatibility guarantees.abstract booleanFor internal use only; no backwards-compatibility guarantees.orFinally(Trigger.OnceTrigger until) Specify an ending condition for this trigger.toString()
-
Field Details
-
subTriggers
-
-
Constructor Details
-
Trigger
-
Trigger
protected Trigger()
-
-
Method Details
-
subTriggers
-
getContinuationTrigger
Return a trigger to use after aGroupByKeyto preserve the intention of this trigger. Specifically, triggers that are time based and intended to provide speculative results should continue providing speculative results. Triggers that fire once (or multiple times) should continue firing once (or multiple times).If this method is not overridden, its default implementation delegates its behavior to
getContinuationTrigger(List)which is expected to be implemented by subclasses. -
getContinuationTrigger
Subclasses should override this to return thegetContinuationTrigger()of thisTrigger. For convenience, this is provided the continuation trigger of each of the sub-triggers in the same order assubTriggers.- Parameters:
continuationTriggers- contains the result ofgetContinuationTrigger()on each of thesubTriggersin the same order.
-
getWatermarkThatGuaranteesFiring
For internal use only; no backwards-compatibility guarantees.Returns a bound in event time by which this trigger would have fired at least once for a given window had there been input data.
For triggers that do not fire based on the watermark advancing, returns
BoundedWindow.TIMESTAMP_MAX_VALUE.This estimate may be used, for example, to determine that there are no elements in a side-input window, which causes the default value to be used instead.
-
mayFinish
For internal use only; no backwards-compatibility guarantees.Indicates whether this trigger may "finish". A top level trigger that finishes can cause data loss, so is rejected by GroupByKey validation.
-
isCompatible
For internal use only; no backwards-compatibility guarantees.Returns whether this performs the same triggering as the given
Trigger. -
toString
-
equals
-
hashCode
public int hashCode() -
orFinally
Specify an ending condition for this trigger. If theuntilTriggerfires then the combination fires.The expression
t1.orFinally(t2)fires every timet1fires, and finishes as soon as eithert1finishes ort2fires, in which case it fires one last time fort2. Botht1andt2are executed in parallel. This means thatt1may have fired sincet2started, so not all of the elements thatt2has seen are necessarily in the current pane.For example the final firing of the following trigger may only have 1 element:
Repeatedly.forever(AfterPane.elementCountAtLeast(2)) .orFinally(AfterPane.elementCountAtLeast(5))Note that if
t1isTrigger.OnceTrigger, thent1.orFinally(t2)is the same asAfterFirst.of(t1, t2).
-