DESCRIPTION
A map/reduce query.
SYNOPSIS
my $riak = Data::Riak::Fast->new;
my $mr = Data::Riak::Fast::MapReduce->new({
riak => $riak,
inputs => [ [ "products8", $arg ] ],
phases => [
Data::Riak::Fast::MapReduce::Phase::Map->new(
language => "javascript",
source => "
function(v) {
var m = v.values[0].data.toLowerCase().match(/\w*/g);
var r = [];
for(var i in m) {
if(m[i] != '') {
var o = {};
o[m[i]] = 1;
r.push(o);
}
}
return r;
}
",
),
Data::Riak::Fast::MapReduce::Phase::Reduce->new(
language => "javascript",
source => "
function(v) {
var r = {};
for(var i in v) {
for(var w in v[i]) {
if(w in r) r[w] += v[i][w];
else r[w] = v[i][w];
}
}
return [r];
}
",
),
]
});
my $results = $mr->mapreduce;
inputs
Inputs to this query. There are few allowable forms.
For a single bucket:
inputs => "bucketname"
For a bucket and key (or many!):
inputs => [ [ "bucketname", "keyname" ] ]
inputs => [ [ "bucketname", "keyname" ], [ "bucketname", "keyname2" ] ]
And finally:
inputs => [ [ "bucketname", "keyname", "keyData" ] ]
phases
An arrayref of phases that will be executed in order. The phases should be one of Data::Riak::Fast::MapReduce::Phase::Link, Data::Riak::Fast::MapReduce::Phase::Map, or Data::Riak::Fast::MapReduce::Phase::Reduce.
METHOD =head2 mapreduce
Execute the mapreduce query.
To enable streaming, do the following:
my $results = $mr->mapreduce(chunked => 1);