Facing exception error in riak-erlang client in erlang shell while doing Mapreduce

Steve Vinoski steve at basho.com
Sat May 17 10:51:02 EDT 2014


On Sat, May 17, 2014 at 10:04 AM, Gopi Krishna <gopi at lintelindia.com> wrote:

> Hi,
>
> I am getting the following , don't know what was happening could you
> please elaborate and explain the solution to this.
>
> I am working on erlang-riak-client.
>
>
> 1> {ok, Pid} = riakc_pb_socket:start_link('127.0.0.1',10017).
> {ok,<0.34.0>}
> 2>
> 2>
> 2> Object = riakc_obj:new(<<"test_age">>, <<"test1">>, <<"gopi & 1">>).
> {riakc_obj,<<"test_age">>,<<"test1">>,undefined,[],
>            undefined,<<"gopi & 1">>}
> 3>
> 3>
> 3> riakc_pb_socket:put(Pid,Object).
> ok
> 4>
> 4> Mapf = fun(Obj,_,_) -> [{I,1}|| I <-
> binary_to_term(riak_object:get_value(Object))] end.
>

There are two problems with your Mapf function:

1. The body of the function incorrectly uses Object, which is a variable in
your shell from command 2, rather than Obj, the incoming parameter to the
function. This is the source of the function_clause error you're getting.

2. You've stored a binary value in your object, not an Erlang term, so
binary_to_term will fail here with a badarg exception. Change your Mapf
function to this instead:

Mapf = fun(Obj,_,_) -> [riak_object:get_value(Obj)] end.

#Fun<erl_eval.18.82930912>
> 5> {ok, [{0,[R]}]} =
> riakc_pb_socket:mapred(Pid,<<"test_age">>,[{map,{qfun,Mapf},none,true}])
> 5> .
> ** exception error: no match of right hand side value
> {error,<<"{\"phase\":0,\"error\":\"function_clause\",\"input\":\"{ok,{r_object,<<\\\"test_age\\\">>,<<\\\"test1\\\">>,[{r_content,{dict"...>>}
>

If you make the changes I described above, you get:

5> {ok, [{0,[R]}]} =
riakc_pb_socket:mapred(Pid,<<"test_age">>,[{map,{qfun,Mapf},none,true}]).
{ok,[{0,[<<"gopi & 1">>]}]}
6> R.
<<"gopi & 1">>

exactly as expected.

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20140517/9f06dc0d/attachment.html>


More information about the riak-users mailing list