Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP client API all-in-one [3/3] #1398

Merged
merged 7 commits into from
Apr 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/riak_kv_qry.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ do_describe(?DDL{fields = FieldSpecs,
ColumnNames = [<<"Column">>, <<"Type">>, <<"Is Null">>, <<"Primary Key">>, <<"Local Key">>],
ColumnTypes = [ varchar, varchar, boolean, sint64, sint64 ],
Rows =
[{Name, list_to_binary(atom_to_list(Type)), Nullable,
[[Name, list_to_binary(atom_to_list(Type)), Nullable,
column_pk_position_or_blank(Name, PKSpec),
column_lk_position_or_blank(Name, LKSpec)}
column_lk_position_or_blank(Name, LKSpec)]
|| #riak_field_v1{name = Name,
type = Type,
optional = Nullable} <- FieldSpecs],
Expand Down Expand Up @@ -299,11 +299,11 @@ describe_table_columns_test() ->
Res = do_describe(DDL),
?assertMatch(
{ok, {_, _,
[{<<"f">>, <<"varchar">>, false, 1, 1},
{<<"s">>, <<"varchar">>, false, 2, 2},
{<<"t">>, <<"timestamp">>, false, 3, 3},
{<<"w">>, <<"sint64">>, false, [], []},
{<<"p">>, <<"double">>, true, [], []}]}},
[[<<"f">>, <<"varchar">>, false, 1, 1],
[<<"s">>, <<"varchar">>, false, 2, 2],
[<<"t">>, <<"timestamp">>, false, 3, 3],
[<<"w">>, <<"sint64">>, false, [], []],
[<<"p">>, <<"double">>, true, [], []]]}},
Res).

validate_make_insert_row_basic_test() ->
Expand Down
6 changes: 2 additions & 4 deletions src/riak_kv_qry_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ prepare_final_results(#state{
prepare_final_results2(#riak_sel_clause_v1{col_return_types = ColTypes,
col_names = ColNames}, Rows) ->
%% filter out empty records
FinalRows = [list_to_tuple(R) || R <- Rows, R /= [[]]],
FinalRows = [R || R <- Rows, R /= [[]]],
{ColNames, ColTypes, FinalRows}.

%%%===================================================================
Expand All @@ -292,10 +292,8 @@ prepare_final_results2(#riak_sel_clause_v1{col_return_types = ColTypes,

prepare_final_results_test() ->
Rows = [[12, <<"windy">>], [13, <<"windy">>]],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be tuples then? I'll test and find out...

Copy link
Contributor Author

@hmmr hmmr Apr 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list_to_tuple now happens in riak_kv_ts_svc, right before the records are delivered to the PB/TTB code and further to the client. This is so in order to avoid converting tuples back to lists in riak_kv_wm_timeseries_query, where lists are required for converting the data to json.

Which is why we still have native records-as-lists here.

RowsAsTuples = [{12, <<"windy">>}, {13, <<"windy">>}],
% IndexedChunks = [{1, Rows}],
?assertEqual(
{[<<"a">>, <<"b">>], [sint64, varchar], RowsAsTuples},
{[<<"a">>, <<"b">>], [sint64, varchar], Rows},
prepare_final_results(
#state{
qry =
Expand Down
5 changes: 3 additions & 2 deletions src/riak_kv_ts_svc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,9 @@ sub_tscoveragereq(Mod, _DDL, #tscoveragereq{table = Table,
{reply, ts_query_responses() | #rpberrorresp{}, #state{}}.
sub_tsqueryreq(_Mod, DDL = ?DDL{table = Table}, SQL, State) ->
case riak_kv_ts_api:query(SQL, DDL) of
{ok, Data} ->
{reply, make_tsqueryresp(Data), State};
{ok, {ColNames, ColTypes, LdbNativeRows}} ->
Rows = [list_to_tuple(R) || R <- LdbNativeRows],
{reply, make_tsqueryresp({ColNames, ColTypes, Rows}), State};

%% the following timeouts are known and distinguished:
{error, no_type} ->
Expand Down
14 changes: 12 additions & 2 deletions src/riak_kv_web.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%%
%% riak_kv_web: setup Riak's KV HTTP interface
%%
%% Copyright (c) 2007-2010 Basho Technologies, Inc. All Rights Reserved.
%% Copyright (c) 2007-2016 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -121,7 +121,17 @@ raw_dispatch(Name) ->
{Prefix ++ ["buckets", bucket, "index", field, '*'],
riak_kv_wm_index, Props}

] || {Prefix, Props} <- Props2 ]).
] || {Prefix, Props} <- Props2 ]) ++

lists:flatten(
[
%% Right now we only have version 1. When we get version 2 we have to
%% decide if we want to dispatch to separate resource modules or handle
%% the different versions inside the same resource handler module.
[{["ts", api_version, "tables", table, "list_keys"], riak_kv_wm_timeseries_listkeys, Props},
{["ts", api_version, "tables", table, "keys", '*'], riak_kv_wm_timeseries, Props},
{["ts", api_version, "query"], riak_kv_wm_timeseries_query, Props}
] || {_Prefix, Props} <- Props2]).

is_post(Req) ->
wrq:method(Req) == 'POST'.
Expand Down
Loading