2016-08-02 17:25:12 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2016 Basho Technologies, Inc.
|
|
|
|
%%
|
|
|
|
%% This file is provided to you under the Apache License,
|
|
|
|
%% Version 2.0 (the "License"); you may not use this file
|
|
|
|
%% except in compliance with the License. You may obtain
|
|
|
|
%% a copy of the License at
|
|
|
|
%%
|
|
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
%%
|
|
|
|
%% Unless required by applicable law or agreed to in writing,
|
|
|
|
%% software distributed under the License is distributed on an
|
|
|
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
%% KIND, either express or implied. See the License for the
|
|
|
|
%% specific language governing permissions and limitations
|
|
|
|
%% under the License.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ts_simple_select_iso8601).
|
|
|
|
|
|
|
|
-behavior(riak_test).
|
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
-export([confirm/0]).
|
|
|
|
|
|
|
|
%% We'll populate the table with one record per second between the
|
|
|
|
%% lower and upper bounds
|
|
|
|
-define(LOWER, "2016-08-02 10:15:00").
|
|
|
|
-define(UPPER, "2016-08-02 10:45:00").
|
|
|
|
|
2016-10-24 21:45:05 +00:00
|
|
|
-define(PASS_TESTS, [
|
2016-08-02 17:25:12 +00:00
|
|
|
%% Test format, illustrated:
|
|
|
|
|
|
|
|
%% We expect 9 seconds between 10:19:50 and 10:20:00,
|
|
|
|
%% exclusive on both ends.
|
|
|
|
{9,
|
|
|
|
{">", "2016-08-02 10:19:50"},
|
|
|
|
{"<", "2016-08-02 10:20"}
|
|
|
|
},
|
|
|
|
|
|
|
|
{60,
|
|
|
|
{">=", "2016-08-02 10:19"},
|
|
|
|
{"<", "2016-08-02 10:20"}
|
|
|
|
},
|
|
|
|
|
|
|
|
%% Two full minutes, from 10:19:00 to 10:20:59
|
|
|
|
%% inclusive
|
|
|
|
{120,
|
|
|
|
{">=", "2016-08-02 10:19"},
|
|
|
|
{"<=", "2016-08-02 10:20"}
|
|
|
|
},
|
|
|
|
|
|
|
|
{61,
|
|
|
|
{">=", "2016-08-02 10:19"},
|
|
|
|
{"<=", "2016-08-02 10:20.01"}
|
|
|
|
},
|
|
|
|
|
|
|
|
{61,
|
|
|
|
{">=", "2016-08-02 10:19"},
|
|
|
|
{"<", "2016-08-02 10:20:01"}
|
|
|
|
},
|
|
|
|
|
|
|
|
{59,
|
|
|
|
{">", "2016-08-02 10:19.0"},
|
|
|
|
{"<", "2016-08-02 10:20"}
|
|
|
|
},
|
|
|
|
|
|
|
|
{0,
|
|
|
|
{">", "2016-08-02 10:19.99"},
|
|
|
|
{"<", "2016-08-02 10:20"}
|
|
|
|
}
|
|
|
|
]).
|
2016-10-25 19:09:51 +00:00
|
|
|
%% expected error code is the first entry
|
2016-10-24 21:45:05 +00:00
|
|
|
-define(FAIL_TESTS, [
|
2016-10-24 21:56:44 +00:00
|
|
|
{
|
2016-10-25 19:09:51 +00:00
|
|
|
1001,
|
2016-10-24 21:45:05 +00:00
|
|
|
{">", "2016-08-02 10:19"},
|
|
|
|
{"<", "2016-08-02 10:20"}
|
|
|
|
}
|
|
|
|
]).
|
|
|
|
|
2016-08-02 17:25:12 +00:00
|
|
|
|
|
|
|
confirm() ->
|
2016-11-01 14:03:48 +00:00
|
|
|
Table = ts_data:get_default_bucket(),
|
|
|
|
DDL = ts_data:get_ddl(),
|
2016-08-02 17:25:12 +00:00
|
|
|
Start = jam:to_epoch(jam:compile(jam_iso8601:parse(?LOWER)), 3),
|
|
|
|
End = jam:to_epoch(jam:compile(jam_iso8601:parse(?UPPER)), 3),
|
2016-11-01 14:03:48 +00:00
|
|
|
AllData = ts_data:get_valid_select_data(fun() -> lists:seq(Start, End, 1000) end),
|
2016-08-02 17:25:12 +00:00
|
|
|
QryFmt =
|
|
|
|
"SELECT * FROM GeoCheckin "
|
|
|
|
"WHERE time ~s '~s' and time ~s '~s' "
|
|
|
|
"AND myfamily = 'family1' "
|
|
|
|
"AND myseries ='seriesX' ",
|
|
|
|
|
2016-11-01 14:03:48 +00:00
|
|
|
Cluster = ts_setup:start_cluster(1),
|
|
|
|
ts_setup:create_bucket_type(Cluster, DDL, Table),
|
|
|
|
ts_setup:activate_bucket_type(Cluster, Table),
|
|
|
|
ts_ops:put(Cluster, Table, AllData),
|
|
|
|
|
|
|
|
DDL = ts_data:get_ddl(),
|
|
|
|
|
2016-08-02 17:25:12 +00:00
|
|
|
lists:foreach(
|
2016-11-01 14:03:48 +00:00
|
|
|
fun({Tally, {Op1, String1}, {Op2, String2}}) ->
|
|
|
|
Qry = ts_data:flat_format(QryFmt, [Op1, String1,
|
|
|
|
Op2, String2]),
|
2016-08-02 17:25:12 +00:00
|
|
|
|
2016-11-01 14:03:48 +00:00
|
|
|
{ok, {_Cols, Data}} = ts_ops:query(Cluster, Qry),
|
2016-08-02 17:25:12 +00:00
|
|
|
|
|
|
|
?assertEqual(Tally, length(Data))
|
2016-11-01 14:03:48 +00:00
|
|
|
end, ?PASS_TESTS),
|
2016-10-24 21:45:05 +00:00
|
|
|
|
|
|
|
lists:foreach(
|
2016-11-01 14:03:48 +00:00
|
|
|
fun({ErrCode, {Op1, String1}, {Op2, String2}}) ->
|
|
|
|
Qry = ts_data:flat_format(QryFmt, [Op1, String1,
|
|
|
|
Op2, String2]),
|
2016-10-24 21:45:05 +00:00
|
|
|
|
2016-11-01 14:03:48 +00:00
|
|
|
RetMsg = ts_ops:query(Cluster, Qry),
|
2016-10-25 19:09:51 +00:00
|
|
|
?assertMatch({error, {ErrCode, _}}, RetMsg)
|
2016-11-01 14:03:48 +00:00
|
|
|
end, ?FAIL_TESTS),
|
2016-10-24 21:45:05 +00:00
|
|
|
|
2016-08-02 17:25:12 +00:00
|
|
|
pass.
|