Question

I am trying to write a riak map reduce using riak-ruby-client. Javascript reduce function looks like this:

arr.reduce(callback,[initialValue]);

I am doing something like this:

map_reduce = Riak::MapReduce.new(Ripple.client)
map_reduce.add(bucket) // I have passed a valid bucket
var callback = "function(previous, current){return previous + current;}"

results = map_reduce.map(map_func).reduce(callback,1,:keep=>true).run //1 is the initial value as in javascript reduce func.

But riak does not treat 1 as the initial value here. Can someone tell how do I pass an initial value to reduce phase??

Was it helpful?

Solution

A reduce phase function takes two arguments, The first one is a list of inputs, containing the output from previous reduce phase iteration(s) as well as a batch of output from the preceding map/input phase. The second argument is a configuration parameter that is passed in every time the reduce phase function executes. This is described in greater detail in the Riak MapReduce documentation.

As reduce phase functions need to be commutative, associative, and idempotent, it is not possible to reliably identify which is the first iteration and it is therefore not possible to set an initial value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top