erlang pb 客户端中的键过滤器问题
更新2 我找到了解决方案(感谢 rvirding)。我必须像这样放置对象
Object = riakc_obj:new(list_to_binary(Bucket),
list_to_binary(Time),
list_to_binary(TimeValue)),
ok = riakc_pb_socket:put(Db_pid, Object);
并发出这样的请求
Query = [{map, %query type
{modfun, riak_kv_mapreduce, map_object_value}, %function from riak erlang built-in module
none, true}],
Inputs = {Bucket, [[<<"between">>, <<"0">>, <<"0.05">>]]},
Result = riakc_pb_socket:mapred(Pid, Inputs, Query),
我认为应该在文档中提及。
顺便提一句!如果我写的话
Object = riakc_obj:new(<<Bucket>>,
<<Time>>,
<<TimeValue>>),
我会得到关于 badarg 的错误。仍然对此感到困惑。(
更新
如果我写这个
Inputs = {Bucket, [[<<"between">>, 0, 1]]}
我没有错误,我什至得到“ok”结果,但它是空的,这不是预期的行为。)
======= =================================================== ======
我完全失去了理智,但我必须完成它。
我有一个简单的应用程序:它从 txt 文件中提取数据(例如“时间戳值”之类的数据),将其推送到 Riak 并进行一些范围查询。 问题是当我进行关键过滤器查询时,我收到 {error,disconnected}。 我以这种方式在riak中存储数据:key – 时间戳(如0.43),value – 值(如1.14),bucket – 添加数据的时间(如“2011-07-24-23-39-45”)。 这是请求的代码:
(dca_db.erl)
handle_call({range_query, Bucket, From, To}, _, #state{db_pid = Pid} = State) ->
Query = [{map, %query type
{modfun, riak_kv_mapreduce, map_object_value}, %function from riak erlang built-in module
none, true}],
Inputs = {Bucket, [["between", 0, 1]]},
Result = riakc_pb_socket:mapred(Pid, Inputs, Query),
{reply, Result, State};
(test/dca_db_tests.erl)
range_request(Pid) ->
Bucket = <<"2011-07-24-23-39-45">>,
Result = gen_server:call(Pid, {range_query, Bucket, 0, 1}),
error_logger:info_msg("RESULT:~p~n",[Result]).
您可以在 github 中找到我的代码 – https ://github.com/DimitryDushkin/distributed_calc_riak_matlab
如果我使用类似的东西(在dca_db.erl)
Inputs = {Bucket, [["eq", 1]]},
我有另一个错误
Compiled src/dca_db.erl
undefined
*unexpected termination of test process*
::{{badmatch,{<<"2011-07-24-23-39-45">>,[["eq",1]]}},
[{dca_db,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}
=ERROR REPORT==== 25-Jul-2011::00:27:24 ===
** Generic server dca_db terminating
** Last message in was {range_query,<<"2011-07-24-23-39-45">>,0,1}
** When Server state == {state,<0.105.0>}
** Reason for termination ==
** {{badmatch,{<<"2011-07-24-23-39-45">>,[["eq",1]]}},
[{dca_db,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}
=======================================================
Failed: 0. Skipped: 0. Passed: 1.
One or more tests were cancelled.
Cover analysis: /Users/ddushkin/Documents/workspaces/eclipse/distributed_calc_riak_matlab/.eunit/index.html
ERROR: One or more eunit tests failed.
make: *** [test_db] Error 1
,如果我不使用过滤器,一切正常:
Inputs = Bucket,
谢谢。
UPDATE2
I found the solution (thx to rvirding). I have to put object like this
Object = riakc_obj:new(list_to_binary(Bucket),
list_to_binary(Time),
list_to_binary(TimeValue)),
ok = riakc_pb_socket:put(Db_pid, Object);
And make the request like this
Query = [{map, %query type
{modfun, riak_kv_mapreduce, map_object_value}, %function from riak erlang built-in module
none, true}],
Inputs = {Bucket, [[<<"between">>, <<"0">>, <<"0.05">>]]},
Result = riakc_pb_socket:mapred(Pid, Inputs, Query),
I think It should be mentioned in docs.
BTW! If I wrote
Object = riakc_obj:new(<<Bucket>>,
<<Time>>,
<<TimeValue>>),
I got en error about badarg. Still confused about this.(
UPDATE
If I write this
Inputs = {Bucket, [[<<"between">>, 0, 1]]}
I got no error, I even got "ok" result, but it is empty, which is not expected behavior.)
===============================================================
I totally lost my mind with this, but I have to finish it.
I have simple app: it extracts data from txt file (data like "timestamp value"), push it to Riak and make some range queries.
The problem is when I make key filter query I get {error,disconnected}.
I strore data in riak in this way: key – timestamp (like 0.43), value – value (like 1.14), bucket – time of adding data (like "2011-07-24-23-39-45").
Here's the code of request:
(dca_db.erl)
handle_call({range_query, Bucket, From, To}, _, #state{db_pid = Pid} = State) ->
Query = [{map, %query type
{modfun, riak_kv_mapreduce, map_object_value}, %function from riak erlang built-in module
none, true}],
Inputs = {Bucket, [["between", 0, 1]]},
Result = riakc_pb_socket:mapred(Pid, Inputs, Query),
{reply, Result, State};
(test/dca_db_tests.erl)
range_request(Pid) ->
Bucket = <<"2011-07-24-23-39-45">>,
Result = gen_server:call(Pid, {range_query, Bucket, 0, 1}),
error_logger:info_msg("RESULT:~p~n",[Result]).
You can find my code in github – https://github.com/DimitryDushkin/distributed_calc_riak_matlab
If I use something like (in dca_db.erl)
Inputs = {Bucket, [["eq", 1]]},
I have another error
Compiled src/dca_db.erl
undefined
*unexpected termination of test process*
::{{badmatch,{<<"2011-07-24-23-39-45">>,[["eq",1]]}},
[{dca_db,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}
=ERROR REPORT==== 25-Jul-2011::00:27:24 ===
** Generic server dca_db terminating
** Last message in was {range_query,<<"2011-07-24-23-39-45">>,0,1}
** When Server state == {state,<0.105.0>}
** Reason for termination ==
** {{badmatch,{<<"2011-07-24-23-39-45">>,[["eq",1]]}},
[{dca_db,handle_call,3},
{gen_server,handle_msg,5},
{proc_lib,init_p_do_apply,3}]}
=======================================================
Failed: 0. Skipped: 0. Passed: 1.
One or more tests were cancelled.
Cover analysis: /Users/ddushkin/Documents/workspaces/eclipse/distributed_calc_riak_matlab/.eunit/index.html
ERROR: One or more eunit tests failed.
make: *** [test_db] Error 1
And everything works if I do not use filters:
Inputs = Bucket,
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
riak 的存储桶和密钥应该是二进制文件,这就是为什么你不会收到错误。您没有找到任何东西意味着存储桶/钥匙是错误的。当数据添加到数据库时它们是如何创建的?确保您以完全相同的方式进行操作!在我使用过的一个应用程序中,他们对值做了
term_to_binary(Key)
,但它可以以您选择的任何方式完成。The bucket and keys to riak should be binaries, that is why you get no error. That you are not finding anything means that the bucket/keys are wrong. How were they created when data was added to the DB? Make sure you do it exactly the same way! In an app I have worked with they did
term_to_binary(Key)
for the value but it can be done in any way you choose.