Class: Riak::MapReduce::Results Private

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/map_reduce/results.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Collects and normalizes results from MapReduce requests

Instance Method Summary collapse

Constructor Details

#initialize(mr) ⇒ Results

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new result collector

Parameters:



22
23
24
25
# File 'lib/riak/map_reduce/results.rb', line 22

def initialize(mr)
  @keep_count = mr.query.select {|p| p.keep }.size
  @hash = create_results_hash(mr.query)
end

Instance Method Details

#add(phase, result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds a new result to the collector

Parameters:

  • phase (Fixnum)

    the phase index

  • result (Array)

    the phase result



30
31
32
# File 'lib/riak/map_reduce/results.rb', line 30

def add(phase, result)
  @hash[phase] += result
end

#reportArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coalesces the query results

Returns:

  • (Array)

    the query results, coalesced according to the phase configuration



37
38
39
40
41
42
43
# File 'lib/riak/map_reduce/results.rb', line 37

def report
  if @keep_count > 1
    @hash.to_a.sort.map {|(num, results)| results }
  else
    @hash[@hash.keys.first]
  end
end