Interface GroupReduceFunction<T,​O>

  • Type Parameters:
    T - Type of the elements that this function processes.
    O - The type of the elements returned by the user-defined function.
    All Superinterfaces:
    Function, Serializable
    All Known Implementing Classes:
    MergeOperatorStates, OperatorSubtaskStateReducer, RichGroupReduceFunction
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @Public
    @FunctionalInterface
    public interface GroupReduceFunction<T,​O>
    extends Function, Serializable
    The interface for group reduce functions. GroupReduceFunctions process groups of elements. They may aggregate them to a single value, or produce multiple result values for each group. The group may be defined by sharing a common grouping key, or the group may simply be all elements of a data set.

    For a reduce functions that works incrementally by combining always two elements, see ReduceFunction.

    The basic syntax for using a grouped GroupReduceFunction is as follows:

    
     DataSet<X> input = ...;
    
     DataSet<X> result = input.groupBy(<key-definition>).reduceGroup(new MyGroupReduceFunction());
     

    Partial computation can significantly improve the performance of a GroupReduceFunction. This technique is also known as applying a Combiner. Implement the GroupCombineFunction interface to enable partial computations, i.e., a combiner for this GroupReduceFunction.

    • Method Detail

      • reduce

        void reduce​(Iterable<T> values,
                    Collector<O> out)
             throws Exception
        The reduce method. The function receives one call per group of elements.
        Parameters:
        values - All records that belong to the given input key.
        out - The collector to hand results to.
        Throws:
        Exception - This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.