Class: Wukong::Streamer::CountingReducer

Inherits:
AccumulatingReducer show all
Defined in:
lib/wukong/streamer/counting_reducer.rb

Overview

Emit each unique key and the count of its occurrences

Instance Attribute Summary

Attributes inherited from AccumulatingReducer

#key

Attributes inherited from Base

#own_options

Instance Method Summary collapse

Methods inherited from AccumulatingReducer

#after_stream, #before_stream, #get_key, #process

Methods inherited from Base

#after_stream, #bad_record!, #before_stream, #each_record, #emit, #initialize, #mapper, mapper, #monitor, #options, #process, #recordize, #run, run, #stream, #track

Constructor Details

This class inherits a constructor from Wukong::Streamer::Base

Instance Method Details

#accumulate(*vals) ⇒ Object

record one more for this key



14
15
16
# File 'lib/wukong/streamer/counting_reducer.rb', line 14

def accumulate *vals
  @count += 1
end

#finalize {|[key, @count]| ... } ⇒ Object

emit each key field and the count, tab-separated.

Yields:

  • ([key, @count])


19
20
21
# File 'lib/wukong/streamer/counting_reducer.rb', line 19

def finalize
  yield [key, @count]
end

#start!(*args) ⇒ Object

reset the counter to zero



9
10
11
# File 'lib/wukong/streamer/counting_reducer.rb', line 9

def start! *args
  @count = 0
end