Net::Riak::MapReduce - Allows you to build up and run a map/reduce operation on Riak
version 0.1600
use Net::Riak; my $riak = Net::Riak->new( host => "http://10.0.0.127:8098/" ); my $bucket = $riak->bucket("Cats"); my $query = $riak->add("Cats"); $query->map( 'function(v, d, a) { return [v]; }', arg => [qw/some params to your function/] ); $query->reduce("function(v) { return [v];}"); my $json = $query->run(10000); # can also be used like: my $query = Net::Riak::MapReduce->new( client => $riak->client ); # named functions my $json = $query->add_bucket('Dogs') ->map('Riak.mapValuesJson') ->reduce('Your.SortFunction') ->run;
The MapReduce object allows you to build up and run a map/reduce operations on Riak.
arguments: Net::Riak::Bucket / Bucket name / Net::Riak::Object / Array
return: a Net::Riak::MapReduce object
Add inputs to a map/reduce operation. This method takes three different forms, depending on the provided inputs. You can specify either a RiakObject, a string bucket name, or a bucket, key, and additional arg.
Create a MapReduce job
my $mapred = $riak->add( ["alice","p1"],["alice","p2"],["alice","p5"] );
Add your inputs to a MapReduce job
$mapred->add( ["alice","p1"],["alice","p2"] ); $mapred->add( "alice", "p5" ); $mapred->add( $riak->bucket("alice")->get("p6") );
arguments: bucketname, tag, keep
return: $self
Add a link phase to the map/reduce operation.
The default value for bucket name is '_', which means all buckets.
The default value for tag is '_'.
The flag argument means to flag whether to keep results from this stage in the map/reduce. (default False, unless this is the last step in the phase)
arguments: $function, %options
return: self
->map("function () {..}", keep => 0, args => ['foo', 'bar']); ->map('Riak.mapValuesJson'); # de-serializes data into JSON
Add a map phase to the map/reduce operation.
functions is either a named javascript function (i: 'Riak.mapValues'), or an anonymous javascript function (ie: 'function(...) ....')
%options is an optional associative array containing:
language keep - flag arg - an arrayref of parameterss for the JavaScript function
->reduce("function () {..}", keep => 1, args => ['foo', 'bar']);
Add a reduce phase to the map/reduce operation.
arguments: $timeout
return: arrayref
Run the map/reduce operation and attempt to de-serialize the JSON response to a perl structure. rayref of RiakLink objects if the last phase is a link phase.
Timeout in milliseconds,
REST API
https://wiki.basho.com/display/RIAK/MapReduce
List of built-in named functions for map / reduce phases
http://hg.basho.com/riak/src/tip/doc/js-mapreduce.org#cl-496
franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com>
This software is copyright (c) 2011 by linkfluence.
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 Net::Riak, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Riak
CPAN shell
perl -MCPAN -e shell install Net::Riak
For more information on module installation, please visit the detailed CPAN module installation guide.