Class: CouchProxy::Reduce::MapReducer

Inherits:
BaseReducer show all
Defined in:
lib/couchproxy/reduce/map_reducer.rb

Overview

Sorts and merges map query results from many different source streams.

Constant Summary

Constants inherited from BaseReducer

BaseReducer::ID, BaseReducer::KEY

Instance Method Summary collapse

Methods inherited from BaseReducer

#complete?, #reduce

Constructor Details

#initialize(args) ⇒ MapReducer

Args should contain the following keys:

sources: List of stream sources used to identify from where
         streaming rows are arriving.
  limit: Maximum number of rows to return. If not specified, all
         rows are returned.
   skip: Number of rows at the start of the stream to skip before
         returning the rest. If not specified, no rows are skipped.

collator: A CouchProxy::Collator instance used to sort rows.



17
18
19
20
21
22
23
24
25
# File 'lib/couchproxy/reduce/map_reducer.rb', line 17

def initialize(args)
  collator = args[:collator]
  # key = 0, id = 1
  @sorter = proc do |a, b|
    key = collator.compare(a[0], b[0])
    (key == 0) ? collator.compare(a[1], b[1]) : key
  end
  super(args)
end