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:
AfterWatermark
for 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.AfterProcessingTime
for firing after some amount of processing time has elapsed (typically since the first element in a pane).AfterPane
for 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. AnAfterFirst
trigger 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. AnAfterAll
trigger finishes after it fires once.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
For internal use only; no backwards-compatibility guarantees. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Return a trigger to use after aGroupByKey
to preserve the intention of this trigger.protected abstract Trigger
getContinuationTrigger
(List<Trigger> continuationTriggers) Subclasses should override this to return thegetContinuationTrigger()
of thisTrigger
.abstract Instant
For internal use only; no backwards-compatibility guarantees.int
hashCode()
boolean
isCompatible
(Trigger other) For internal use only; no backwards-compatibility guarantees.abstract boolean
For 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 aGroupByKey
to 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 thesubTriggers
in 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 theuntil
Trigger
fires then the combination fires.The expression
t1.orFinally(t2)
fires every timet1
fires, and finishes as soon as eithert1
finishes ort2
fires, in which case it fires one last time fort2
. Botht1
andt2
are executed in parallel. This means thatt1
may have fired sincet2
started, so not all of the elements thatt2
has 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
t1
isTrigger.OnceTrigger
, thent1.orFinally(t2)
is the same asAfterFirst.of(t1, t2)
.
-