Class WindowOperator<K,​W extends Window>

  • Type Parameters:
    K - The type of key returned by the KeySelector.
    W - The type of Window that the WindowAssigner assigns.
    All Implemented Interfaces:
    Serializable, org.apache.flink.api.common.state.CheckpointListener, org.apache.flink.streaming.api.operators.Input<org.apache.flink.table.data.RowData>, org.apache.flink.streaming.api.operators.KeyContext, org.apache.flink.streaming.api.operators.KeyContextHandler, org.apache.flink.streaming.api.operators.OneInputStreamOperator<org.apache.flink.table.data.RowData,​org.apache.flink.table.data.RowData>, org.apache.flink.streaming.api.operators.StreamOperator<org.apache.flink.table.data.RowData>, org.apache.flink.streaming.api.operators.StreamOperatorStateHandler.CheckpointedStreamOperator, org.apache.flink.streaming.api.operators.Triggerable<K,​W>, org.apache.flink.streaming.api.operators.YieldingOperator<org.apache.flink.table.data.RowData>
    Direct Known Subclasses:
    AggregateWindowOperator, TableAggregateWindowOperator

    public abstract class WindowOperator<K,​W extends Window>
    extends org.apache.flink.streaming.api.operators.AbstractStreamOperator<org.apache.flink.table.data.RowData>
    implements org.apache.flink.streaming.api.operators.OneInputStreamOperator<org.apache.flink.table.data.RowData,​org.apache.flink.table.data.RowData>, org.apache.flink.streaming.api.operators.Triggerable<K,​W>
    An operator that implements the logic for windowing based on a GroupWindowAssigner and Trigger.

    This is the base class for AggregateWindowOperator and TableAggregateWindowOperator. The big difference between AggregateWindowOperator and TableAggregateWindowOperator is AggregateWindowOperator emits only one result for each aggregate group, while TableAggregateWindowOperator can emit multi results for each aggregate group.

    When an element arrives it gets assigned a key using a KeySelector and it gets assigned to zero or more windows using a GroupWindowAssigner. 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 NamespaceAggsHandleFunctionBase is invoked to produce the results that are emitted for the pane to which the Trigger belongs.

    The parameter types: <IN>: RowData <OUT>: JoinedRowData(KEY, AGG_RESULT) <KEY>: GenericRowData <AGG_RESULT>: GenericRowData <ACC>: GenericRowData

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.flink.streaming.api.operators.TimestampedCollector<org.apache.flink.table.data.RowData> collector
      This is used for emitting elements with a given timestamp.
      protected org.apache.flink.runtime.state.internal.InternalValueState<K,​W,​org.apache.flink.table.data.RowData> previousState  
      protected boolean produceUpdates  
      protected RecordCounter recordCounter
      Used to count the number of added and retracted input records.
      protected ZoneId shiftTimeZone
      The shift timezone of the window, if the proctime or rowtime type is TIMESTAMP_LTZ, the shift timezone is the timezone user configured in TableConfig, other cases the timezone is UTC which means never shift when assigning windows.
      protected NamespaceAggsHandleFunctionBase<W> windowAggregator  
      protected InternalWindowProcessFunction<K,​W> windowFunction  
      • Fields inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator

        combinedWatermark, config, lastRecordAttributes1, lastRecordAttributes2, latencyStats, LOG, metrics, output, processingTimeService, stateHandler, stateKeySelector1, stateKeySelector2, timeServiceManager
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      protected abstract void compileGeneratedCode()  
      protected abstract void emitWindowResult​(W window)
      Emits the window result of the given window.
      protected org.apache.flink.metrics.Counter getNumLateRecordsDropped()  
      protected org.apache.flink.metrics.Gauge<Long> getWatermarkLatency()  
      void onEventTime​(org.apache.flink.streaming.api.operators.InternalTimer<K,​W> timer)  
      void onProcessingTime​(org.apache.flink.streaming.api.operators.InternalTimer<K,​W> timer)  
      void open()  
      void processElement​(org.apache.flink.streaming.runtime.streamrecord.StreamRecord<org.apache.flink.table.data.RowData> record)  
      boolean useSplittableTimers()  
      • Methods inherited from class org.apache.flink.streaming.api.operators.AbstractStreamOperator

        beforeInitializeStateHandler, finish, getContainingTask, getCurrentKey, getExecutionConfig, getInternalTimerService, getKeyedStateBackend, getKeyedStateStore, getMetricGroup, getOperatorConfig, getOperatorID, getOperatorName, getOperatorStateBackend, getOrCreateKeyedState, getPartitionedState, getPartitionedState, getProcessingTimeService, getRuntimeContext, getStateKeySelector1, getStateKeySelector2, getTimeServiceManager, getUserCodeClassloader, hasKeyContext1, hasKeyContext2, initializeState, initializeState, isAsyncKeyOrderedProcessingEnabled, isUsingCustomRawKeyedState, notifyCheckpointAborted, notifyCheckpointComplete, prepareSnapshotPreBarrier, processLatencyMarker, processLatencyMarker1, processLatencyMarker2, processRecordAttributes, processRecordAttributes1, processRecordAttributes2, processWatermark, processWatermark, processWatermark1, processWatermark1, processWatermark2, processWatermark2, processWatermarkStatus, processWatermarkStatus, processWatermarkStatus1, processWatermarkStatus2, reportOrForwardLatencyMarker, setCurrentKey, setKeyContextElement1, setKeyContextElement2, setMailboxExecutor, setProcessingTimeService, setup, snapshotState, snapshotState
      • Methods inherited from interface org.apache.flink.api.common.state.CheckpointListener

        notifyCheckpointAborted, notifyCheckpointComplete
      • Methods inherited from interface org.apache.flink.streaming.api.operators.Input

        processLatencyMarker, processRecordAttributes, processWatermark, processWatermark, processWatermarkStatus
      • Methods inherited from interface org.apache.flink.streaming.api.operators.KeyContext

        getCurrentKey, setCurrentKey
      • Methods inherited from interface org.apache.flink.streaming.api.operators.KeyContextHandler

        hasKeyContext
      • Methods inherited from interface org.apache.flink.streaming.api.operators.OneInputStreamOperator

        setKeyContextElement
      • Methods inherited from interface org.apache.flink.streaming.api.operators.StreamOperator

        finish, getMetricGroup, getOperatorAttributes, getOperatorID, initializeState, prepareSnapshotPreBarrier, setKeyContextElement1, setKeyContextElement2, snapshotState
    • Field Detail

      • produceUpdates

        protected final boolean produceUpdates
      • shiftTimeZone

        protected final ZoneId shiftTimeZone
        The shift timezone of the window, if the proctime or rowtime type is TIMESTAMP_LTZ, the shift timezone is the timezone user configured in TableConfig, other cases the timezone is UTC which means never shift when assigning windows.
      • recordCounter

        protected final RecordCounter recordCounter
        Used to count the number of added and retracted input records.
      • collector

        protected transient org.apache.flink.streaming.api.operators.TimestampedCollector<org.apache.flink.table.data.RowData> collector
        This is used for emitting elements with a given timestamp.
      • previousState

        protected transient org.apache.flink.runtime.state.internal.InternalValueState<K,​W extends Window,​org.apache.flink.table.data.RowData> previousState
    • Method Detail

      • useSplittableTimers

        public boolean useSplittableTimers()
        Overrides:
        useSplittableTimers in class org.apache.flink.streaming.api.operators.AbstractStreamOperator<org.apache.flink.table.data.RowData>
      • compileGeneratedCode

        protected abstract void compileGeneratedCode()
      • open

        public void open()
                  throws Exception
        Specified by:
        open in interface org.apache.flink.streaming.api.operators.StreamOperator<K>
        Overrides:
        open in class org.apache.flink.streaming.api.operators.AbstractStreamOperator<org.apache.flink.table.data.RowData>
        Throws:
        Exception
      • close

        public void close()
                   throws Exception
        Specified by:
        close in interface org.apache.flink.streaming.api.operators.StreamOperator<K>
        Overrides:
        close in class org.apache.flink.streaming.api.operators.AbstractStreamOperator<org.apache.flink.table.data.RowData>
        Throws:
        Exception
      • processElement

        public void processElement​(org.apache.flink.streaming.runtime.streamrecord.StreamRecord<org.apache.flink.table.data.RowData> record)
                            throws Exception
        Specified by:
        processElement in interface org.apache.flink.streaming.api.operators.Input<K>
        Throws:
        Exception
      • onEventTime

        public void onEventTime​(org.apache.flink.streaming.api.operators.InternalTimer<K,​W> timer)
                         throws Exception
        Specified by:
        onEventTime in interface org.apache.flink.streaming.api.operators.Triggerable<K,​W extends Window>
        Throws:
        Exception
      • onProcessingTime

        public void onProcessingTime​(org.apache.flink.streaming.api.operators.InternalTimer<K,​W> timer)
                              throws Exception
        Specified by:
        onProcessingTime in interface org.apache.flink.streaming.api.operators.Triggerable<K,​W extends Window>
        Throws:
        Exception
      • emitWindowResult

        protected abstract void emitWindowResult​(W window)
                                          throws Exception
        Emits the window result of the given window.
        Throws:
        Exception
      • getNumLateRecordsDropped

        protected org.apache.flink.metrics.Counter getNumLateRecordsDropped()
      • getWatermarkLatency

        protected org.apache.flink.metrics.Gauge<Long> getWatermarkLatency()