Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleOneInputStreamProcessFunction.java
/** This class contains all logical related to process records from single input. */
public interface OneInputStreamProcessFunction<IN, OUT> extends ProcessFunction {
    /**
     * Process record and emit data through {@link Collector}.
     *
     * @param record to process.
     * @param output to emit processed records.
     * @param ctx, runtime context in which this function is executed.
     */
    void processRecord(IN record, Collector<OUT> output, RuntimeContext ctx) throws Exception;

    /**
     * This is a life-cycle method indicates that this function will no longer receive any input
     * data. This allowing the ProcessFunction to emit results at once rather than upon each record.
     *
     * @param output to emit record.
     * @param ctx, runtimethe context in which this function is executed.
     */
    default void endInput(Collector<OUT> output, RuntimeContextNonPartitionedContext ctx) {}
}

TwoInputStreamProcessFunction

Code Block
languagejava
titleTwoInputStreamProcessFunction.java
/** This class contains all logical related to process records from two input. */
public interface TwoInputStreamProcessFunction<IN1, IN2, OUT> extends ProcessFunction {
    /**
     * Process record from first input and emit data through {@link Collector}.
     *
     * @param record to process.
     * @param output to emit processed records.
     * @param ctx, runtime context in which this function is executed.
     */
    void processRecordFromFirstInput(IN1 record, Collector<OUT> output, RuntimeContext ctx)
            throws Exception;

    /**
     * Process record from second input and emit data through {@link Collector}.
     *
     * @param record to process.
     * @param output to emit processed records.
     * @param ctx, runtime context in which this function is executed.
     */
    void processRecordFromSecondInput(IN2 record, Collector<OUT> output, RuntimeContext ctx)
            throws Exception;

    /**
     * This is a life-cycle method indicates that this function will no longer receive any data from
     * the first input.
  This allowing the ProcessFunction*
 to emit results at once* rather@param thanctx, upon
the context in which this *function eachis recordexecuted.
     */
    default *void @param output to emit record.endFirstInput(NonPartitionedContext ctx) {}

     * @param ctx, runtime context in which this function is executed.
     */
    default void endFirstInput(Collector<OUT> output, RuntimeContext ctx) {}

    /**/**
     * This is a life-cycle method indicates that this function will no longer receive any data from
     * the second input.
 This allowing the ProcessFunction to*
 emit results at once rather* than@param upon
ctx, the context in which this *function eachis recordexecuted.
     */
    default *void @param output to emit record.
     * @param ctx, runtime context in which this function is executed.
     */
    default void endSecondInput(Collector<OUT> output, RuntimeContext ctx) {}
endSecondInput(NonPartitionedContext ctx) {}
}

BroadcastTwoInputStreamProcessFunction

Code Block
languagejava
titleBroadcastTwoInputStreamProcessFunction
/**
 * This class contains all logical related to process records from a broadcast stream and a
 * non-broadcast stream.
 */
public interface BroadcastTwoInputStreamProcessFunction<IN1, IN2, OUT> extends ProcessFunction {
    /**
     * Process record from non-broadcast input and emit data through {@link Collector}.
     *
     * @param record to process.
     * @param output to emit processed records.
     * @param ctx, runtime context in which this function is executed.
     */
    void processRecordFromNonBroadcastInput(IN1 record, Collector<OUT> output, RuntimeContext ctx)
            throws Exception;

    /**
     * Process record from broadcast input.In general, the broadcast side is not allowed to
     * manipulate state and output data because it corresponds to all partitions instead of a single
     * partition. But you could use broadcast context to process all the partitions at once.
     *
     * @param record to process.
     * @param ctx, the context in which this function is executed.
     */
    void processRecordFromBroadcastInput(IN2 record, BroadcastContext<OUT>NonPartitionedContext<OUT> ctx) throws Exception;

    /**
     * This is a life-cycle method indicates that this function will no longer receive any data from
     * the non-broadcast input.
 This allowing the ProcessFunction to*
 emit results at once rather
* @param ctx, the context *in which thanthis uponfunction eachis recordexecuted.
     */
    default *void @param output to emit record.
     * @param ctx, runtime context in which this function is executed.
     */
    default void endNonBroadcastInput(Collector<OUT> output, RuntimeContext ctx) {endNonBroadcastInput(NonPartitionedContext ctx) {}

    /**
     * This is a life-cycle method indicates that this function will no longer receive any data from
     * the broadcast input.
     *
     * @param ctx, the context in which this function is executed.
     */
    default void endBroadcastInput(BroadcastContext<OUT>NonPartitionedContext<OUT> ctx) {}
}
   

/**
 * This interface represents the context associated with broadcasting. all operations must be applied to all
 * partitions.
 */
 public interface BroadcastContext<OUT>NonPartitionedContext<OUT> {
    /**
     * Apply a function to all partitions. For keyed stream, it will apply to all keys. For
     * non-keyed stream, it will apply to single partition.
     */
    void applyToAllPartitions(ApplyPartitionFunction<OUT> applyPartitionFunction);
}

/** A function to be applied to all partitions . */
@FunctionalInterface
public interface ApplyPartitionFunction<OUT> {
    /**
     * The actual method to be applied to each partition.
     *
     * @param collector to output data.
     * @param ctx runtime context in which this function is executed.
     */
    void apply(Collector<OUT> collector, RuntimeContext ctx) throws Exception;
}

...

Code Block
languagejava
titleTwoOutputStreamProcessFunction.java
/** This class contains all logical related to process and emit records to two outputs. */
public interface TwoOutputStreamProcessFunction<IN, OUT1, OUT2> extends ProcessFunction {
    /**
     * Process and emit record to the first/second output through {@link Collector}s.
     *
     * @param record to process.
     * @param output1 to emit processed records to the first output.
     * @param output2 to emit processed records to the second output.
     * @param ctx, runtime context in which this function is executed.
     */
    void processRecord(
            IN record, Collector<OUT1> output1, Collector<OUT2> output2, RuntimeContext ctx);

   /**
     * This is a life-cycle method indicates that this function will no longer receive any input
     * data.
     *
     * @param ctx, the context in which this function is executed.
     */
    default void endInput(TwoOutputNonPartitionedContext ctx) {}
}

/**
 * This interface represents the context associated with all operations must be applied to all
 * partitions with two outputs.
 */
public interface TwoOutputNonPartitionedContext<OUT1, OUT2> {
    /**
     * Apply a function to all partitions. For keyed stream, it will apply to all keys. For
     * non-keyed stream, it will apply to single partition.
     */
    void applyToAllPartitions(TwoOutputNonPartitionedContext<OUT1, OUT2> applyPartitionFunction);
}

/** A *function Thisto isbe aapplied life-cycleto methodall indicatespartitions thatwith thistwo function will no longer receive any inputoutputs.. */
@FunctionalInterface
public interface TwoOutputApplyPartitionFunction<OUT1, OUT2> {
     /**
 data. This allowing the ProcessFunction* toThe emitactual resultsmethod atto oncebe ratherapplied than uponto each recordpartition.
     *
     * @param output1firstOutput to emit record to the first output.
     * @param output2secondOutput to emit record to the second output.
     * @param ctx, runtime context in which this function is executed.
     */
    default void endInputapply(
Collector<OUT1> firstOutput, Collector<OUT2> secondOutput, RuntimeContext ctx)
       Collector<OUT1> output1, Collector<OUT2> output2, RuntimeContext ctx) {}throws Exception;
}

RuntimeContext contains information about the context in which process functions are executed. It is currently just an empty interface but will be expanded later, such as supporting access to state, registering timers, etc. This part will be elaborated in the subsequent sub-FLIPs.

...