NAME
Net::Riak::MapReduce - Allows you to build up and run a map/reduce operation on Riak
VERSION
version 0.1702
SYNOPSIS
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;
DESCRIPTION
The MapReduce object allows you to build up and run a map/reduce operations on Riak.
ATTRIBUTES
- phases
- inputs_bucket
- inputs
- input_mode
METHODS
add
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") );
add_object
add_bucket_key_data
add_bucket
link
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)
map
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
arguments: $function, %options
return: $self
->reduce("function () {..}", keep => 1, args => ['foo', 'bar']);
Add a reduce phase to the map/reduce operation.
functions is either a named javascript function (i: 'Riak.mapValues'), or an anonymous javascript function (ie: 'function(...) ....')
run
arguments: $function, %options
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,
SEE ALSO
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
AUTHOR
franck cuny <franck@lumberjaph.net>, robin edwards <robin.ge@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 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.