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:



8
9
10
11
# File 'lib/riak/map_reduce/results.rb', line 8

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



16
17
18
# File 'lib/riak/map_reduce/results.rb', line 16

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



23
24
25
26
27
28
29
# File 'lib/riak/map_reduce/results.rb', line 23

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