Skip to content

Commit 82ae32b

Browse files
author
Luke Bakken
committed
Add information about using bucket types in input lists and test for such.
1 parent f3e6401 commit 82ae32b

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,14 @@ It is possible to define a wide range of inputs for a mapreduce job. Some exampl
542542

543543
**Bucket/Key list:** `[{<<"bucket1">>,<<"key1">>},{<<"bucket1">>,<<"key2">>}]`
544544

545+
**Bucket Type/Bucket/Key list:** `[{{{<<"type1">>,<<"bucket1">>},<<"key1">>},key_data1},{{{<<"type1">>,<<"bucket1">>},<<"key2">>},key_data2}]`
546+
547+
*Note*: due to [a bug](https://github.com/basho/riak_kv/issues/1623), you must include "key data" in the above input list to be able to include bucket type.
548+
545549
**All keys in a bucket:** `<<"bucket1">>`
546550

551+
**All keys in a typed bucket:** `{<<"type1">>,<<"bucket1">>}`
552+
547553
**Result of exact secondary index match:** `{index, <<"bucket1">>, {binary_index, "idx"}, <<"key">>}`, `{index, <<"bucket1">>, <<"idx_bin">>, <<"key">>}`
548554

549555
**Result of secondary index range query:** `{index, <<"bucket1">>, {integer_index, "idx"}, 1, 100}`, `{index, <<"bucket1">>, <<"idx_int">>, <<"1">>, <<"100">>}`

test/riakc_pb_socket_tests.erl

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,40 @@ integration_tests() ->
425425
{ok, Pid} = riakc_test_utils:start_link(),
426426
B = <<"bucket">>,
427427
K = <<"foo">>,
428-
O=riakc_obj:new(B, K),
428+
O = riakc_obj:new(B, K),
429429
riakc_pb_socket:put(Pid, riakc_obj:update_value(O, <<"2">>, "application/json")),
430+
Inputs = [{B, K}],
431+
Args = [{map, {jsanon, <<"function (v) { return [JSON.parse(v.values[0].data)]; }">>}, undefined, true}],
432+
Want = {ok, [{0, [2]}]},
433+
Got = riakc_pb_socket:mapred(Pid, Inputs, Args),
434+
?assertMatch(Want, Got)
435+
end)},
430436

431-
?assertEqual({ok, [{0, [2]}]},
432-
riakc_pb_socket:mapred(Pid,
433-
[{B, K}],
434-
[{map, {jsanon, <<"function (v) { return [JSON.parse(v.values[0].data)]; }">>},
435-
undefined, true}]))
437+
{"javascript_source_map_with_bucket_type_test()",
438+
?_test(begin
439+
riakc_test_utils:reset_riak(),
440+
{ok, Pid} = riakc_test_utils:start_link(),
441+
BT = <<"plain">>,
442+
B = <<"my_bucket">>,
443+
BWT = {BT, B}, % NB: Bucket With Type
444+
K = <<"baz">>,
445+
Value = <<"bat">>,
446+
O = riakc_obj:new(BWT, K),
447+
O2 = riakc_obj:update_value(O, Value, "application/json"),
448+
?assertMatch(BT, riakc_obj:bucket_type(O2)),
449+
?assertMatch(BWT, riakc_obj:bucket(O2)),
450+
?assertMatch(K, riakc_obj:key(O2)),
451+
?assertMatch(ok, riakc_pb_socket:put(Pid, O2)),
452+
{ok, GotObj} = riakc_pb_socket:get(Pid, BWT, K),
453+
?assertMatch(BT, riakc_obj:bucket_type(GotObj)),
454+
?assertMatch(BWT, riakc_obj:bucket(GotObj)),
455+
?assertMatch(K, riakc_obj:key(GotObj)),
456+
% NB: see basho/riak_kv#1623
457+
Inputs = [{{BWT, K}, ignored},{{BWT, K}, ignored}],
458+
Args = [{map, {jsanon, <<"function (v) { return [v.values[0].data]; }">>}, undefined, true}],
459+
Want = {ok, [{0, [Value, Value]}]},
460+
Got = riakc_pb_socket:mapred(Pid, Inputs, Args),
461+
?assertMatch(Want, Got)
436462
end)},
437463

438464
{"javascript_named_map_test()",
@@ -520,6 +546,25 @@ integration_tests() ->
520546
{reduce, {jsfun, <<"Riak.reduceSum">>}, undefined, true}]))
521547
end)},
522548

549+
{"javascript_bucket_type_map_reduce_test()",
550+
?_test(begin
551+
riakc_test_utils:reset_riak(),
552+
{ok, Pid} = riakc_test_utils:start_link(),
553+
BT = {<<"plain">>,<<"bucket">>},
554+
Store = fun({K, V}) ->
555+
O=riakc_obj:new(BT, K),
556+
riakc_pb_socket:put(Pid,riakc_obj:update_value(O, V, "application/json"))
557+
end,
558+
[Store(KV) || KV <- [{<<"foo">>, <<"2">>},
559+
{<<"bar">>, <<"3">>},
560+
{<<"baz">>, <<"4">>}]],
561+
Want = {ok, [{1, [9]}]},
562+
Query = [{map, {jsfun, <<"Riak.mapValuesJson">>}, undefined, false},
563+
{reduce, {jsfun, <<"Riak.reduceSum">>}, undefined, true}],
564+
Got = riakc_pb_socket:mapred_bucket(Pid, BT, Query),
565+
?assertMatch(Want, Got)
566+
end)},
567+
523568
{"javascript_arg_map_reduce_test()",
524569
?_test(begin
525570
riakc_test_utils:reset_riak(),

0 commit comments

Comments
 (0)