Merge pull request #1196 from basho/fix-az-dont_fail_to_produce_test_query_with_empty_orderby

ts_simple_query_buffers: query generator failed to emit ORDER BY-less ones
This commit is contained in:
Andrei Zavada 2016-11-16 21:41:04 +02:00 committed by GitHub
commit c73713d129
2 changed files with 15 additions and 15 deletions

View File

@ -92,7 +92,7 @@ full_query(Table, OptionalClauses) ->
Item <- [order_by, limit, offset]], Item <- [order_by, limit, offset]],
fmt("~s~s~s~s", fmt("~s~s~s~s",
[base_query(Table), [base_query(Table),
[fmt(" order by ~s", [make_orderby_list(OrderBy)]) || OrderBy /= undefined], [fmt(" order by ~s", [make_orderby_list(OrderBy)]) || OrderBy /= []],
[fmt(" limit ~b", [Limit]) || Limit /= undefined], [fmt(" limit ~b", [Limit]) || Limit /= undefined],
[fmt(" offset ~b", [Offset]) || Offset /= undefined]]). [fmt(" offset ~b", [Offset]) || Offset /= undefined]]).

View File

@ -103,14 +103,14 @@ query_orderby_comprehensive(Cfg) ->
F3 <- ?ORDBY_COLS, F3 <- ?ORDBY_COLS,
F4 <- ?ORDBY_COLS, F4 <- ?ORDBY_COLS,
F5 <- ?ORDBY_COLS, F5 <- ?ORDBY_COLS,
all_different([F1, F2, F3, F4, F5]), all_different([F1, F2, F3, F4, F5])],
not_all_undefined([F1, F2, F3, F4, F5])],
OrderByBattery2 = OrderByBattery2 =
lists:map( lists:usort(
fun(FF) -> lists:map(
[F || F <- FF, F /= undefined] fun(FF) ->
end, [F || F <- FF, F /= undefined]
OrderByBattery1), end,
OrderByBattery1)),
lists:foreach( lists:foreach(
fun(Items) -> fun(Items) ->
Variants = Variants =
@ -118,23 +118,23 @@ query_orderby_comprehensive(Cfg) ->
lists:foreach( lists:foreach(
fun(Var) -> fun(Var) ->
check_sorted(C, ?TABLE, Data, [{order_by, Var}]), check_sorted(C, ?TABLE, Data, [{order_by, Var}]),
check_sorted(C, ?TABLE, Data, [{order_by, Var}, {limit, 1}, {offset, 10}]), check_sorted(C, ?TABLE, Data, [{order_by, Var}, {limit, 1}]),
check_sorted(C, ?TABLE, Data, [{order_by, Var}, {limit, 4}, {offset, 5}]), check_sorted(C, ?TABLE, Data, [{order_by, Var}, {limit, 2}, {offset, 4}])
check_sorted(C, ?TABLE, Data, [{order_by, Var}, {limit, 55}, {offset, 11}])
end, end,
Variants) Variants)
end, end,
OrderByBattery2). OrderByBattery2).
all_different(XX) -> all_different(XX) ->
length(lists:usort(XX)) == length(XX). YY = [X || X <- XX, X /= undefined],
not_all_undefined(XX) -> length(lists:usort(YY)) == length(YY).
not lists:all(fun(X) -> X == undefined end, XX).
%% given a single list of fields, e.g., ["a", "b", "c"], produce all %% given a single list of fields, e.g., ["a", "b", "c"], produce all
%% variants featuring all possible modifiers with each field, thus: %% variants featuring all possible modifiers with each field, thus:
%% [[{"a", "asc", "nulls first"}, ...], ..., %% [[{"a", "asc", "nulls first"}, ...], ...,
%% [{"a", undefined, undefined}, ...]] %% [{"a", undefined, undefined}, ...]]
make_ordby_item_variants([]) ->
[[]]; %% this special case gets lost in rolling/unrolling wizardry
make_ordby_item_variants(FF) -> make_ordby_item_variants(FF) ->
Modifiers = Modifiers =
[{Dir, Nul} || Dir <- ["asc", "desc", undefined], [{Dir, Nul} || Dir <- ["asc", "desc", undefined],
@ -270,6 +270,7 @@ check_sorted(C, Table, OrigData, Clauses) ->
check_sorted(C, Table, OrigData, Clauses, [{allow_qbuf_reuse, true}]). check_sorted(C, Table, OrigData, Clauses, [{allow_qbuf_reuse, true}]).
check_sorted(C, Table, OrigData, Clauses, Options) -> check_sorted(C, Table, OrigData, Clauses, Options) ->
Query = ts_qbuf_util:full_query(Table, Clauses), Query = ts_qbuf_util:full_query(Table, Clauses),
ct:log("Query: \"~s\"", [Query]),
{ok, {_Cols, Returned}} = {ok, {_Cols, Returned}} =
riakc_ts:query(C, Query, [], undefined, Options), riakc_ts:query(C, Query, [], undefined, Options),
OrderBy = proplists:get_value(order_by, Clauses), OrderBy = proplists:get_value(order_by, Clauses),
@ -279,7 +280,6 @@ check_sorted(C, Table, OrigData, Clauses, Options) ->
%% including sorting according to ORDER BY %% including sorting according to ORDER BY
%% uncomment these log entries to inspect the data visually (else %% uncomment these log entries to inspect the data visually (else
%% it's just going to blow up the log into tens of megs): %% it's just going to blow up the log into tens of megs):
%% ct:log("Query: \"~s\"", [Query]),
%% ct:log("Fetched ~p", [Returned]), %% ct:log("Fetched ~p", [Returned]),
PreSelected = sort_by( PreSelected = sort_by(
where_filter(OrigData, [{"a", ?WHERE_FILTER_A}, where_filter(OrigData, [{"a", ?WHERE_FILTER_A},