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 canc开发者_JAVA百科elled.
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.
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.
精彩评论