Merge with upstream

This commit is contained in:
Gordon Guthrie 2016-08-03 15:13:53 +00:00
commit 94ae0c38ee
7 changed files with 205 additions and 23 deletions

View File

@ -8,15 +8,21 @@
"}}.
{{command, "show_nodes; "}, {result, "The connected nodes are: ['dev1@127.0.0.1','dev2@127.0.0.1','dev3@127.0.0.1']"}}.
{{command, "CREATE TABLE GeoCheckin (myfamily varchar not null, myseries varchar not null, time timestamp not null, weather varchar not null, temperature double, PRIMARY KEY ((myfamily, myseries, quantum(time, 15, 'm')), myfamily, myseries, time));\n"}, {result, ""}}.
{{command, "describe GeoCheckin;\n"}, {result, "+-----------+---------+-------+-----------+---------+
| Column | Type |Is Null|Primary Key|Local Key|
+-----------+---------+-------+-----------+---------+
| myfamily | varchar | false | 1 | 1 |
| myseries | varchar | false | 2 | 2 |
| time |timestamp| false | 3 | 3 |
| weather | varchar | false | | |
|temperature| double | true | | |
+-----------+---------+-------+-----------+---------+
{{command, "describe GeoCheckin;\n"}, {result, "+-----------+---------+-------+-----------+---------+--------+----+
| Column | Type |Is Null|Primary Key|Local Key|Interval|Unit|
+-----------+---------+-------+-----------+---------+--------+----+
| myfamily | varchar | false | 1 | 1 | | |
| myseries | varchar | false | 2 | 2 | | |
| time |timestamp| false | 3 | 3 | 15 | m |
| weather | varchar | false | | | | |
|temperature| double | true | | | | |
+-----------+---------+-------+-----------+---------+--------+----+
"}}.
{{command, "SHOW TABLES;\n"}, {result, "+----------+
| Table |
+----------+
|GeoCheckin|
+----------+
"}}.
{{command, "insert into GeoCheckin (myfamily, myseries, time, weather, temperature) values ('family1','series1',1,'snow',25.2);\n"}, {result, ""}}.
{{command, "insert into GeoCheckin (myfamily, myseries, time, weather, temperature) values ('family1','series1',2,'rain',24.5);\n"}, {result, ""}}.

View File

@ -167,14 +167,14 @@ confirm_select(C, PvalP1, PvalP2, Options) ->
lists:flatten(
io_lib:format(
"select score, pooter2 from ~s where"
" ~s = '~s'"
" and ~s = '~s'"
" ~s = '~ts'"
" and ~s = '~ts'"
" and ~s > ~b and ~s < ~b",
[?BUCKET,
?PKEY_P1, PvalP1,
?PKEY_P2, PvalP2,
?PKEY_P3, ?TIMEBASE + 10, ?PKEY_P3, ?TIMEBASE + 20])),
io:format("Running query: ~p\n", [Query]),
io:format("Running query: ~ts\n", [Query]),
{ok, {_Columns, Rows}} = riakc_ts:query(C, Query, Options),
io:format("Got ~b rows back\n~p\n", [length(Rows), Rows]),
?assertEqual(10 - 1 - 1, length(Rows)),

View File

@ -0,0 +1,63 @@
%% -------------------------------------------------------------------
%%
%% 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_insert_iso8601).
-behavior(riak_test).
-include_lib("eunit/include/eunit.hrl").
-export([confirm/0]).
%% Epoch mappings for this test
-define(TESTS, [
{"2016-08-02T10:00:00Z", 1470132000000},
{"2016-08-02T10:00:00-05:30", 1470151800000},
{"2016-08-02T24:00:00Z", 1470182400000},
{"2016-08-02 23:59:59Z", 1470182399000},
{"2016-08-03T23:59:60Z", 1470268800000},
{"2016-08", 1470009600000},
{"2016-08-04T15.5", 1470324600000},
{"2016-08-02 05Z", 1470114000000}
]).
confirm() ->
DDL = ts_util:get_ddl(),
Table = ts_util:get_default_bucket(),
{Cluster, Conn} = ts_util:cluster_and_connect(single),
ts_util:create_and_activate_bucket_type(Cluster, DDL),
QryFmt = "select * from GeoCheckin Where time >= ~B and time <= ~B and myfamily = 'family1' and myseries ='seriesX'",
lists:foreach(
fun({String, Epoch}) ->
Qry = lists:flatten(
io_lib:format(QryFmt, [Epoch-10, Epoch+10])),
{ok, {[], []}} = ts_util:single_query(Conn, Qry),
ts_util:ts_insert_no_columns(Conn, Table,
{<<"family1">>, <<"seriesX">>,
unicode:characters_to_binary(String), <<"cloudy">>, 5.5}),
{ok, {_Cols, OneRow}} = ts_util:single_query(Conn, Qry),
?assertEqual(1, length(OneRow))
end, ?TESTS),
pass.

View File

@ -0,0 +1,111 @@
%% -------------------------------------------------------------------
%%
%% 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").
-define(TESTS, [
%% 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"},
{"<", "2016-08-02 10:20"}
},
{0,
{">", "2016-08-02 10:19.99"},
{"<", "2016-08-02 10:20"}
}
]).
confirm() ->
DDL = ts_util:get_ddl(),
Start = jam:to_epoch(jam:compile(jam_iso8601:parse(?LOWER)), 3),
End = jam:to_epoch(jam:compile(jam_iso8601:parse(?UPPER)), 3),
AllData = ts_util:get_valid_select_data(fun() -> lists:seq(Start, End, 1000) end),
{Cluster, Conn} = ts_util:cluster_and_connect(single),
Bucket = ts_util:get_default_bucket(),
ts_util:create_table(normal, Cluster, DDL, Bucket),
riakc_ts:put(Conn, Bucket, AllData),
QryFmt =
"SELECT * FROM GeoCheckin "
"WHERE time ~s '~s' and time ~s '~s' "
"AND myfamily = 'family1' "
"AND myseries ='seriesX' ",
lists:foreach(
fun({Tally, {Op1, String1}, {Op2, String2}}) ->
Qry = lists:flatten(
io_lib:format(QryFmt, [Op1, String1,
Op2, String2])),
{ok, {_Cols, Data}} = ts_util:single_query(Conn, Qry),
?assertEqual(Tally, length(Data))
end, ?TESTS),
pass.

View File

@ -119,7 +119,7 @@ run_scenario(Config,
" need_table_node_transition: ~p\n"
" need_query_node_transition: ~p\n"
" need_pre_cluster_mixed: ~p\n"
" need_post_cluster_mixed: ~p\n",
" need_post_cluster_mixed: ~p\n",
[TableNodeVsn, QueryNodeVsn,
NeedTableNodeTransition, NeedQueryNodeTransition,
NeedPreClusterMixed, NeedPostClusterMixed]),
@ -197,11 +197,11 @@ query_with_client(Query, Node, Config) ->
case Version of
current ->
riakc_ts:query(Client, Query);
previous ->
rpc:call(
?CFG(previous_client_node, Config),
riakc_ts, query, [Client, Query])
end.
previous ->
rpc:call(
?CFG(previous_client_node, Config),
riakc_ts, query, [Client, Query])
end.
-spec is_cluster_mixed(versioned_cluster()) -> boolean().
@ -372,7 +372,7 @@ insert_data(#test_set{testname = Testname,
Table = get_table_name(Testname, Timestamp),
case riakc_ts:put(Client1, Table, Data) of
Exp ->
ct:log("Table ~p on ~p had ~b records successfully inserted)",
ct:log("Table ~p on ~p had ~b records successfully inserted)",
[Table, TableNode, length(Data)]),
pass;
Error ->
@ -408,7 +408,7 @@ run_select(#select{qry = Q,
add_timestamps(TestSets) ->
[X#test_set{timestamp = make_timestamp()} || X <- TestSets].
make_timestamp() ->
make_timestamp() ->
{_Mega, Sec, Milli} = os:timestamp(),
fmt("~b~b", [Sec, Milli]).

View File

@ -1,3 +1,4 @@
%% -*- Mode: Erlang -*-
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2016 Basho Technologies, Inc.

View File

@ -140,7 +140,7 @@ ts_insert(Conn, Table, Columns, Data) ->
TermFn = fun insert_term_format/2,
ColClause = string:strip(lists:foldl(ColFn, [], Columns), right, $,),
ValClause = string:strip(lists:foldl(TermFn, [], tuple_to_list(Data)), right, $,),
SQL = flat_format("INSERT INTO ~s (~s) VALUES (~s)",
SQL = flat_format("INSERT INTO ~s (~s) VALUES (~ts)",
[Table, ColClause, ValClause]),
lager:info("~ts", [SQL]),
Got = riakc_ts:query(Conn, SQL),
@ -150,7 +150,7 @@ ts_insert(Conn, Table, Columns, Data) ->
ts_insert_no_columns(Conn, Table, Data) ->
TermFn = fun insert_term_format/2,
ValClause = string:strip(lists:foldl(TermFn, [], tuple_to_list(Data)), right, $,),
SQL = flat_format("INSERT INTO ~s VALUES (~s)",
SQL = flat_format("INSERT INTO ~s VALUES (~ts)",
[Table, ValClause]),
lager:info("~ts", [SQL]),
Got = riakc_ts:query(Conn, SQL),
@ -505,7 +505,8 @@ get_integer() ->
get_s(0, Acc) ->
Acc;
get_s(N, Acc) when is_integer(N) andalso N > 0 ->
get_s(N - 1, [random:uniform(255) | Acc]).
%% make it plain ASCII
get_s(N - 1, [crypto:rand_uniform($a, $z) | Acc]).
get_timestamp() ->
random:uniform(?MAXTIMESTAMP).