2
我試圖使用地圖降低了Riak做到這一點:了Riak地圖降低二郎,錯誤時嘗試列出索引/元
- 查詢過在桶中的所有鍵X
- 帶索引「last_modify_int '1和10
- 之間映射關鍵字和索引的tag_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) }].
我儲存在桶的培訓,關鍵巴茲,數據和索引last_modify_int => 3,tag_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.
如果我試試這個功能:
get_keys(Value,_Keydata,_Arg) ->
[{riak_object:bucket(Value), riak_object:get_metadata(Value) }].
的錯誤是:
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}]}]'
有人能幫助我嗎?
編輯:
完成此項工作:
-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} ].
我可以返回所有索引,但在某些情況下,我有一個以上的值,這樣就只返回最後一個索引值的一個指標。幫幫我。