Interface ReduceFunction<T>

  • Type Parameters:
    T - Type of the elements that this function processes.
    All Superinterfaces:
    Function, Serializable
    All Known Implementing Classes:
    RichReduceFunction
    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 ReduceFunction<T>
    extends Function, Serializable
    Base interface for Reduce functions. Reduce functions combine groups of elements to a single value, by taking always two elements and combining them into one. Reduce functions may be used on entire data sets, or on grouped data sets. In the latter case, each group is reduced individually.

    For a reduce functions that work on an entire group at the same time (such as the MapReduce/Hadoop-style reduce), see GroupReduceFunction. In the general case, ReduceFunctions are considered faster, because they allow the system to use more efficient execution strategies.

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

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

    Like all functions, the ReduceFunction needs to be serializable, as defined in Serializable.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      T reduce​(T value1, T value2)
      The core method of ReduceFunction, combining two values into one value of the same type.
    • Method Detail

      • reduce

        T reduce​(T value1,
                 T value2)
          throws Exception
        The core method of ReduceFunction, combining two values into one value of the same type. The reduce function is consecutively applied to all values of a group until only a single value remains.
        Parameters:
        value1 - The first value to combine.
        value2 - The second value to combine.
        Returns:
        The combined value of both input values.
        Throws:
        Exception - This method may throw exceptions. Throwing an exception will cause the operation to fail and may trigger recovery.