Class AbstractUdfStreamOperator<OUT,F extends org.apache.flink.api.common.functions.Function>

java.lang.Object
org.apache.flink.streaming.api.operators.AbstractStreamOperator<OUT>
org.apache.flink.streaming.api.operators.AbstractUdfStreamOperator<OUT,F>
Type Parameters:
OUT - The output type of the operator
F - The type of the user function
All Implemented Interfaces:
Serializable, org.apache.flink.api.common.state.CheckpointListener, KeyContext, KeyContextHandler, org.apache.flink.streaming.api.operators.OutputTypeConfigurable<OUT>, StreamOperator<OUT>, StreamOperatorStateHandler.CheckpointedStreamOperator, UserFunctionProvider<F>, YieldingOperator<OUT>
Direct Known Subclasses:
BatchGroupedReduceOperator, CoBroadcastWithKeyedOperator, CoBroadcastWithNonKeyedOperator, CoProcessOperator, CoStreamFlatMap, CoStreamMap, IntervalJoinOperator, KeyedCoProcessOperator, KeyedProcessOperator, LegacyKeyedCoProcessOperator, LegacyKeyedProcessOperator, MapPartitionOperator, PartitionAggregateOperator, PartitionReduceOperator, ProcessOperator, StreamFilter, StreamFlatMap, StreamGroupedReduceOperator, StreamMap, StreamSink, StreamSource, WindowOperator

@PublicEvolving public abstract class AbstractUdfStreamOperator<OUT,F extends org.apache.flink.api.common.functions.Function> extends AbstractStreamOperator<OUT> implements org.apache.flink.streaming.api.operators.OutputTypeConfigurable<OUT>, UserFunctionProvider<F>
This is used as the base class for operators that have a user-defined function. This class handles the opening and closing of the user-defined functions, as part of the operator life cycle.
See Also:
  • Field Details

    • userFunction

      protected final F extends org.apache.flink.api.common.functions.Function userFunction
      The user function.
  • Constructor Details

    • AbstractUdfStreamOperator

      public AbstractUdfStreamOperator(F userFunction)
    • AbstractUdfStreamOperator

      protected AbstractUdfStreamOperator(StreamOperatorParameters<OUT> parameters, F userFunction)
  • Method Details

    • getUserFunction

      public F getUserFunction()
      Gets the user function executed in this operator.
      Specified by:
      getUserFunction in interface UserFunctionProvider<OUT>
      Returns:
      The user function of this operator.
    • setup

      protected void setup(StreamTask<?,?> containingTask, StreamConfig config, Output<StreamRecord<OUT>> output)
      Overrides:
      setup in class AbstractStreamOperator<OUT>
    • snapshotState

      public void snapshotState(StateSnapshotContext context) throws Exception
      Description copied from class: AbstractStreamOperator
      Stream operators with state, which want to participate in a snapshot need to override this hook method.
      Specified by:
      snapshotState in interface StreamOperatorStateHandler.CheckpointedStreamOperator
      Overrides:
      snapshotState in class AbstractStreamOperator<OUT>
      Parameters:
      context - context that provides information and means required for taking a snapshot
      Throws:
      Exception
    • initializeState

      public void initializeState(StateInitializationContext context) throws Exception
      Description copied from class: AbstractStreamOperator
      Stream operators with state which can be restored need to override this hook method.
      Specified by:
      initializeState in interface StreamOperatorStateHandler.CheckpointedStreamOperator
      Overrides:
      initializeState in class AbstractStreamOperator<OUT>
      Parameters:
      context - context that allows to register different states.
      Throws:
      Exception
    • open

      public void open() throws Exception
      Description copied from class: AbstractStreamOperator
      This method is called immediately before any elements are processed, it should contain the operator's initialization logic, e.g. state initialization.

      The default implementation does nothing.

      Specified by:
      open in interface StreamOperator<OUT>
      Overrides:
      open in class AbstractStreamOperator<OUT>
      Throws:
      Exception - An exception in this method causes the operator to fail.
    • finish

      public void finish() throws Exception
      Description copied from interface: StreamOperator
      This method is called at the end of data processing.

      The method is expected to flush all remaining buffered data. Exceptions during this flushing of buffered data should be propagated, in order to cause the operation to be recognized as failed, because the last data items are not processed properly.

      After this method is called, no more records can be produced for the downstream operators.

      WARNING: It is not safe to use this method to commit any transactions or other side effects! You can use this method to flush any buffered data that can later on be committed e.g. in a CheckpointListener.notifyCheckpointComplete(long).

      NOTE:This method does not need to close any resources. You should release external resources in the StreamOperator.close() method.

      Specified by:
      finish in interface StreamOperator<OUT>
      Overrides:
      finish in class AbstractStreamOperator<OUT>
      Throws:
      Exception - An exception in this method causes the operator to fail.
    • close

      public void close() throws Exception
      Description copied from interface: StreamOperator
      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.

      This method is expected to make a thorough effort to release all resources that the operator has acquired.

      NOTE:It can not emit any records! If you need to emit records at the end of processing, do so in the StreamOperator.finish() method.

      Specified by:
      close in interface StreamOperator<OUT>
      Overrides:
      close in class AbstractStreamOperator<OUT>
      Throws:
      Exception
    • notifyCheckpointComplete

      public void notifyCheckpointComplete(long checkpointId) throws Exception
      Specified by:
      notifyCheckpointComplete in interface org.apache.flink.api.common.state.CheckpointListener
      Overrides:
      notifyCheckpointComplete in class AbstractStreamOperator<OUT>
      Throws:
      Exception
    • notifyCheckpointAborted

      public void notifyCheckpointAborted(long checkpointId) throws Exception
      Specified by:
      notifyCheckpointAborted in interface org.apache.flink.api.common.state.CheckpointListener
      Overrides:
      notifyCheckpointAborted in class AbstractStreamOperator<OUT>
      Throws:
      Exception
    • setOutputType

      public void setOutputType(org.apache.flink.api.common.typeinfo.TypeInformation<OUT> outTypeInfo, org.apache.flink.api.common.ExecutionConfig executionConfig)
      Specified by:
      setOutputType in interface org.apache.flink.streaming.api.operators.OutputTypeConfigurable<OUT>
    • getUserFunctionParameters

      public org.apache.flink.configuration.Configuration getUserFunctionParameters()
      Since the streaming API does not implement any parametrization of functions via a configuration, the config returned here is actually empty.
      Returns:
      The user function parameters (currently empty)