diff --git a/README.md b/README.md index 84da1713..182f3c9b 100644 --- a/README.md +++ b/README.md @@ -542,8 +542,14 @@ It is possible to define a wide range of inputs for a mapreduce job. Some exampl **Bucket/Key list:** `[{<<"bucket1">>,<<"key1">>},{<<"bucket1">>,<<"key2">>}]` +**Bucket Type/Bucket/Key list:** `[{{{<<"type1">>,<<"bucket1">>},<<"key1">>},key_data1},{{{<<"type1">>,<<"bucket1">>},<<"key2">>},key_data2}]` + +*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. + **All keys in a bucket:** `<<"bucket1">>` +**All keys in a typed bucket:** `{<<"type1">>,<<"bucket1">>}` + **Result of exact secondary index match:** `{index, <<"bucket1">>, {binary_index, "idx"}, <<"key">>}`, `{index, <<"bucket1">>, <<"idx_bin">>, <<"key">>}` **Result of secondary index range query:** `{index, <<"bucket1">>, {integer_index, "idx"}, 1, 100}`, `{index, <<"bucket1">>, <<"idx_int">>, <<"1">>, <<"100">>}` diff --git a/test/riakc_pb_socket_tests.erl b/test/riakc_pb_socket_tests.erl index d7ea3b76..7debc8df 100644 --- a/test/riakc_pb_socket_tests.erl +++ b/test/riakc_pb_socket_tests.erl @@ -425,14 +425,40 @@ integration_tests() -> {ok, Pid} = riakc_test_utils:start_link(), B = <<"bucket">>, K = <<"foo">>, - O=riakc_obj:new(B, K), + O = riakc_obj:new(B, K), riakc_pb_socket:put(Pid, riakc_obj:update_value(O, <<"2">>, "application/json")), + Inputs = [{B, K}], + Args = [{map, {jsanon, <<"function (v) { return [JSON.parse(v.values[0].data)]; }">>}, undefined, true}], + Want = {ok, [{0, [2]}]}, + Got = riakc_pb_socket:mapred(Pid, Inputs, Args), + ?assertMatch(Want, Got) + end)}, - ?assertEqual({ok, [{0, [2]}]}, - riakc_pb_socket:mapred(Pid, - [{B, K}], - [{map, {jsanon, <<"function (v) { return [JSON.parse(v.values[0].data)]; }">>}, - undefined, true}])) + {"javascript_source_map_with_bucket_type_test()", + ?_test(begin + riakc_test_utils:reset_riak(), + {ok, Pid} = riakc_test_utils:start_link(), + BT = <<"plain">>, + B = <<"my_bucket">>, + BWT = {BT, B}, % NB: Bucket With Type + K = <<"baz">>, + Value = <<"bat">>, + O = riakc_obj:new(BWT, K), + O2 = riakc_obj:update_value(O, Value, "application/json"), + ?assertMatch(BT, riakc_obj:bucket_type(O2)), + ?assertMatch(BWT, riakc_obj:bucket(O2)), + ?assertMatch(K, riakc_obj:key(O2)), + ?assertMatch(ok, riakc_pb_socket:put(Pid, O2)), + {ok, GotObj} = riakc_pb_socket:get(Pid, BWT, K), + ?assertMatch(BT, riakc_obj:bucket_type(GotObj)), + ?assertMatch(BWT, riakc_obj:bucket(GotObj)), + ?assertMatch(K, riakc_obj:key(GotObj)), + % NB: see basho/riak_kv#1623 + Inputs = [{{BWT, K}, ignored},{{BWT, K}, ignored}], + Args = [{map, {jsanon, <<"function (v) { return [v.values[0].data]; }">>}, undefined, true}], + Want = {ok, [{0, [Value, Value]}]}, + Got = riakc_pb_socket:mapred(Pid, Inputs, Args), + ?assertMatch(Want, Got) end)}, {"javascript_named_map_test()", @@ -520,6 +546,25 @@ integration_tests() -> {reduce, {jsfun, <<"Riak.reduceSum">>}, undefined, true}])) end)}, + {"javascript_bucket_type_map_reduce_test()", + ?_test(begin + riakc_test_utils:reset_riak(), + {ok, Pid} = riakc_test_utils:start_link(), + BT = {<<"plain">>,<<"bucket">>}, + Store = fun({K, V}) -> + O=riakc_obj:new(BT, K), + riakc_pb_socket:put(Pid,riakc_obj:update_value(O, V, "application/json")) + end, + [Store(KV) || KV <- [{<<"foo">>, <<"2">>}, + {<<"bar">>, <<"3">>}, + {<<"baz">>, <<"4">>}]], + Want = {ok, [{1, [9]}]}, + Query = [{map, {jsfun, <<"Riak.mapValuesJson">>}, undefined, false}, + {reduce, {jsfun, <<"Riak.reduceSum">>}, undefined, true}], + Got = riakc_pb_socket:mapred_bucket(Pid, BT, Query), + ?assertMatch(Want, Got) + end)}, + {"javascript_arg_map_reduce_test()", ?_test(begin riakc_test_utils:reset_riak(),