K - The type of key returned by the KeySelector.IN - The type of the incoming elements.OUT - The type of elements emitted by the InternalWindowFunction.W - The type of Window that the WindowAssigner assigns.@Internal public class WindowOperator<K,IN,ACC,OUT,W extends Window> extends AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W>> implements OneInputStreamOperator<IN,OUT>, Triggerable, org.apache.flink.api.java.typeutils.InputTypeConfigurable
WindowAssigner and
Trigger.
When an element arrives it gets assigned a key using a KeySelector and it gets
assigned to zero or more windows using a WindowAssigner. Based on this, the element
is put into panes. A pane is the bucket of elements that have the same key and same
Window. An element can be in multiple panes if it was assigned to multiple windows by the
WindowAssigner.
Each pane gets its own instance of the provided Trigger. This trigger determines when
the contents of the pane should be processed to emit results. When a trigger fires,
the given InternalWindowFunction is invoked to produce the results that are emitted for
the pane to which the Trigger belongs.
| Modifier and Type | Class and Description |
|---|---|
class |
WindowOperator.Context
Context is a utility for handling Trigger invocations. |
protected static class |
WindowOperator.Timer<K,W extends Window>
Internal class for keeping track of in-flight timers.
|
AbstractStreamOperator.CountingOutput| Modifier and Type | Field and Description |
|---|---|
protected long |
allowedLateness
The allowed lateness for elements.
|
protected WindowOperator.Context |
context |
protected long |
currentWatermark
To keep track of the current watermark so that we can immediately fire if a trigger
registers an event time callback for a timestamp that lies in the past.
|
protected org.apache.flink.api.common.typeutils.TypeSerializer<IN> |
inputSerializer
This is used to copy the incoming element because it can be put into several window
buffers.
|
protected org.apache.flink.api.java.functions.KeySelector<IN,K> |
keySelector |
protected org.apache.flink.api.common.typeutils.TypeSerializer<K> |
keySerializer
For serializing the key in checkpoints.
|
protected Map<K,MergingWindowSet<W>> |
mergingWindowsByKey |
protected Map<Long,ScheduledFuture<?>> |
processingTimeTimerFutures |
protected Set<WindowOperator.Timer<K,W>> |
processingTimeTimers |
protected PriorityQueue<WindowOperator.Timer<K,W>> |
processingTimeTimersQueue
Processing time timers that are currently in-flight.
|
protected com.google.common.collect.Multiset<Long> |
processingTimeTimerTimestamps |
protected TimestampedCollector<OUT> |
timestampedCollector
This is given to the
InternalWindowFunction for emitting elements with a given timestamp. |
protected Trigger<? super IN,? super W> |
trigger |
protected Set<WindowOperator.Timer<K,W>> |
watermarkTimers
Current waiting watermark callbacks.
|
protected PriorityQueue<WindowOperator.Timer<K,W>> |
watermarkTimersQueue |
protected WindowAssigner<? super IN,W> |
windowAssigner |
protected WindowAssigner.WindowAssignerContext |
windowAssignerContext |
protected org.apache.flink.api.common.typeutils.TypeSerializer<W> |
windowSerializer
For serializing the window in checkpoints.
|
protected org.apache.flink.api.common.state.StateDescriptor<? extends org.apache.flink.api.common.state.AppendingState<IN,ACC>,?> |
windowStateDescriptor |
userFunctionchainingStrategy, LOG, metrics, output| Constructor and Description |
|---|
WindowOperator(WindowAssigner<? super IN,W> windowAssigner,
org.apache.flink.api.common.typeutils.TypeSerializer<W> windowSerializer,
org.apache.flink.api.java.functions.KeySelector<IN,K> keySelector,
org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer,
org.apache.flink.api.common.state.StateDescriptor<? extends org.apache.flink.api.common.state.AppendingState<IN,ACC>,?> windowStateDescriptor,
InternalWindowFunction<ACC,OUT,K,W> windowFunction,
Trigger<? super IN,? super W> trigger,
long allowedLateness)
Creates a new
WindowOperator based on the given policies and user functions. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This method is called after all records have been added to the operators via the methods
OneInputStreamOperator.processElement(StreamRecord), or
TwoInputStreamOperator.processElement1(StreamRecord) and
TwoInputStreamOperator.processElement2(StreamRecord). |
protected void |
deleteCleanupTimer(W window)
Deletes the cleanup timer set for the contents of the provided window.
|
void |
dispose()
This method is called at the very end of the operator's life, both in the case of a successful
completion of the operation, and in the case of a failure and canceling.
|
org.apache.flink.api.java.functions.KeySelector<IN,K> |
getKeySelector() |
protected MergingWindowSet<W> |
getMergingWindowSet()
Retrieves the
MergingWindowSet for the currently active key. |
org.apache.flink.api.common.state.StateDescriptor<? extends org.apache.flink.api.common.state.AppendingState<IN,ACC>,?> |
getStateDescriptor() |
Trigger<? super IN,? super W> |
getTrigger() |
WindowAssigner<? super IN,W> |
getWindowAssigner() |
protected boolean |
isCleanupTime(W window,
long time)
Decides if it is time to clean up the window state.
|
protected boolean |
isLate(W window)
Decides if a window is currently late or not, based on the current
watermark, i.e.
|
void |
open()
This method is called immediately before any elements are processed, it should contain the
operator's initialization logic.
|
void |
processElement(StreamRecord<IN> element)
Processes one element that arrived at this operator.
|
void |
processWatermark(Watermark mark)
Processes a
Watermark. |
protected void |
registerCleanupTimer(W window)
Registers a timer to cleanup the content of the window.
|
void |
restoreState(StreamTaskState taskState)
Restores the operator state, if this operator's execution is recovering from a checkpoint.
|
void |
setInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type,
org.apache.flink.api.common.ExecutionConfig executionConfig) |
StreamTaskState |
snapshotOperatorState(long checkpointId,
long timestamp)
Called to draw a state snapshot from the operator.
|
void |
trigger(long time)
This method is invoked with the timestamp for which the trigger was scheduled.
|
getUserFunction, getUserFunctionParameters, notifyOfCompletedCheckpoint, setOutputType, setupgetChainingStrategy, getContainingTask, getCurrentProcessingTime, getExecutionConfig, getMetricGroup, getOperatorConfig, getPartitionedState, getPartitionedState, getRuntimeContext, getStateBackend, getUserCodeClassloader, registerTimer, setChainingStrategy, setKeyContext, setKeyContextElement1, setKeyContextElement2clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetChainingStrategy, getMetricGroup, notifyOfCompletedCheckpoint, setChainingStrategy, setKeyContextElement1, setKeyContextElement2, setupprotected final WindowAssigner<? super IN,W extends Window> windowAssigner
protected final org.apache.flink.api.common.state.StateDescriptor<? extends org.apache.flink.api.common.state.AppendingState<IN,ACC>,?> windowStateDescriptor
protected org.apache.flink.api.common.typeutils.TypeSerializer<IN> inputSerializer
protected final org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer
protected final org.apache.flink.api.common.typeutils.TypeSerializer<W extends Window> windowSerializer
protected final long allowedLateness
window.maxTimestamp + allowedLateness landmark.
protected transient TimestampedCollector<OUT> timestampedCollector
InternalWindowFunction for emitting elements with a given timestamp.protected transient Map<Long,ScheduledFuture<?>> processingTimeTimerFutures
protected transient long currentWatermark
protected transient WindowOperator.Context context
protected transient WindowAssigner.WindowAssignerContext windowAssignerContext
protected transient PriorityQueue<WindowOperator.Timer<K,W extends Window>> processingTimeTimersQueue
protected transient Set<WindowOperator.Timer<K,W extends Window>> processingTimeTimers
protected transient com.google.common.collect.Multiset<Long> processingTimeTimerTimestamps
protected transient Set<WindowOperator.Timer<K,W extends Window>> watermarkTimers
protected transient PriorityQueue<WindowOperator.Timer<K,W extends Window>> watermarkTimersQueue
protected transient Map<K,MergingWindowSet<W extends Window>> mergingWindowsByKey
public WindowOperator(WindowAssigner<? super IN,W> windowAssigner, org.apache.flink.api.common.typeutils.TypeSerializer<W> windowSerializer, org.apache.flink.api.java.functions.KeySelector<IN,K> keySelector, org.apache.flink.api.common.typeutils.TypeSerializer<K> keySerializer, org.apache.flink.api.common.state.StateDescriptor<? extends org.apache.flink.api.common.state.AppendingState<IN,ACC>,?> windowStateDescriptor, InternalWindowFunction<ACC,OUT,K,W> windowFunction, Trigger<? super IN,? super W> trigger, long allowedLateness)
WindowOperator based on the given policies and user functions.public final void setInputType(org.apache.flink.api.common.typeinfo.TypeInformation<?> type,
org.apache.flink.api.common.ExecutionConfig executionConfig)
setInputType in interface org.apache.flink.api.java.typeutils.InputTypeConfigurablepublic final void open()
throws Exception
AbstractStreamOperatorThe default implementation does nothing.
open in interface StreamOperator<OUT>open in class AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W extends Window>>Exception - An exception in this method causes the operator to fail.public final void close()
throws Exception
AbstractStreamOperatorOneInputStreamOperator.processElement(StreamRecord), or
TwoInputStreamOperator.processElement1(StreamRecord) and
TwoInputStreamOperator.processElement2(StreamRecord).
The method is expected to flush all remaining buffered data. Exceptions during this flushing of buffered should be propagated, in order to cause the operation to be recognized asa failed, because the last data items are not processed properly.
close in interface StreamOperator<OUT>close in class AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W extends Window>>Exception - An exception in this method causes the operator to fail.public void dispose()
AbstractStreamOperatordispose in interface StreamOperator<OUT>dispose in class AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W extends Window>>public void processElement(StreamRecord<IN> element) throws Exception
OneInputStreamOperatorprocessElement in interface OneInputStreamOperator<IN,OUT>Exceptionpublic void processWatermark(Watermark mark) throws Exception
OneInputStreamOperatorWatermark.
This method is guaranteed to not be called concurrently with other methods of the operator.processWatermark in interface OneInputStreamOperator<IN,OUT>ExceptionWatermarkpublic void trigger(long time)
throws Exception
TriggerableIf the triggering is delayed for whatever reason (trigger timer was blocked, JVM stalled due to a garbage collection), the timestamp supplied to this function will still be the original timestamp for which the trigger was scheduled.
trigger in interface Triggerabletime - The timestamp for which the trigger event was scheduled.Exceptionprotected MergingWindowSet<W> getMergingWindowSet() throws Exception
MergingWindowSet for the currently active key.
The caller must ensure that the correct key is set in the state backend.Exceptionprotected boolean isLate(W window)
window - The collection of windows returned by the WindowAssigner.eligibleWindows) for which the element should still be
considered when triggering.protected void registerCleanupTimer(W window)
window - the window whose state to discardprotected void deleteCleanupTimer(W window)
window - the window whose state to discardprotected final boolean isCleanupTime(W window, long time)
window - the window to cleantime - the current time (event or processing depending on the WindowAssignertrue if it is time to clean up the window state, false otherwise.public StreamTaskState snapshotOperatorState(long checkpointId, long timestamp) throws Exception
StreamOperatorsnapshotOperatorState in interface StreamOperator<OUT>snapshotOperatorState in class AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W extends Window>>checkpointId - The ID of the checkpoint.timestamp - The timestamp of the checkpoint.Exception - Forwards exceptions that occur while drawing snapshots from the operator
and the key/value state.public void restoreState(StreamTaskState taskState) throws Exception
StreamOperatorThis method is called after StreamOperator.setup(StreamTask, StreamConfig, Output)
and before StreamOperator.open().
restoreState in interface StreamOperator<OUT>restoreState in class AbstractUdfStreamOperator<OUT,InternalWindowFunction<ACC,OUT,K,W extends Window>>taskState - The state of operator that was snapshotted as part of checkpoint
from which the execution is restored.Exception - Exceptions during state restore should be forwarded, so that the system can
properly react to failed state restore and fail the execution attempt.public WindowAssigner<? super IN,W> getWindowAssigner()
Copyright © 2014–2016 The Apache Software Foundation. All rights reserved.