Skip to content

Commit

Permalink
Merge pull request #218 from basho/am/fixes/gset-update-return-value
Browse files Browse the repository at this point in the history
Add GSET update response handling to riak_pb_dt_codec.erl
  • Loading branch information
alexmoore authored Jan 5, 2017
2 parents 4541303 + 38f5d1d commit 6c67dc5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
4 changes: 2 additions & 2 deletions include/riak_ts_pb.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
-ifndef('TSCOVERAGEREQ_PB_H').
-define('TSCOVERAGEREQ_PB_H', true).
-record(tscoveragereq,
{query :: #tsinterpolation{} | undefined, % = 1
{'query' :: #tsinterpolation{} | undefined, % = 1
table :: binary(), % = 2
replace_cover :: binary() | undefined, % = 3
unavailable_cover = [] :: [binary()] % = 4
Expand Down Expand Up @@ -259,7 +259,7 @@
-ifndef('TSQUERYREQ_PB_H').
-define('TSQUERYREQ_PB_H', true).
-record(tsqueryreq,
{query :: #tsinterpolation{} | undefined, % = 1
{'query' :: #tsinterpolation{} | undefined, % = 1
stream = false :: boolean() | 0 | 1 | undefined, % = 2
cover_context :: binary() | undefined % = 3
}).
Expand Down
6 changes: 4 additions & 2 deletions src/riak_pb_dt_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,10 @@ encode_update_response(counter, Value, Key, Context, _Mods) ->
#dtupdateresp{key=Key, context=Context, counter_value=Value};
encode_update_response(set, Value, Key, Context, _Mods) ->
#dtupdateresp{key=Key, context=Context, set_value=Value};
encode_update_response(hll, Value, Key, Context, _Mods) ->
#dtupdateresp{key=Key, context=Context, hll_value=Value};
encode_update_response(gset, Value, Key, _Context, _Mods) ->
#dtupdateresp{key=Key, context=_Context, gset_value=Value};
encode_update_response(hll, Value, Key, _Context, _Mods) ->
#dtupdateresp{key=Key, context=_Context, hll_value=Value};
encode_update_response(map, Value, Key, Context, Mods) when is_list(Value) ->
#dtupdateresp{key=Key, context=Context,
map_value=[encode_map_entry(Entry, Mods)
Expand Down
40 changes: 20 additions & 20 deletions src/riak_ts_pb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ e_msg_tscoveragereq(Msg, TrUserData) ->
e_msg_tscoveragereq(Msg, <<>>, TrUserData).


e_msg_tscoveragereq(#tscoveragereq{query = F1,
e_msg_tscoveragereq(#tscoveragereq{'query' = F1,
table = F2, replace_cover = F3,
unavailable_cover = F4},
Bin, TrUserData) ->
Expand Down Expand Up @@ -1069,7 +1069,7 @@ e_msg_tsqueryreq(Msg, TrUserData) ->
e_msg_tsqueryreq(Msg, <<>>, TrUserData).


e_msg_tsqueryreq(#tsqueryreq{query = F1, stream = F2,
e_msg_tsqueryreq(#tsqueryreq{'query' = F1, stream = F2,
cover_context = F3},
Bin, TrUserData) ->
B1 = if F1 == undefined -> Bin;
Expand Down Expand Up @@ -4133,7 +4133,7 @@ dfp_read_field_def_tscoveragereq(<<34, Rest/binary>>,
F1, F2, F3, F4, TrUserData);
dfp_read_field_def_tscoveragereq(<<>>, 0, 0, F1, F2, F3,
F4, TrUserData) ->
#tscoveragereq{query = F1, table = F2,
#tscoveragereq{'query' = F1, table = F2,
replace_cover = F3,
unavailable_cover = lists_reverse(F4, TrUserData)};
dfp_read_field_def_tscoveragereq(Other, Z1, Z2, F1, F2,
Expand Down Expand Up @@ -4182,7 +4182,7 @@ dg_read_field_def_tscoveragereq(<<0:1, X:7,
end;
dg_read_field_def_tscoveragereq(<<>>, 0, 0, F1, F2, F3,
F4, TrUserData) ->
#tscoveragereq{query = F1, table = F2,
#tscoveragereq{'query' = F1, table = F2,
replace_cover = F3,
unavailable_cover = lists_reverse(F4, TrUserData)}.

Expand Down Expand Up @@ -6496,7 +6496,7 @@ dfp_read_field_def_tsqueryreq(<<26, Rest/binary>>, Z1,
F3, TrUserData);
dfp_read_field_def_tsqueryreq(<<>>, 0, 0, F1, F2, F3,
_) ->
#tsqueryreq{query = F1, stream = F2,
#tsqueryreq{'query' = F1, stream = F2,
cover_context = F3};
dfp_read_field_def_tsqueryreq(Other, Z1, Z2, F1, F2, F3,
TrUserData) ->
Expand Down Expand Up @@ -6537,7 +6537,7 @@ dg_read_field_def_tsqueryreq(<<0:1, X:7, Rest/binary>>,
end;
dg_read_field_def_tsqueryreq(<<>>, 0, 0, F1, F2, F3,
_) ->
#tsqueryreq{query = F1, stream = F2,
#tsqueryreq{'query' = F1, stream = F2,
cover_context = F3}.

d_field_tsqueryreq_query(<<1:1, X:7, Rest/binary>>, N,
Expand Down Expand Up @@ -7373,14 +7373,14 @@ merge_msg_tsinterpolation(#tsinterpolation{interpolations
'erlang_++'(PFinterpolations, NFinterpolations,
TrUserData)}.

merge_msg_tscoveragereq(#tscoveragereq{query = PFquery,
merge_msg_tscoveragereq(#tscoveragereq{'query' = PFquery,
replace_cover = PFreplace_cover,
unavailable_cover = PFunavailable_cover},
#tscoveragereq{query = NFquery, table = NFtable,
#tscoveragereq{'query' = NFquery, table = NFtable,
replace_cover = NFreplace_cover,
unavailable_cover = NFunavailable_cover},
TrUserData) ->
#tscoveragereq{query =
#tscoveragereq{'query' =
if PFquery /= undefined, NFquery /= undefined ->
merge_msg_tsinterpolation(PFquery, NFquery,
TrUserData);
Expand Down Expand Up @@ -7585,13 +7585,13 @@ merge_msg_rpbauthreq(#rpbauthreq{},
#rpbauthreq{user = NFuser, password = NFpassword}, _) ->
#rpbauthreq{user = NFuser, password = NFpassword}.

merge_msg_tsqueryreq(#tsqueryreq{query = PFquery,
merge_msg_tsqueryreq(#tsqueryreq{'query' = PFquery,
stream = PFstream,
cover_context = PFcover_context},
#tsqueryreq{query = NFquery, stream = NFstream,
#tsqueryreq{'query' = NFquery, stream = NFstream,
cover_context = NFcover_context},
TrUserData) ->
#tsqueryreq{query =
#tsqueryreq{'query' =
if PFquery /= undefined, NFquery /= undefined ->
merge_msg_tsinterpolation(PFquery, NFquery,
TrUserData);
Expand Down Expand Up @@ -7925,13 +7925,13 @@ v_msg_tsinterpolation(#tsinterpolation{base = F1,
v_msg_tsinterpolation(X, Path, _TrUserData) ->
mk_type_error({expected_msg, tsinterpolation}, X, Path).

v_msg_tscoveragereq(#tscoveragereq{query = F1,
v_msg_tscoveragereq(#tscoveragereq{'query' = F1,
table = F2, replace_cover = F3,
unavailable_cover = F4},
Path, TrUserData) ->
if F1 == undefined -> ok;
true ->
v_msg_tsinterpolation(F1, [query | Path], TrUserData)
v_msg_tsinterpolation(F1, ['query' | Path], TrUserData)
end,
v_type_bytes(F2, [table | Path]),
if F3 == undefined -> ok;
Expand Down Expand Up @@ -8173,12 +8173,12 @@ v_msg_rpbauthreq(#rpbauthreq{user = F1, password = F2},
v_type_bytes(F2, [password | Path]),
ok.

v_msg_tsqueryreq(#tsqueryreq{query = F1, stream = F2,
v_msg_tsqueryreq(#tsqueryreq{'query' = F1, stream = F2,
cover_context = F3},
Path, TrUserData) ->
if F1 == undefined -> ok;
true ->
v_msg_tsinterpolation(F1, [query | Path], TrUserData)
v_msg_tsinterpolation(F1, ['query' | Path], TrUserData)
end,
if F2 == undefined -> ok;
true -> v_type_bool(F2, [stream | Path])
Expand Down Expand Up @@ -8451,7 +8451,7 @@ get_msg_defs() ->
{type, {msg, rpbpair}}, {occurrence, repeated},
{opts, []}]]},
{{msg, tscoveragereq},
[[{name, query}, {fnum, 1}, {rnum, 2},
[[{name, 'query'}, {fnum, 1}, {rnum, 2},
{type, {msg, tsinterpolation}}, {occurrence, optional},
{opts, []}],
[{name, table}, {fnum, 2}, {rnum, 3}, {type, bytes},
Expand Down Expand Up @@ -8567,7 +8567,7 @@ get_msg_defs() ->
[{name, password}, {fnum, 2}, {rnum, 3}, {type, bytes},
{occurrence, required}, {opts, []}]]},
{{msg, tsqueryreq},
[[{name, query}, {fnum, 1}, {rnum, 2},
[[{name, 'query'}, {fnum, 1}, {rnum, 2},
{type, {msg, tsinterpolation}}, {occurrence, optional},
{opts, []}],
[{name, stream}, {fnum, 2}, {rnum, 3}, {type, bool},
Expand Down Expand Up @@ -8741,7 +8741,7 @@ find_msg_def(tsinterpolation) ->
{type, {msg, rpbpair}}, {occurrence, repeated},
{opts, []}]];
find_msg_def(tscoveragereq) ->
[[{name, query}, {fnum, 1}, {rnum, 2},
[[{name, 'query'}, {fnum, 1}, {rnum, 2},
{type, {msg, tsinterpolation}}, {occurrence, optional},
{opts, []}],
[{name, table}, {fnum, 2}, {rnum, 3}, {type, bytes},
Expand Down Expand Up @@ -8857,7 +8857,7 @@ find_msg_def(rpbauthreq) ->
[{name, password}, {fnum, 2}, {rnum, 3}, {type, bytes},
{occurrence, required}, {opts, []}]];
find_msg_def(tsqueryreq) ->
[[{name, query}, {fnum, 1}, {rnum, 2},
[[{name, 'query'}, {fnum, 1}, {rnum, 2},
{type, {msg, tsinterpolation}}, {occurrence, optional},
{opts, []}],
[{name, stream}, {fnum, 2}, {rnum, 3}, {type, bool},
Expand Down
14 changes: 13 additions & 1 deletion test/riak_pb_dt_codec_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ operation_type/1,
decode_fetch_response/1,
encode_fetch_response/4,
encode_update_request/4,
decode_update_response/3
decode_update_response/3,
encode_update_response/5
]).

-define(CONTEXT, undefined_context).
-define(SET_KEY, <<"amoore">>).
-define(SET_VALUE, [<<"binarytemple">>]).

operation_type_gset_test() ->
Expand Down Expand Up @@ -76,3 +78,13 @@ encode_update_request_gset_test() ->
}, Res),
ok
.

encode_update_response_gset_test() ->
Resp = encode_update_response(gset, ?SET_VALUE, ?SET_KEY, undefined, []),
?assertMatch(
#dtupdateresp{
key = ?SET_KEY,
context = undefined,
gset_value = ?SET_VALUE
},
Resp).

0 comments on commit 6c67dc5

Please sign in to comment.