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.



299
300
301
302
303
# File 'lib/jrf/stage.rb', line 299

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

Instance Attribute Details

#slotsObject (readonly)

Returns the value of attribute slots.



297
298
299
# File 'lib/jrf/stage.rb', line 297

def slots
  @slots
end

Instance Method Details

#array_input?Boolean

Returns:

  • (Boolean)


305
306
307
# File 'lib/jrf/stage.rb', line 305

def array_input?
  @array_input
end

#finishObject



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/jrf/stage.rb', line 313

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



309
310
311
# File 'lib/jrf/stage.rb', line 309

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