与Riak Mapreduce [英] Mapreduce with Riak

查看:128
本文介绍了与Riak Mapreduce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有可以在单个Riak节点上运行的Riak mapreduce的示例代码。

解决方案

  cd〜/ riak 
erl -name zed@127.0.0.1 -setcookie riak -pa apps / riak / ebin

在shell中:

 #连接到服务器
> {ok,Client} = riak:client_connect('riak@127.0.0.1')。
{ok,{riak_client,'riak @ 127.0.0.1',< 6,201,208,64>}}

#创建并插入对象
>客户:put(riak_object:new(<groceries>><mine>> [eggs,bacons]),1)。
ok
>客户:put(riak_object:new(<groceries>><yours>> [eggs,sausage]))1)。
ok

#创建Map和Reduce函数
> Count = fun(G,'undefined','none') - >
[dict:from_list([{I,1} || I< - riak_object:get_value(G)])]
end。
#Fun< erl_eval.18.105910772>
> Merge = fun(Gcounts,'none') - >
[列表:foldl(fun(G,Acc))>
dict:merge(fun(_,X,Y) - > X + Y end,G,Acc)
end,dict:new(),Gcounts)]
end。
#Fun< erl_eval.12.113037538>

#做map-reduce
> {ok,[R]} = Client:mapred([{<groceries>><mine>>},
{< >>>>>}],
[{'map',{'qfun',Count},'none',false},
{ 'reduce',{'qfun',Merge},'none',true}])。
{ok,[{dict,...

>字典:to_list(R)。
[{鸡蛋,2},{susages,1},{bacons,1}]

对于服务器我绝对使用默认配置:

  $ hg clone http:// hg。 basho.com/riak/ 
$ cd riak
$ ./rebar compile generate
$ cd rel
$ ./riak/bin/riak start


Does anyone have example code for mapreduce for Riak that can be run on a single Riak node.

解决方案

cd ~/riak
erl -name zed@127.0.0.1 -setcookie riak -pa apps/riak/ebin

In the shell:

# connect to the server
> {ok, Client} = riak:client_connect('riak@127.0.0.1').
{ok,{riak_client,'riak@127.0.0.1',<<6,201,208,64>>}}

# create and insert objects
> Client:put(riak_object:new(<<"groceries">>, <<"mine">>, ["eggs", "bacons"]), 1).
ok
> Client:put(riak_object:new(<<"groceries">>, <<"yours">>, ["eggs", "sausages"]), 1).
ok

# create Map and Reduce functions
> Count = fun(G, 'undefined', 'none') ->
            [dict:from_list([{I, 1} || I <- riak_object:get_value(G)])]
          end.
#Fun<erl_eval.18.105910772>
> Merge = fun(Gcounts, 'none') ->
            [lists:foldl(fun(G, Acc) ->
                           dict:merge(fun(_, X, Y) -> X+Y end, G, Acc)
                         end, dict:new(), Gcounts)] 
          end.
#Fun<erl_eval.12.113037538>

# do the map-reduce
> {ok, [R]} = Client:mapred([{<<"groceries">>, <<"mine">>},
                             {<<"groceries">>, <<"yours">>}],
                            [{'map', {'qfun', Count}, 'none', false},
                             {'reduce', {'qfun', Merge}, 'none', true}]).           
{ok,[{dict,...

> dict:to_list(R).
[{"eggs",2},{"susages",1},{"bacons",1}]

For the server I used absolutely default config:

$ hg clone http://hg.basho.com/riak/
$ cd riak
$ ./rebar compile generate
$ cd rel
$ ./riak/bin/riak start

这篇关于与Riak Mapreduce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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