Data::Riak::MapReduce - A map/reduce query
version 1.9
my $riak = Data::Riak->new; my $mr = Data::Riak::MapReduce->new({ riak => $riak, inputs => [ [ "products8", $arg ] ], phases => [ Data::Riak::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::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;
A map/reduce query.
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" ] ]
An arrayref of phases that will be executed in order. The phases should be one of Data::Riak::MapReduce::Phase::Link, Data::Riak::MapReduce::Phase::Map, or Data::Riak::MapReduce::Phase::Reduce.
Execute the mapreduce query.
To enable streaming, do the following:
my $results = $mr->mapreduce(chunked => 1);
Andrew Nelson <anelson at cpan.org>
Florian Ragwitz <rafl@debian.org>
This software is copyright (c) 2013 by Infinity Interactive.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Data::Riak, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Riak
CPAN shell
perl -MCPAN -e shell install Data::Riak
For more information on module installation, please visit the detailed CPAN module installation guide.