From ecffe5af7d4652ab953e2c085b23d644849883bb Mon Sep 17 00:00:00 2001 From: gayyappan Date: Fri, 18 Sep 2020 14:19:59 -0400 Subject: [PATCH] Add test for dimensions view Create more than 2 dimensions and verify that dimensions view displays information correctly. --- tsl/test/expected/dist_views.out | 16 +++++++++++----- tsl/test/sql/dist_views.sql | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tsl/test/expected/dist_views.out b/tsl/test/expected/dist_views.out index 3b3396340..552cb16d0 100644 --- a/tsl/test/expected/dist_views.out +++ b/tsl/test/expected/dist_views.out @@ -39,15 +39,20 @@ SELECT setseed(1); (1 row) -CREATE TABLE dist_table(time timestamptz, device int, temp float); +CREATE TABLE dist_table(time timestamptz NOT NULL, device int, temp float, timedim date NOT NULL); SELECT create_distributed_hypertable('dist_table', 'time', 'device', replication_factor => 2); -NOTICE: adding not-null constraint to column "time" create_distributed_hypertable ------------------------------- (1,public,dist_table,t) (1 row) -INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 80 +SELECT add_dimension('dist_table', 'timedim', chunk_time_interval=>'7 days'::interval); + add_dimension +--------------------------------- + (3,public,dist_table,timedim,t) +(1 row) + +INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 80, '2020-01-01' FROM generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-04 1:00', '1 hour') t; ALTER TABLE dist_table SET (timescaledb.compress, timescaledb.compress_segmentby='device', timescaledb.compress_orderby = 'time DESC'); -- Test views with compression @@ -65,7 +70,7 @@ SELECT * FROM timescaledb_information.hypertables WHERE table_name = 'dist_table'; table_schema | table_name | owner | num_dimensions | num_chunks | compression_enabled | is_distributed | replication_factor | data_nodes | tablespaces --------------+------------+-------------+----------------+------------+---------------------+----------------+--------------------+---------------------------------------+------------- - public | dist_table | test_role_1 | 2 | 3 | f | t | 2 | {view_node_1,view_node_2,view_node_3} | + public | dist_table | test_role_1 | 3 | 3 | f | t | 2 | {view_node_1,view_node_2,view_node_3} | (1 row) SELECT * from timescaledb_information.chunks @@ -83,7 +88,8 @@ ORDER BY hypertable_name, dimension_number; -------------------+-----------------+------------------+-------------+--------------------------+----------------+---------------+------------------+------------------+---------------- public | dist_table | 1 | time | timestamp with time zone | Time | @ 7 days | | | public | dist_table | 2 | device | integer | Space | | | | 3 -(2 rows) + public | dist_table | 3 | timedim | date | Time | @ 7 days | | | +(3 rows) SELECT * FROM chunks_detailed_size('dist_table'::regclass) ORDER BY chunk_name, node_name; diff --git a/tsl/test/sql/dist_views.sql b/tsl/test/sql/dist_views.sql index e6124ca77..dfb866259 100644 --- a/tsl/test/sql/dist_views.sql +++ b/tsl/test/sql/dist_views.sql @@ -23,9 +23,10 @@ SET client_min_messages TO NOTICE; SET ROLE :ROLE_1; SELECT setseed(1); -CREATE TABLE dist_table(time timestamptz, device int, temp float); +CREATE TABLE dist_table(time timestamptz NOT NULL, device int, temp float, timedim date NOT NULL); SELECT create_distributed_hypertable('dist_table', 'time', 'device', replication_factor => 2); -INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 80 +SELECT add_dimension('dist_table', 'timedim', chunk_time_interval=>'7 days'::interval); +INSERT INTO dist_table SELECT t, (abs(timestamp_hash(t::timestamp)) % 10) + 1, 80, '2020-01-01' FROM generate_series('2018-03-02 1:00'::TIMESTAMPTZ, '2018-03-04 1:00', '1 hour') t; ALTER TABLE dist_table SET (timescaledb.compress, timescaledb.compress_segmentby='device', timescaledb.compress_orderby = 'time DESC');