Class: Wukong::Streamer::CountingReducer
- Inherits:
-
AccumulatingReducer
- Object
- Base
- AccumulatingReducer
- Wukong::Streamer::CountingReducer
- 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
Attributes inherited from Base
Instance Method Summary collapse
-
#accumulate(*vals) ⇒ Object
record one more for this key.
-
#finalize {|[key, @count]| ... } ⇒ Object
emit each key field and the count, tab-separated.
-
#start!(*args) ⇒ Object
reset the counter to zero.
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.
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 |