Class: CopyReduce

Inherits:
ReduceBase show all
Defined in:
lib/mrtoolkit.rb

Overview

Reducer collects all values Outputs as many lines as input Init with number of fields to copy (default 1). Optional second arg is the number of initial fields to skip.

Instance Attribute Summary

Attributes inherited from Stage

#errors, #in_fields, #in_sep, #out_fields, #out_sep

Instance Method Summary collapse

Methods inherited from ReduceBase

#process_begin, #process_each, #process_end, #process_end_internal, #process_init, #process_internal, #process_term, #run

Methods inherited from Stage

#catch_errors, #copy_struct, #emit, #emit_separator, #field, #field_separator, #new_input, #new_output, #prepare, #process_step, #write_out

Constructor Details

#initialize(*args) ⇒ CopyReduce

Returns a new instance of CopyReduce.



299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/mrtoolkit.rb', line 299

def initialize(*args)
  if args[0]
    @n = args[0].to_i - 1
  else
    @n = 0
  end
  if args[1]
    @m = args[1].to_i - 1
  else
    @m = -1
  end
end

Instance Method Details

#declareObject



311
312
313
314
315
316
# File 'lib/mrtoolkit.rb', line 311

def declare
  (0..@m).each {|i| field "skip#{i}"}
  (0..@n).each {|i| field "col#{i}"}

  (0..@n).each {|i| emit "col#{i}"}
end

#process(input, output) ⇒ Object



318
319
320
# File 'lib/mrtoolkit.rb', line 318

def process(input, output)
  copy_struct(input, output, @m+1)
end