Mapreduce erlang中的Riak映射缩减,尝试列出索引/元数据时出错

Mapreduce erlang中的Riak映射缩减,尝试列出索引/元数据时出错,mapreduce,erlang,riak,Mapreduce,Erlang,Riak,我正在尝试使用Riak中的map reduce来执行以下操作: 查询bucket X中的所有键 索引“last_modify_int”介于1和10之间 映射索引标记_bin的键和值 在javascript中,映射将 function(riakObject) { var indexes = riakObject.values[0].metadata.index; var tag_bin = indexes.tag_bin; return

我正在尝试使用Riak中的map reduce来执行以下操作:

  • 查询bucket X中的所有键
  • 索引“last_modify_int”介于1和10之间
  • 映射索引标记_bin的键和值
  • 在javascript中,映射将

    function(riakObject) {
              var indexes = riakObject.values[0].metadata.index;
              var tag_bin = indexes.tag_bin;
    
              return (tag_bin)? [
                [
                  riakObject.key, tag_bin
                ]
              ] : [];
            }
    
    但我不能用javascript来实现这一点。我正在存储非json数据(二进制),无法转换为json。我无法转换为base64或其他格式

    我决定使用Erlang。但是我如何获取索引“tag_bin”

    我试图修改这个示例,只是为了列出所有索引/元数据/等等,但没有成功

    -module(mr_example).
    
    -export([get_keys/3]).
    
    % Returns bucket and key pairs from a map phase
    get_keys(Value,_Keydata,_Arg) ->
      [{riak_object:bucket(Value), riak_object:index_data(Value) }].
    
    我将数据存储在bucket training、key baz和索引last\u modify\u int=>3、tag\u bin=>“偶数”中

    但它引发了一个例外:

    Error in 'map_reduce' : Riak Error (code: 0) '{"phase":0,"error":"undef","input":"{ok,{r_object,<<\"training\">>,<<\"baz\">>,[{r_content,{dict,4,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[],[],[],[],[],[],[],[],[[<<\"content-type\">>,112,108,97,105,110,47,116,101,120,116],[<<\"X-Riak-VTag\">>,53,100,98,54,69,79,103,103,70,75,70,48,85,105,50,110,73,78,57,101,101,69]],[[<<\"index\">>,{<<\"last_modify_int\">>,3},{<<\"tag_bin\">>,<<\"even\">>}]],[],[[<<\"X-Riak-Last-Modified\">>|{1386,780017,102696}]],[],[]}}},<<86,48,45,61,115,114,108,1,0,40,43,1,40,43,8,32,206,...>>}],...},...}","type":"error","stack":"[{riak_object,index_data,[{r_object,<<\"training\">>,<<\"baz\">>,[{r_content,{dict,4,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[],[],[],[],[],[],[],[],[[<<\"content-type\">>,112,108,97,105,110,47,116,101,120,116],[<<\"X-Riak-VTag\">>,53,100,98,54,69,79,103,103,70,75,70,48,85,105,50,110,73,78,57,101,101,69]],[[<<\"index\">>,{<<\"last_modify_int\">>,3},{<<\"tag_bin\">>,<<\"even\">>}]],[],[[<<\"X-Riak-Last-Modified\">>|{1386,780017,102696}]],[],[]}}},<<86,48,45,61,115,114,108,1,...>>}],...}],...},...]"}' at t/17_2i_map_reduce.t line 72.
    
    错误是:

    Error in 'map_reduce' : Riak Error (code: 0) 'Error processing stream message: exit:{json_encode,
                                           {bad_term,
                                            {dict,4,16,16,8,80,48,
                                             {[],[],[],[],[],[],[],[],[],[],[],[],
                                              [],[],[],[]},
                                             {{[],[],[],[],[],[],[],[],[],[],
                                               [[<<"content-type">>,112,108,97,
                                                 105,110,47,116,101,120,116],
                                                [<<"X-Riak-VTag">>,50,103,117,98,
                                                 121,107,119,109,102,117,120,73,
                                                 100,108,74,101,86,108,122,75,55,
                                                 70]],
                                               [[<<"index">>,
                                                 {<<"last_modify_int">>,3},
                                                 {<<"tag_bin">>,<<"even">>}]],
                                               [],
                                               [[<<"X-Riak-Last-Modified">>|
                                                 {1386,780159,925964}]],
                                               [],[]}}}}}:[{mochijson2,
                                                            json_encode,2,
                                                            [{file,
                                                              "src/mochijson2.erl"},
                                                             {line,149}]},
                                                           {mochijson2,
                                                            '-json_encode_proplist/2-fun-0-',
                                                            3,
                                                            [{file,
                                                              "src/mochijson2.erl"},
                                                             {line,167}]},
                                                           {lists,foldl,3,
                                                            [{file,"lists.erl"},
                                                             {line,1197}]},
                                                           {mochijson2,
                                                            json_encode_proplist,
                                                            2,
                                                            [{file,
                                                              "src/mochijson2.erl"},
                                                             {line,170}]},
                                                           {riak_kv_pb_mapred,
                                                            msgs_for_results,4,
                                                            [{file,
                                                              "src/riak_kv_pb_mapred.erl"},
                                                             {line,205}]},
                                                           {riak_kv_pb_mapred,
                                                            process_stream,3,
                                                            [{file,
                                                              "src/riak_kv_pb_mapred.erl"},
                                                             {line,89}]},
                                                           {riak_api_pb_server,
                                                            process_stream,5,
                                                            [{file,
                                                              "src/riak_api_pb_server.erl"},
                                                             {line,246}]},
                                                           {riak_api_pb_server,
                                                            handle_info,2,
                                                            [{file,
                                                              "src/riak_api_pb_server.erl"},
                                                             {line,129}]}]'
    
    'map_reduce'中的
    错误:Riak错误(代码:0)'处理流消息时出错:退出:{json_encode,
    {坏词,
    {dict,4,16,16,8,80,48,
    {[],[],[],[],[],[],[],[],[],[],[],[],
    [],[],[],[]},
    {{[],[],[],[],[],[],[],[],[],[],
    [[,112,108,97,
    105,110,47,116,101,120,116],
    [,50,103,117,98,
    121,107,119,109,102,117,120,73,
    100,108,74,101,86,108,122,75,55,
    70]],
    [[,
    {,3},
    {,}]],
    [],
    [[|
    {1386,780159,925964}]],
    [],[]}:[{mochijson2,
    json_编码,2,
    [{文件,
    “src/mochijson2.erl”},
    {line,149}]},
    {mochijson 2,
    '-json_encode_proplist/2-fun-0-',
    3.
    [{文件,
    “src/mochijson2.erl”},
    {line,167}]},
    {列表,foldl,3,
    [{file,“lists.erl”},
    {line,1197}]},
    {mochijson 2,
    json_encode_proplist,
    2.
    [{文件,
    “src/mochijson2.erl”},
    {line,170}]},
    {riak_kv_pb_mapred,
    msgs_用于_结果,4,
    [{文件,
    “src/riak_kv_pb_mapred.erl”,
    {line,205}]},
    {riak_kv_pb_mapred,
    工艺流程,3,
    [{文件,
    “src/riak_kv_pb_mapred.erl”,
    {line,89}]},
    {riak_api_pb_服务器,
    工艺流程,5,
    [{文件,
    “src/riak_api_pb_server.erl”},
    {line,246}]},
    {riak_api_pb_服务器,
    处理信息,2,
    [{文件,
    “src/riak_api_pb_server.erl”},
    {line,129}]}]'
    
    有人能帮我吗

    编辑:

    这样做:

    -module(mr_example).
    
    -export([get_keys/3]).
    
    % Returns bucket and key pairs from a map phase
    get_keys(Value,_Keydata,_Arg) ->
      Meta  = riak_object:get_metadata(Value),
      Index = dict:fetch(<<"index">>, Meta),
      [{riak_object:key(Value), Index} ].
    
    -模块(mr_示例)。
    -导出([获取密钥/3])。
    %从映射阶段返回bucket和key对
    获取密钥(值、\u密钥数据、\u参数)->
    Meta=riak_对象:获取_元数据(值),
    索引=dict:fetch(,Meta),
    [{riak_object:key(Value),Index}]。
    

    我可以返回所有索引,但在某些情况下,我有一个索引具有多个值,这样它只返回最后一个索引值。帮助。

    好的,我发现了问题

    Index是一个元组数组,我使用keyfind返回tag_bin的索引值,它返回最后一个元素

    -module(mr_example).
    
    -export([get_keys/3]).
    
    % Returns bucket and key pairs from a map phase
    get_keys(Value,_Keydata,_Arg) ->
      Meta  = riak_object:get_metadata(Value),
      Index = dict:fetch(<<"index">>, Meta),
      [{riak_object:key(Value), Index} ].