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, InputTypeConfigurable
WindowAssigner
and
Trigger
.
When an element arrives it gets assigned a key using a KeySelector
and it get's
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 of 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.
This operator also needs a WindowBufferFactory
to create a buffer for storing the
elements of each pane.
Modifier and Type | Class and Description |
---|---|
protected 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.
|
Modifier and Type | Field and Description |
---|---|
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 TypeSerializer<IN> |
inputSerializer
This is used to copy the incoming element because it can be put into several window
buffers.
|
protected KeySelector<IN,K> |
keySelector |
protected TypeSerializer<K> |
keySerializer
For serializing the key in checkpoints.
|
protected Set<WindowOperator.Timer<K,W>> |
processingTimeTimers
Processing time timers that are currently in-flight.
|
protected PriorityQueue<WindowOperator.Timer<K,W>> |
processingTimeTimersQueue |
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 TypeSerializer<W> |
windowSerializer
For serializing the window in checkpoints.
|
protected StateDescriptor<? extends MergingState<IN,ACC>,?> |
windowStateDescriptor |
userFunction
chainingStrategy, LOG, output
Constructor and Description |
---|
WindowOperator(WindowAssigner<? super IN,W> windowAssigner,
TypeSerializer<W> windowSerializer,
KeySelector<IN,K> keySelector,
TypeSerializer<K> keySerializer,
StateDescriptor<? extends MergingState<IN,ACC>,?> windowStateDescriptor,
InternalWindowFunction<ACC,OUT,K,W> windowFunction,
Trigger<? super IN,? super W> trigger)
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) . |
KeySelector<IN,K> |
getKeySelector() |
StateDescriptor<? extends MergingState<IN,ACC>,?> |
getStateDescriptor() |
Trigger<? super IN,? super W> |
getTrigger() |
WindowAssigner<? super IN,W> |
getWindowAssigner() |
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.
|
protected void |
processTriggerResult(TriggerResult triggerResult,
K key,
W window) |
void |
processWatermark(Watermark mark)
Processes a
Watermark . |
void |
restoreState(StreamTaskState taskState,
long recoveryTimestamp)
Restores the operator state, if this operator's execution is recovering from a checkpoint.
|
void |
setInputType(TypeInformation<?> type,
ExecutionConfig executionConfig)
Method that is called on an
OutputFormat when it is passed to
the DataSet's output method. |
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.
|
dispose, getUserFunction, getUserFunctionParameters, notifyOfCompletedCheckpoint, setOutputType, setup
disableInputCopy, getChainingStrategy, getContainingTask, getExecutionConfig, getOperatorConfig, getPartitionedState, getPartitionedState, getRuntimeContext, getStateBackend, getUserCodeClassloader, isInputCopyingDisabled, registerTimer, setChainingStrategy, setKeyContext, setKeyContextElement1, setKeyContextElement2
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dispose, getChainingStrategy, isInputCopyingDisabled, notifyOfCompletedCheckpoint, setChainingStrategy, setKeyContextElement1, setKeyContextElement2, setup
protected final WindowAssigner<? super IN,W extends Window> windowAssigner
protected final KeySelector<IN,K> keySelector
protected final StateDescriptor<? extends MergingState<IN,ACC>,?> windowStateDescriptor
protected TypeSerializer<IN> inputSerializer
protected final TypeSerializer<K> keySerializer
protected final TypeSerializer<W extends Window> windowSerializer
protected transient TimestampedCollector<OUT> timestampedCollector
InternalWindowFunction
for emitting elements with a given timestamp.protected transient long currentWatermark
protected transient WindowOperator.Context context
protected transient Set<WindowOperator.Timer<K,W extends Window>> processingTimeTimers
protected transient PriorityQueue<WindowOperator.Timer<K,W extends Window>> processingTimeTimersQueue
protected transient Set<WindowOperator.Timer<K,W extends Window>> watermarkTimers
protected transient PriorityQueue<WindowOperator.Timer<K,W extends Window>> watermarkTimersQueue
public WindowOperator(WindowAssigner<? super IN,W> windowAssigner, TypeSerializer<W> windowSerializer, KeySelector<IN,K> keySelector, TypeSerializer<K> keySerializer, StateDescriptor<? extends MergingState<IN,ACC>,?> windowStateDescriptor, InternalWindowFunction<ACC,OUT,K,W> windowFunction, Trigger<? super IN,? super W> trigger)
WindowOperator
based on the given policies and user functions.public final void setInputType(TypeInformation<?> type, ExecutionConfig executionConfig)
InputTypeConfigurable
OutputFormat
when it is passed to
the DataSet's output method. May be used to configures the output format based on the data type.setInputType
in interface InputTypeConfigurable
type
- The data type of the input.public final void open() throws Exception
AbstractStreamOperator
The 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
AbstractStreamOperator
OneInputStreamOperator.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 processElement(StreamRecord<IN> element) throws Exception
OneInputStreamOperator
processElement
in interface OneInputStreamOperator<IN,OUT>
Exception
protected void processTriggerResult(TriggerResult triggerResult, K key, W window) throws Exception
Exception
public final void processWatermark(Watermark mark) throws Exception
OneInputStreamOperator
Watermark
.
This method is guaranteed to not be called concurrently with other methods of the operator.processWatermark
in interface OneInputStreamOperator<IN,OUT>
Exception
Watermark
public final void trigger(long time) throws Exception
Triggerable
If 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 Triggerable
time
- The timestamp for which the trigger event was scheduled.Exception
public StreamTaskState snapshotOperatorState(long checkpointId, long timestamp) throws Exception
StreamOperator
snapshotOperatorState
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, long recoveryTimestamp) throws Exception
StreamOperator
This 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.recoveryTimestamp
- Global recovery timestampException
- Exceptions during state restore should be forwarded, so that the system can
properly react to failed state restore and fail the execution attempt.public KeySelector<IN,K> getKeySelector()
public WindowAssigner<? super IN,W> getWindowAssigner()
public StateDescriptor<? extends MergingState<IN,ACC>,?> getStateDescriptor()
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.