Erlang MapReduce在Riak数据库中提供异常 [英] Erlang MapReduce on Riak database giving exception

查看:182
本文介绍了Erlang MapReduce在Riak数据库中提供异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览riak和Erlang的教程,我已经用riak-erlang-client存储了riak中的数据,我做了以下操作:

  1> {ok,Pid} = riakc_pb_socket:start_link(127.0.0.1,8087)。 
{ok,< 0.34.0>}
2> Val1 = [1,2,3]。
[1,2,3]
3> MyBucket =<number>> ;.
<numbers>>
4> Obj1 = riakc_obj:new(MyBucket,<ott>>,Val1)。
5> riakc_pb_socket:把(PID,OBJ1)。
ok
6> {ok,Fetched} = riakc_pb_socket:get(Pid,MyBucket,<ott>>)。
{ok,{riakc_obj,<numbers>,<ott>>><< 107& 96,204,96,202,5,82,28,202,156,255,126,
6,251,159,184,148,193,148,...>>
[{{dict,3,16,16,8,80,48,
{ [],[],[],[],[],[],[],[],[],[],[],[],...},
{{[ [],[],[],[],[],[],[],[],[],...}}},
<< 131,107,0,3,1, 2,3>}],
undefined,undefined}}
7> Val1 == binary_to_term(riakc_obj:get_value(Fetched)))。
true
8> binary_to_term(riakc_obj:的get_value(读出))。
[1,2,3]

现在一切都好,我想提取



因为我已经完成了以下操作,列表[1,2,3]中的值只能通过erlang从mapreduce中除以2。

  9> Res = fun(Fetched,none) - > [X || X<  -  binary_to_term(riakc_obj:get_value(Fetched)),X rem 2 == 0] end。 

我不知道应该在函数参数中写什么,因为我是erlang的新手和/或者riak,所以请纠正我错了。



现在,当我去mapreduce我写这个,

  10> {ok,[{X}]} = riakc_pb_socket:mapred(Pid,[{<"numbers>,<ott >>}],[{地图,{qfun,RES},无,真}])。 

它正在抛出以下异常。我建议我一个很好的方式来了解发生了什么,以及如何运行mapreduce。

  **异常退出:{noproc,{gen_server,call,
[<0.34。 0>
{req,{rpbmapredreq,<< 131,108,0,0,0,3,104,2,100,0,6,105,
110,112,117,116,115,108,...>>>
$,
$ 60,
{132578423,<0.49.0}},
无限]}}函数gen_server中的
:call / 3(gen_server.erl,第188行)
来自riakc_pb_socket的调用:mapred / 5(src / riakc_pb_socket.erl,行643)

请帮助我,建议我,我喜欢follo wed的链接,但我不清楚如何写我自己的mapreduce所以请指导我...将帮助我。

解决方案

您正在获得noproc错误,因为您传递了一个arity-2功能。地图相位函数应为arity-3。另外,在函数头中指定 none 将导致该子句仅在相应参数显式匹配时执行,使用 _ 代替你不关心的论据,例如:

  Res = fun(Fetched,_,_) - > ; [X || X<  -  binary_to_term(riakc_obj:get_value(Fetched)),X rem 2 == 0] end。 


I am going through the tutorials of riak and Erlang, I have stored data in riak by the riak-erlang-client and i did the following:

1> {ok,Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087).
{ok,<0.34.0>} 
2> Val1 = [1,2,3]. 
[1,2,3]
3> MyBucket = <<"numbers">>.
<<"numbers">>
4> Obj1 = riakc_obj:new(MyBucket,<<"ott">>,Val1).
5> riakc_pb_socket:put(Pid,Obj1).
ok
6> {ok, Fetched} = riakc_pb_socket:get(Pid,MyBucket,<<"ott">>).
{ok,{riakc_obj,<<"numbers">>,<<"ott">>,
           <<107,206,97,96,96,96,204,96,202,5,82,28,202,156,255,126,
             6,251,159,184,148,193,148,...>>,
           [{{dict,3,16,16,8,80,48,
                   {[],[],[],[],[],[],[],[],[],[],[],[],...},
                   {{[],[],[],[],[],[],[],[],[],[],...}}},
             <<131,107,0,3,1,2,3>>}],
           undefined,undefined}}
7> Val1 == binary_to_term(riakc_obj:get_value(Fetched)).
true
8> binary_to_term(riakc_obj:get_value(Fetched)).        
[1,2,3]

Now everything was fine , i want to extract the values from the list [1,2,3] that where only divisible by 2 from a mapreduce through erlang.

for that i have done the following,

9>Res = fun(Fetched,none)-> [X || X <- binary_to_term(riakc_obj:get_value(Fetched)), X rem 2 == 0] end.

I don't know exactly about what should write in the function parameters,as i am new to erlang and riak, so please correct me if am wrong.

Now when i going for mapreduce i have written this,

10>{ok , [{X}]} = riakc_pb_socket:mapred(Pid,[{<<"numbers">>,<<"ott">>}],[{map,{qfun,Res},none,true}]).

It was throwing the below exception..please suggest me a good way to understand what's going on and how to run mapreduce.

** exception exit: {noproc,{gen_server,call,
                                   [<0.34.0>,
                                    {req,{rpbmapredreq,<<131,108,0,0,0,3,104,2,100,0,6,105,
                                                         110,112,117,116,115,108,...>>,
                                                       <<"application/x-erlang-binary">>},
                                         60100,
                                         {132578423,<0.49.0>}},
                                    infinity]}}
 in function  gen_server:call/3 (gen_server.erl, line 188)
 in call from riakc_pb_socket:mapred/5 (src/riakc_pb_socket.erl, line 643)

Please,help me and suggest me, i hjave followed the links but i am not getting clearly that how to write on my own for a mapreduce so please guide me..it will help me.

解决方案

You are getting the noproc error because you are passing an arity-2 function. The map phase function should be arity-3. Also, specifying none in the function header will cause that clause to only be executed when the corresponding argument explicitly matches, use _ in place of arguments you don't care about, like:

Res = fun(Fetched,_,_)-> [X || X <- binary_to_term(riakc_obj:get_value(Fetched)), X rem 2 == 0] end.

这篇关于Erlang MapReduce在Riak数据库中提供异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆