Map function in erlang that takes entire bucket as input?

Christian Dahlqvist christian at basho.com
Thu Jan 10 11:03:19 EST 2013


Hi Shaan,

When using a bucket, input is <<"groceries">>. Did you by any chance specify it as [<<"groceries">>]?

I ran the example and it worked for me with the following result:

28> {ok, [{1, [R]}]} = riakc_pb_socket:mapred(Client,<<"groceries">>,[{map, {qfun, Count}, none, false},{reduce, {qfun, Merge}, none, true}]).          {ok,[{1,                            
      [{dict,3,16,16,8,80,48,
             {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
             {{[],[],[],[],[],
               [["bread"|1],["eggs"|1]],
               [["bacon"|2]],
               [],[],[],[],[],[],...}}}]}]}

Best regards,

Christian



On 10 Jan 2013, at 15:57, Shaan Sapra <shaanfire at gmail.com> wrote:

> Unfortunately, this does not seem to work..
> 
> ** exception error: no match of right hand side value {error,<<"{inputs,{\"Inputs target tuples must be {B,K} or {{B,K},KeyData}:\",\n         [<<\"groceries\">>]}}">>}
> 
> 
> On Thu, Jan 10, 2013 at 9:43 AM, Shaan Sapra <shaanfire at gmail.com> wrote:
> Ah thank you! 
> 
> 
> On Thu, Jan 10, 2013 at 9:40 AM, Christian Dahlqvist <christian at basho.com> wrote:
> Hi Shaan,
> 
> The riakc_pb_socket:mapred function can take several different types of input: a bucket name, a list of bucket/key pairs or a secondary index query specification. 
> 
> If you wanted to run the example in the tutorial based on all keys in the groceries bucket instead of having to specify the keys individually, you could set input to the bucket name <<"groceries">> as shown below:
> 
> {ok, [{1, [R]}]} = riakc_pb_socket:mapred(
>                          Client,
>                          [<<"groceries">>,
>                          [{map, {qfun, Count}, none, false},
>                           {reduce, {qfun, Merge}, none, true}]).
> 
> The specification for what inputs you can specify is available in the riakc.hrl file (https://github.com/basho/riak-erlang-client/blob/master/include/riakc.hrl) and looks like this:
> 
> -type mapred_inputs() :: [{bucket(), key()} | {{bucket(), key()}, term()}] |
>                          {modfun, Module::atom(), Function::atom(), [term()]} |
>                          bucket() |
>                          {index, bucket(), Index::binary(), key()} |
>                          {index, bucket(), Index::binary(), StartKey::key(), EndKey::key()}.
> 
> Best regards,
> 
> Christian
> 
> 
> 
> On 10 Jan 2013, at 06:56, Shaan Sapra <shaanfire at gmail.com> wrote:
> 
>> Hi all,
>> 
>> I'm exploring the erlang-riak-client and trying to write MapReduce functions to mimic the ones I've written in Javascript and in the riak-ruby-client.
>> 
>> Following the tutorial here, I have successfully run the query. I have now loaded a bucket with 10000 keys into Riak and now I want to write a simple map function that queries the bucket and returns all of the objects back to me.
>> 
>> I noticed that the input is specified as {<<"groceries">>, <<"mine">>}. Is there is a way to specify just the bucket in its entirety? If I wanted to query my bucket, would I have to list all 10000 keys in a list?
>> 
>> In the riak-ruby-client, it was possible to add the entire bucket. 
>> 
>> Thanks for any help! I'm sure this is a silly question, but I've been hard pressed to find good documentation for a novice like me.
>> 
>> Shaan
>> _______________________________________________
>> riak-users mailing list
>> riak-users at lists.basho.com
>> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20130110/d60aa996/attachment.html>


More information about the riak-users mailing list