Class: PiecePipe::MapStep
Overview
This type of Step is designed to produce key-value pairs in anticipation of a following aggregation step (see HashedAggregator).
Subclasses implement #map and can produce output via #emit(key, value). Zero-or-more pairs may be generted per #map invocation.
The output structure is in fact a Hash with two keys: :key and :value, eg
class CalorieCounter < PiecePipe::MapStep
# Expects inputs to be a Hash with :person, :date and :calories.
# Output will look like: { :key => ["Dave","2012-05-10"], :value => 6000 }
def map(inputs)
key = [inputs[:person], inputs[:date]]
val = inputs[:calories]
emit key, val
end
end
Instance Attribute Summary
Attributes inherited from Step
Instance Method Summary collapse
Methods inherited from Step
Instance Method Details
#emit(key, value) ⇒ Object
30 31 32 |
# File 'lib/piece_pipe/map_step.rb', line 30 def emit(key, value) produce key: key, value: value end |
#map(item) ⇒ Object
26 27 28 |
# File 'lib/piece_pipe/map_step.rb', line 26 def map(item) emit item, item end |
#process(item) ⇒ Object
22 23 24 |
# File 'lib/piece_pipe/map_step.rb', line 22 def process(item) map item end |