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.



267
268
269
270
271
# File 'lib/jrf/stage.rb', line 267

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

Instance Attribute Details

#slotsObject (readonly)

Returns the value of attribute slots.



265
266
267
# File 'lib/jrf/stage.rb', line 265

def slots
  @slots
end

Instance Method Details

#array_input?Boolean

Returns:

  • (Boolean)


273
274
275
# File 'lib/jrf/stage.rb', line 273

def array_input?
  @array_input
end

#finishObject



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/jrf/stage.rb', line 281

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



277
278
279
# File 'lib/jrf/stage.rb', line 277

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