Class: Wukong::Streamer::ListReducer
- Inherits:
-
AccumulatingReducer
- Object
- Base
- AccumulatingReducer
- Wukong::Streamer::ListReducer
- Defined in:
- lib/wukong/streamer/list_reducer.rb
Overview
Roll up all records from a given key into a single list.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#values ⇒ Object
Returns the value of attribute values.
Attributes inherited from AccumulatingReducer
Attributes inherited from Base
Instance Method Summary collapse
-
#accumulate(*record) ⇒ Object
aggregate all records.
-
#finalize {|[key, @values.to_flat.join(";")].flatten| ... } ⇒ Object
emit the key and all records, tab-separated.
-
#start!(*args) ⇒ Object
start with an empty list.
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 Attribute Details
#values ⇒ Object
Returns the value of attribute values.
7 8 9 |
# File 'lib/wukong/streamer/list_reducer.rb', line 7 def values @values end |
Instance Method Details
#accumulate(*record) ⇒ Object
aggregate all records. note that this accumulates the full record – key, value, everything.
16 17 18 |
# File 'lib/wukong/streamer/list_reducer.rb', line 16 def accumulate *record @values << record end |
#finalize {|[key, @values.to_flat.join(";")].flatten| ... } ⇒ Object
emit the key and all records, tab-separated
you will almost certainly want to override this method to do something interesting with the values (or override accumulate to gather scalar values)
26 27 28 |
# File 'lib/wukong/streamer/list_reducer.rb', line 26 def finalize yield [key, @values.to_flat.join(";")].flatten end |
#start!(*args) ⇒ Object
start with an empty list
10 11 12 |
# File 'lib/wukong/streamer/list_reducer.rb', line 10 def start! *args @values = [] end |