Sha256: 01b5068939c33b5a274ae2e5fd79a0bc10545e6e65771ab4684e9a82638b5c28

Contents?: true

Size: 736 Bytes

Versions: 12

Compression:

Stored size: 736 Bytes

Contents

class MapreduceTest
  
  include SkynetDebugger
  
  def self.run
    job = Skynet::Job.new(
      :mappers          => 2, 
      :reducers         => 1,
      :map_reduce_class => self,
      :map_data         => [OpenStruct.new({:created_by => 2}),OpenStruct.new({:created_by => 2}),OpenStruct.new({:created_by => 3})]
    )    
    results = job.run
  end

  def self.map(profiles)
    result = Array.new
    profiles.each do |profile|
      result << [profile.created_by, 1] if profile.created_by
    end
    result
  end

  def self.reduce(pairs)
    totals = Hash.new
    pairs.each do |pair|
      created_by, count = pair[0], pair[1]
      totals[created_by] ||= 0
      totals[created_by] += count
    end
    totals
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
brendan-skynet-0.9.3.1 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.2 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.3 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.5 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.6 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.7 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.3.8 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.31 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.32 examples/dgrep/lib/mapreduce_test.rb
brendan-skynet-0.9.33 examples/dgrep/lib/mapreduce_test.rb
timocratic-skynet-0.9.4 examples/dgrep/lib/mapreduce_test.rb
skynet-0.9.3 examples/dgrep/lib/mapreduce_test.rb