Class: Jrf::Stage::MapReducer

Inherits:
Object
  • Object
show all
Defined in:
lib/jrf/stage.rb

Defined Under Namespace

Classes: SlotState

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builtin, array_input) ⇒ MapReducer

Returns a new instance of MapReducer.



238
239
240
241
242
# File 'lib/jrf/stage.rb', line 238

def initialize(builtin, array_input)
  @builtin = builtin
  @array_input = array_input
  @slots = {}
end

Instance Attribute Details

#slotsObject (readonly)

Returns the value of attribute slots.



236
237
238
# File 'lib/jrf/stage.rb', line 236

def slots
  @slots
end

Instance Method Details

#array_input?Boolean

Returns:

  • (Boolean)


244
245
246
# File 'lib/jrf/stage.rb', line 244

def array_input?
  @array_input
end

#finishObject



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/jrf/stage.rb', line 252

def finish
  if @array_input
    keys = @slots.keys.sort
    [keys.map { |k| Stage.resolve_template(@slots[k].template, @slots[k].reducers) }]
  else
    case @builtin
    when :map
      [@slots.map { |_k, s| Stage.resolve_template(s.template, s.reducers) }]
    when :map_values, :group_by
      result = {}
      @slots.each { |k, s| result[k] = Stage.resolve_template(s.template, s.reducers) }
      [result]
    else
      raise ArgumentError, "unexpected builtin: #{@builtin}"
    end
  end
end

#slot(key) ⇒ Object



248
249
250
# File 'lib/jrf/stage.rb', line 248

def slot(key)
  @slots[key] ||= SlotState.new
end