Combine.AccumulatingCombineFn (Google Cloud Dataflow SDK 1.9.1 API)

Google Cloud Dataflow SDK for Java, version 1.9.1

Class Combine.AccumulatingCombineFn<InputT,AccumT extends Combine.AccumulatingCombineFn.Accumulator<InputT,AccumT,OutputT>,OutputT>

  • Type Parameters:
    InputT - type of input values
    AccumT - type of mutable accumulator values
    OutputT - type of output values
    All Implemented Interfaces:
    CombineFnBase.GlobalCombineFn<InputT,AccumT,OutputT>, HasDisplayData, Serializable
    Direct Known Subclasses:
    ApproximateQuantiles.ApproximateQuantilesCombineFn, Top.TopCombineFn
    Enclosing class:

    public abstract static class Combine.AccumulatingCombineFn<InputT,AccumT extends Combine.AccumulatingCombineFn.Accumulator<InputT,AccumT,OutputT>,OutputT>
    extends Combine.CombineFn<InputT,AccumT,OutputT>
    A CombineFn that uses a subclass of Combine.AccumulatingCombineFn.Accumulator as its accumulator type. By defining the operations of the Accumulator helper class, the operations of the enclosing CombineFn are automatically provided. This can reduce the code required to implement a CombineFn.

    For example, the example from Combine.CombineFn above can be expressed using AccumulatingCombineFn more concisely as follows:

     public class AverageFn
         extends AccumulatingCombineFn<Integer, AverageFn.Accum, Double> {
       public Accum createAccumulator() {
         return new Accum();
       public class Accum
           extends AccumulatingCombineFn<Integer, AverageFn.Accum, Double>
                   .Accumulator {
         private int sum = 0;
         private int count = 0;
         public void addInput(Integer input) {
           sum += input;
         public void mergeAccumulator(Accum other) {
           sum += other.sum;
           count += other.count;
         public Double extractOutput() {
           return ((double) sum) / count;
     PCollection<Integer> pc = ...;
     PCollection<Double> average = pc.apply(Combine.globally(new AverageFn()));

    See Also:
    Serialized Form