Skip to content

Commit

Permalink
Merge pull request #272 from basho/fixes/lrb/ensure-strings-as-binaries
Browse files Browse the repository at this point in the history
Ensure strings as binaries
  • Loading branch information
Brett Hazen committed Apr 13, 2016
2 parents 106853a + c3f4b1f commit 219156a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/riakc_pb_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1971,10 +1971,10 @@ process_response(#request{msg = #tslistkeysreq{}} = Request,

process_response(#request{msg = #tsqueryreq{}},
tsqueryresp, State) ->
{reply, #tsqueryresp{}, State};
{reply, tsqueryresp, State};

process_response(#request{msg = #tsqueryreq{}},
Result = #tsqueryresp{},
Result = {tsqueryresp, _},
State) ->
{reply, Result, State};

Expand All @@ -1988,10 +1988,10 @@ process_response(#request{msg = #rpbcoveragereq{}},

process_response(#request{msg = #tsgetreq{}},
tsgetresp, State) ->
{reply, #tsgetresp{}, State};
{reply, tsgetresp, State};

process_response(#request{msg = #tsgetreq{}},
Result = #tsgetresp{},
Result = {tsgetresp, _},
State) ->
{reply, Result, State};

Expand Down
20 changes: 8 additions & 12 deletions src/riakc_ts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ query_common(Pid, Query, Interpolations, Cover)
riakc_ts_query_operator:deserialize(Response).


-spec get_coverage(pid(), table_name(), Query::string()) ->
{ok, Entries::[term()]} | {error, term()}.
%% @doc Generate a parallel coverage plan for the specified query
get_coverage(Pid, Table, Query)
when is_pid(Pid), (is_binary(Table) orelse is_list(Table)), is_list(Query) ->
-spec get_coverage(Pid::pid(),
Table::binary(),
QueryText::binary()) -> {ok, Entries::[term()]} | {error, term()} | {'EXIT', any()}.
get_coverage(Pid, Table, QueryText) ->
server_call(Pid,
#tscoveragereq{query = #tsinterpolation{base = iolist_to_binary(Query)},
#tscoveragereq{query = #tsinterpolation{base = iolist_to_binary(QueryText)},
replace_cover = undefined,
table = iolist_to_binary(Table)}).

Expand Down Expand Up @@ -150,14 +150,10 @@ get(Pid, Table, Key, Options)
timeout = proplists:get_value(timeout, Options)},

case server_call(Pid, Message) of
{error, {_NotFoundErrCode, <<"notfound">>}} ->
{ok, {[], []}};
{error, OtherError} ->
{error, OtherError};
Response ->
Columns = Response#tsgetresp.columns,
Rows = Response#tsgetresp.rows,
{ok, {Columns, Rows}}
{tsgetresp, {ColumnNames, _ColumnTypes, Rows}} ->
{ok, {ColumnNames, Rows}}
end.


Expand All @@ -173,7 +169,7 @@ stream_list_keys(Pid, Table, Timeout) when is_integer(Timeout) ->
stream_list_keys(Pid, Table, Options)
when is_pid(Pid), (is_binary(Table) orelse is_list(Table)), is_list(Options) ->
ReqTimeout = proplists:get_value(timeout, Options),
Req = #tslistkeysreq{table = iolist_to_binary(Table),
Req = #tslistkeysreq{table = iolist_to_binary(Table),
timeout = ReqTimeout},
ReqId = riakc_pb_socket:mk_reqid(),
gen_server:call(Pid, {req, Req, ?DEFAULT_PB_TIMEOUT, {ReqId, self()}}, infinity).
Expand Down
12 changes: 9 additions & 3 deletions src/riakc_ts_put_operator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
-export([serialize/3,
deserialize/1]).


serialize(TableName, ColumnNames, Measurements) ->
ColumnDescs = riak_pb_ts_codec:encode_columnnames(ColumnNames),
SerializedRows = riak_ttb_codec:encode_ts_rows(Measurements),
#tsputreq{table = TableName,
#tsputreq{table = iolist_to_binary(TableName),
columns = ColumnDescs,
rows = SerializedRows}.
rows = Measurements}.

deserialize({error, {Code, Message}}) when is_integer(Code), is_list(Message) ->
{error, {Code, iolist_to_binary(Message)}};
deserialize({error, {Code, Message}}) when is_integer(Code), is_atom(Message) ->
{error, {Code, iolist_to_binary(atom_to_list(Message))}};
deserialize({error, Message}) ->
{error, Message};
deserialize(Response) ->
Response.
18 changes: 13 additions & 5 deletions src/riakc_ts_query_operator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
-export([serialize/2,
deserialize/1]).


serialize(QueryText, Interpolations) ->
Content = #tsinterpolation{
base = QueryText,
base = iolist_to_binary(QueryText),
interpolations = serialize_interpolations(Interpolations)},
#tsqueryreq{query = Content}.

Expand All @@ -48,7 +47,16 @@ serialize_interpolations([{Key, Value} | RemainingInterps],
UpdatedInterps = [#rpbpair{key=Key, value=Value} | SerializedInterps],
serialize_interpolations(RemainingInterps, UpdatedInterps).

deserialize({error, Message}) -> {error, Message};

deserialize(#tsqueryresp{columns = {ColumnNames, _ColumnTypes}, rows = Rows}) ->
deserialize({error, {Code, Message}}) when is_integer(Code), is_list(Message) ->
{error, {Code, iolist_to_binary(Message)}};
deserialize({error, {Code, Message}}) when is_integer(Code), is_atom(Message) ->
{error, {Code, iolist_to_binary(atom_to_list(Message))}};
deserialize({error, Message}) ->
{error, Message};

deserialize(tsqueryresp) ->
{[], []};
deserialize({tsqueryresp, {_, _, []}}) ->
{[], []};
deserialize({tsqueryresp, {ColumnNames, _ColumnTypes, Rows}}) ->
{ColumnNames, Rows}.

0 comments on commit 219156a

Please sign in to comment.