Class: CrossJoin
Instance Method Summary collapse
Methods inherited from Join
#initialize, #null_left, #null_right, #report
Constructor Details
This class inherits a constructor from Join
Instance Method Details
#output ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/streaming_join/cross_join.rb', line 4 def output left,right = @join left.each do |lk,lv| right.each do |rk,rv| o = "#{lk}#{@sep_out}#{lv}#{@sep_out}#{rk}#{@sep_out}#{rv}" if block_given? yield o else puts o end end end end |
#process_stream(input = STDIN, &blk) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/streaming_join/cross_join.rb', line 19 def process_stream(input = STDIN, &blk) @join = [] # big memory, big prizes input.each do |line| key, side, value = line.chomp.split(@sep_in, 3) (@join[side.to_i] ||= []) << [key, value] end output(&blk) if not @join.empty? end |