如何执行具有多个地图功能的 riak mapred 查询

发布于 2024-12-12 07:25:39 字数 1536 浏览 0 评论 0原文

我想在 erlang 中执行一个包含两个映射阶段的 MapReduce 查询,以便 Map2 函数将 Map1 函数的结果作为输入。是否可能,如果,每个映射阶段的返回值必须是什么

  • 有关更多详细信息:

我使用两个简单的映射函数运行了一个测试mapred查询,每个函数都返回输入对象(在列表中)。但是通过运行查询,我收到了错误匹配错误

Map1 = fun(O,_,_) -> [O] end.
Map2 = fun(O, _,_) -> [O] end.


C:mapred_bucket(<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>, [{map, {qfun, Map1}, none, false}, {map, {qfun, Map2}, none, true}]).

{{badmatch,{r_object,<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>,
                     <<255,230,193,167,254,7,246,64,154,190,36,236,32,232,189,
                       169,161,124,23,86>>,
                     [{r_content,{dict,2,16,16,8,80,48,
                                       {[],[],[],[],[],[],[],[],[],[],[],...},
                                       {{[],[],[],[],[],[],[],[],[],...}}},
                                 <<"12d33872-4c92-4da5-9d16-5036a8059253">>}],
                     [{<<5,215,86,61>>,{1,63487018636}}],
                     {dict,1,16,16,8,80,48,
                           {[],[],[],[],[],[],[],[],[],[],[],[],...},
                           {{[],[],[],[],[],[],[],[],[],[],...}}},
                     undefined}},
 [{riak_kv_map_phase,build_input,2},
  {riak_kv_map_phase,'-handle_input/3-lc$^0/1-0-',2},
  {riak_kv_map_phase,handle_input,3},
  {luke_phase,executing,2},
  {gen_fsm,handle_msg,7},
  {proc_lib,init_p_do_apply,3}]}

,我正在使用 riak_search-0.14.2

Erlang R14B03 (erts-5.8.4)

谢谢!

I want to execute a mapreduce query, in erlang, that contains two map phases such that the Map2 function takes the result of the Map1 function as input. Is it possible and if, what must be the return value of each map phase

  • For more details:

I have run a test mapred query using two simple map functions, each one returns the input object (in a list). but by runnin the query I get a badmatch error

Map1 = fun(O,_,_) -> [O] end.
Map2 = fun(O, _,_) -> [O] end.


C:mapred_bucket(<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>, [{map, {qfun, Map1}, none, false}, {map, {qfun, Map2}, none, true}]).

{{badmatch,{r_object,<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>,
                     <<255,230,193,167,254,7,246,64,154,190,36,236,32,232,189,
                       169,161,124,23,86>>,
                     [{r_content,{dict,2,16,16,8,80,48,
                                       {[],[],[],[],[],[],[],[],[],[],[],...},
                                       {{[],[],[],[],[],[],[],[],[],...}}},
                                 <<"12d33872-4c92-4da5-9d16-5036a8059253">>}],
                     [{<<5,215,86,61>>,{1,63487018636}}],
                     {dict,1,16,16,8,80,48,
                           {[],[],[],[],[],[],[],[],[],[],[],[],...},
                           {{[],[],[],[],[],[],[],[],[],[],...}}},
                     undefined}},
 [{riak_kv_map_phase,build_input,2},
  {riak_kv_map_phase,'-handle_input/3-lc$^0/1-0-',2},
  {riak_kv_map_phase,handle_input,3},
  {luke_phase,executing,2},
  {gen_fsm,handle_msg,7},
  {proc_lib,init_p_do_apply,3}]}

I'm using riak_search-0.14.2

Erlang R14B03 (erts-5.8.4)

thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拒绝两难 2024-12-19 07:25:39

我不确定 Erlang 中 Map 方法的签名是什么,因为我只在 Javascript 中完成过 map/reduce,但我会尽力提供帮助。

为了链接映射阶段,只有最后一个映射函数需要返回 Riak 中的对象列表。上面的每个其他映射函数都需要返回一个包含存储桶名称和传入值的键的元组。

在 Javascript 中,我已经完成了这一点,如下所示:

function map_function(value, keydata, arg) {
    //filtering stuff here
    if(arg.last) {
      data["key"] = value.key;
      return [data];
    }
    else {
      return [[value.bucket, value.key]];
    }
    //this is in the case the filter returns true; if the filter returns false, return an empty tuple
  }

希望这会有所帮助。

I'm not sure what the signature of the Map method is in Erlang, as I've only done map/reduce in Javascript, but I'll try to help.

In order to chain the map phases, only the last map function needs to return a list of objects in Riak. Every other map function above it needs to return a tuple containing the bucket name and the key of the value passed in.

In Javascript, I've accomplished this like so:

function map_function(value, keydata, arg) {
    //filtering stuff here
    if(arg.last) {
      data["key"] = value.key;
      return [data];
    }
    else {
      return [[value.bucket, value.key]];
    }
    //this is in the case the filter returns true; if the filter returns false, return an empty tuple
  }

Hope this helps.

你的往事 2024-12-19 07:25:39

您必须从第一个映射函数返回 {Bucket, Key} 或 {{Bucket, Key}, KeyData}。
像这样:

Map1 = fun(O,_,_) -> [{riak_object:bucket(O), riak_object:key(O)}] end.
Map2 = fun(O, _,_) -> [O] end.


C:mapred_bucket(<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>, [{map, {qfun, Map1}, none, false}, {map, {qfun, Map2}, none, true}]).

You have to return {Bucket, Key} or {{Bucket, Key}, KeyData} from first map function.
Like this:

Map1 = fun(O,_,_) -> [{riak_object:bucket(O), riak_object:key(O)}] end.
Map2 = fun(O, _,_) -> [O] end.


C:mapred_bucket(<<"b7bc1418-198d-44a3-8835-8aa9cb416d5b">>, [{map, {qfun, Map1}, none, false}, {map, {qfun, Map2}, none, true}]).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文