Class: Wukong::Streamer::ListReducer

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

Overview

Roll up all records from a given key into a single list.

Direct Known Subclasses

Reducer, SetReducer

Instance Attribute Summary collapse

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 Attribute Details

#valuesObject

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)

Yields:



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