On Sat, May 17, 2014 at 10:04 AM, Gopi Krishna <g...@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
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com