Sha256: d466ef92fc73956e03ddc126c284626e16597cad7ab036e6b1087f0b879a3c9d

Contents?: true

Size: 488 Bytes

Versions: 10

Compression:

Stored size: 488 Bytes

Contents

module Wukong
  module Streamer

    #
    # Count the number of records for each key.
    #
    class CountingReducer < AccumulatingReducer
      attr_accessor :count

      # start the sum with 0 for each key
      def start! *_
        self.count = 0
      end
      # ... and count the number of records for this key
      def accumulate *_
        self.count += 1
      end
      # emit [key, count]
      def finalize
        yield [key, count].flatten
      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
wukong-1.5.4 lib/wukong/streamer/counting_reducer.rb
wukong-1.5.3 lib/wukong/streamer/counting_reducer.rb
wukong-1.5.2 lib/wukong/streamer/counting_reducer.rb
wukong-1.5.1 lib/wukong/streamer/counting_reducer.rb
wukong-1.5.0 lib/wukong/streamer/counting_reducer.rb
wukong-1.4.12 lib/wukong/streamer/counting_reducer.rb
wukong-1.4.11 lib/wukong/streamer/counting_reducer.rb
wukong-1.4.10 lib/wukong/streamer/counting_reducer.rb
wukong-1.4.9 lib/wukong/streamer/counting_reducer.rb
wukong-1.4.7 lib/wukong/streamer/counting_reducer.rb