0

I have done the following.I have stored the details like the following,but even though i am getting error in the mapreduce, please help me.i want the data of the test_age bucket. to display {gopi,1}.

1> {ok, Pid} = riakc_pb_socket:start_link('127.0.0.1',10017).
{ok,<0.34.0>}
2> Object = riakc_obj:new(<<"test_age">>, <<"test1">>, <<"gopi & 1">>). 
{riakc_obj,<<"test_age">>,<<"test1">>,undefined,[],
       undefined,<<"gopi & 1">>}
3> riakc_pb_socket:put(Pid,Object).
ok 
4> Mapf = fun(Obj,_,_) -> [{I,1}|| I <- binary_to_term(riak_object:get_value(Object))]   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"...>>}

where i am doing wrong that i cannot figured out. please

Krish gopi
  • 155
  • 4
  • 12
  • Part of the error is missing because Erlang is truncating it; it may be helpful to see the full error. Try printing the results (see https://gist.github.com/macintux/0e0222348263799ffb81) and it may give you more useful information, or at least help someone else solve it. – macintux May 18 '14 at 13:35

1 Answers1

0

The issue is with your map function:

Mapf = fun(Obj,_,_) -> [{I,1}|| I <- binary_to_term(riak_object:get_value(Object))] end.

When this executes,Obj will contain the r_object record, but Object will be undefined. You probably meant to use:

Mapf = fun(Obj,_,_) -> [{I,1}|| I <- binary_to_term(riak_object:get_value(Obj))] end.

The value you are storing is the binary <<"gopi & 1">> which is what would be returned by the call to binary_to_term. The list comprehension then is effectively [{I,1}|| I <- <<"gopi & 1">>] which would throw a bad_generator error. In order to make use of this map function, all of the values would need to be Erlang lists.

Joe
  • 25,000
  • 3
  • 22
  • 44
  • I have written a reduce function that takes list from the map phase,like fun(Litst,_) -> ....end. it will only give list.so how can i assign the right side value to it like {ok,[0,R]} or just ill get only list so i can give as [R] = riakc_pb_socket:mapred(etc etc... – Krish gopi May 21 '14 at 13:31
  • both the map and reduce functions return a list. `riak_pb_socket:mapred` retuns a tuple of `ok` and a list of phases for which `Keep` was true, each phase is a tuple of the phase index (0-based) and the result list. `{ok, [{0,R}]} = riakc_pb_socket:mapred( ...` should get you the result in `R` if you only set Keep to true for a single phase. – Joe May 21 '14 at 15:05