On Sat, Dec 8, 2012 at 6:11 AM, Antonio Rohman Fernandez < roh...@mahalostudio.com> wrote:
> ** > > QUERY: > > { > "inputs":{"bucket":"sales","index":"sex_bin","key":"male"}, > "query":[ > {"map": {"language":"javascript","source":"function(v,k,a) { var m = > v.values[0].data.match(\"1981\"); if (m != null) { return [v.key]; } else { > return []; }}"}}, > {"reduce":{"language":"javascript","source":"function(v,a) { return v; > }"}}, > {"reduce":{"language":"javascript","source":"function(v,a) { return > [v.length]; }"}} > ] > } > > RESPONSE: ( wrong... counting the length of the array gives [2] instead of > [101] > [2] > Hi, Rohman. This is working as expected. If it returned a different result on Riak 0.14, it was only by accident. The outputs from the first reduce phase do not arrive at the second reduce phase as one unit, but instead arrive a few at a time. You can force that second reduce phase to wait for all inputs before processing by adding '"arg":{"reduce_phase_only_1":true}' to the phase's definition[1], like so: {"reduce":{"language":"javascript","source":"function(v,a) { return [v.length]; }","arg":{"reduce_phase_only_1":true}}} Alternatively, you could replace both of those reduce phases with a single phase calling the built in riak_kv_mapreduce:reduce_count_inputs/2, like so: {"reduce":{"language":"erlang","module":"riak_kv_mapreduce","function":"reduce_count_inputs"}} This builtin is able to handle reduce work as it becomes available, instead of waiting for the whole batch. Hope that helps, Bryan [1] "Batch Size" http://docs.basho.com/riak/latest/references/appendices/MapReduce-Implementation/
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com