Skip to content

Commit

Permalink
Add tests for calling functions with NULL arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
svenklemm authored and RobAtticus committed Dec 4, 2018
1 parent cab079e commit 5e0d1cf
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/expected/chunk_adaptive.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ SELECT * FROM test.set_memory_cache_size('2GB');
2147483648
(1 row)

-- test NULL handling
\set ON_ERROR_STOP 0
SELECT * FROM set_adaptive_chunking(NULL,NULL);
ERROR: invalid hypertable: cannot be NULL
\set ON_ERROR_STOP 1
CREATE TABLE test_adaptive(time timestamptz, temp float, location int);
\set ON_ERROR_STOP 0
-- Bad signature of sizing func should fail
Expand Down
2 changes: 2 additions & 0 deletions test/expected/create_chunks.out
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ ORDER BY d.id;
(2 rows)

\set ON_ERROR_STOP 0
select set_chunk_time_interval(NULL,NULL::interval);
ERROR: invalid main_table: cannot be NULL
-- should fail since time column is an int
SELECT set_chunk_time_interval('chunk_test', INTERVAL '1 minute');
ERROR: invalid interval: must be an integer type for integer dimensions
Expand Down
16 changes: 16 additions & 0 deletions test/expected/ddl_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ CREATE TABLE PUBLIC."Hypertable_1" (
);
CREATE INDEX ON PUBLIC."Hypertable_1" (time, "Device_id");
\set ON_ERROR_STOP 0
SELECT * FROM create_hypertable(NULL, NULL);
ERROR: invalid main_table: cannot be NULL
SELECT * FROM create_hypertable('"public"."Hypertable_1"', NULL);
ERROR: invalid time_column_name: cannot be NULL
SELECT * FROM create_hypertable('"public"."Hypertable_1_mispelled"', 'time', 'Device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
ERROR: relation "public.Hypertable_1_mispelled" does not exist at character 33
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time_mispelled', 'Device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
Expand Down Expand Up @@ -122,4 +126,16 @@ SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_ti
\set ON_ERROR_STOP 0
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
ERROR: hypertables do not support rules
\set ON_ERROR_STOP 1
\set ON_ERROR_STOP 0
SELECT add_dimension(NULL,NULL);
ERROR: invalid main_table: cannot be NULL
\set ON_ERROR_STOP 1
\set ON_ERROR_STOP 0
SELECT attach_tablespace(NULL,NULL);
ERROR: invalid tablespace name
\set ON_ERROR_STOP 1
\set ON_ERROR_STOP 0
select set_number_partitions(NULL,NULL);
ERROR: invalid main_table: cannot be NULL
\set ON_ERROR_STOP 1
4 changes: 4 additions & 0 deletions test/expected/drop_chunks.out
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ CREATE VIEW dependent_view AS SELECT * FROM _timescaledb_internal._hyper_1_1_chu
\set ON_ERROR_STOP 0
SELECT drop_chunks(2);
ERROR: cannot drop table _timescaledb_internal._hyper_1_1_chunk because other objects depend on it
SELECT drop_chunks(NULL::interval);
ERROR: can only use drop_chunks with an INTERVAL for TIMESTAMP, TIMESTAMPTZ, and DATE types
SELECT drop_chunks(NULL::int);
ERROR: the timestamp provided to drop_chunks cannot be NULL
\set ON_ERROR_STOP 1
-- show created constraints and dimension slices for each chunk
SELECT c.table_name, cc.constraint_name, ds.id AS dimension_slice_id, ds.range_start, ds.range_end
Expand Down
40 changes: 40 additions & 0 deletions test/expected/size_utils.out
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,43 @@ SELECT * FROM hypertable_approximate_row_count();
public | two_Partitions | 0
(5 rows)

SELECT * FROM hypertable_approximate_row_count(NULL);
schema_name | table_name | row_estimate
-------------+-------------------------+--------------
public | approx_count | 10
public | timestamp_partitioned | 0
public | timestamp_partitioned_2 | 0
public | toast_test | 0
public | two_Partitions | 0
(5 rows)

SELECT * FROM chunk_relation_size(NULL);
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_bytes | index_bytes | toast_bytes | total_bytes
----------+-------------+----------------------+---------------------------+-----------------------------+--------+-------------+-------------+-------------+-------------
(0 rows)

SELECT * FROM chunk_relation_size_pretty(NULL);
chunk_id | chunk_table | partitioning_columns | partitioning_column_types | partitioning_hash_functions | ranges | table_size | index_size | toast_size | total_size
----------+-------------+----------------------+---------------------------+-----------------------------+--------+------------+------------+------------+------------
(0 rows)

SELECT * FROM hypertable_relation_size(NULL);
table_bytes | index_bytes | toast_bytes | total_bytes
-------------+-------------+-------------+-------------
(0 rows)

SELECT * FROM hypertable_relation_size_pretty(NULL);
table_size | index_size | toast_size | total_size
------------+------------+------------+------------
(0 rows)

SELECT * FROM indexes_relation_size(NULL);
index_name | total_bytes
------------+-------------
(0 rows)

SELECT * FROM indexes_relation_size_pretty(NULL);
index_name | total_size
------------+------------
(0 rows)

11 changes: 11 additions & 0 deletions test/expected/tablespace.out
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ INNER JOIN _timescaledb_catalog.chunk ch ON (ch.table_name = c.relname);
(1 row)

--check some error conditions
SELECT attach_tablespace(NULL,NULL);
ERROR: invalid tablespace name
SELECT attach_tablespace('tablespace2', NULL);
ERROR: invalid hypertable
SELECT attach_tablespace(NULL, 'tspace_2dim');
Expand All @@ -39,6 +41,15 @@ SELECT attach_tablespace('none_existing_tablespace', 'tspace_2dim');
ERROR: tablespace "none_existing_tablespace" does not exist
SELECT attach_tablespace('tablespace2', 'none_existing_table');
ERROR: relation "none_existing_table" does not exist at character 41
SELECT detach_tablespace(NULL);
ERROR: invalid tablespace name
SELECT detach_tablespaces(NULL);
ERROR: invalid argument
SELECT show_tablespaces(NULL);
show_tablespaces
------------------
(0 rows)

--attach another tablespace without first creating it --> should generate error
SELECT attach_tablespace('tablespace2', 'tspace_2dim');
ERROR: tablespace "tablespace2" does not exist
Expand Down
5 changes: 5 additions & 0 deletions test/sql/chunk_adaptive.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ $BODY$;
-- (independent of available machine memory)
SELECT * FROM test.set_memory_cache_size('2GB');

-- test NULL handling
\set ON_ERROR_STOP 0
SELECT * FROM set_adaptive_chunking(NULL,NULL);
\set ON_ERROR_STOP 1

CREATE TABLE test_adaptive(time timestamptz, temp float, location int);

\set ON_ERROR_STOP 0
Expand Down
1 change: 1 addition & 0 deletions test/sql/create_chunks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ WHERE h.schema_name = 'public' AND h.table_name = 'chunk_test2'
ORDER BY d.id;

\set ON_ERROR_STOP 0
select set_chunk_time_interval(NULL,NULL::interval);
-- should fail since time column is an int
SELECT set_chunk_time_interval('chunk_test', INTERVAL '1 minute');
-- should fail since its not a valid way to represent time
Expand Down
1 change: 1 addition & 0 deletions test/sql/create_hypertable.sql
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,4 @@ select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func

-- A valid function should work:
select add_dimension('test_schema.test_partfunc', 'device', 2, partitioning_func => 'partfunc_valid');

14 changes: 14 additions & 0 deletions test/sql/ddl_errors.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ CREATE TABLE PUBLIC."Hypertable_1" (
CREATE INDEX ON PUBLIC."Hypertable_1" (time, "Device_id");

\set ON_ERROR_STOP 0
SELECT * FROM create_hypertable(NULL, NULL);
SELECT * FROM create_hypertable('"public"."Hypertable_1"', NULL);
SELECT * FROM create_hypertable('"public"."Hypertable_1_mispelled"', 'time', 'Device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'time_mispelled', 'Device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
SELECT * FROM create_hypertable('"public"."Hypertable_1"', 'Device_id', 'Device_id', 2, chunk_time_interval=>_timescaledb_internal.interval_to_usec('1 month'));
Expand Down Expand Up @@ -115,4 +117,16 @@ SELECT * FROM create_hypertable('"public"."Hypertable_1_rule"', 'time', chunk_ti

\set ON_ERROR_STOP 0
CREATE RULE notify_me AS ON UPDATE TO "Hypertable_1_rule" DO ALSO NOTIFY "Hypertable_1_rule";
\set ON_ERROR_STOP 1

\set ON_ERROR_STOP 0
SELECT add_dimension(NULL,NULL);
\set ON_ERROR_STOP 1

\set ON_ERROR_STOP 0
SELECT attach_tablespace(NULL,NULL);
\set ON_ERROR_STOP 1

\set ON_ERROR_STOP 0
select set_number_partitions(NULL,NULL);
\set ON_ERROR_STOP 1
2 changes: 2 additions & 0 deletions test/sql/drop_chunks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ CREATE VIEW dependent_view AS SELECT * FROM _timescaledb_internal._hyper_1_1_chu

\set ON_ERROR_STOP 0
SELECT drop_chunks(2);
SELECT drop_chunks(NULL::interval);
SELECT drop_chunks(NULL::int);
\set ON_ERROR_STOP 1

-- show created constraints and dimension slices for each chunk
Expand Down
9 changes: 9 additions & 0 deletions test/sql/size_utils.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ SELECT * FROM hypertable_approximate_row_count('approx_count');

-- all hypertables
SELECT * FROM hypertable_approximate_row_count();
SELECT * FROM hypertable_approximate_row_count(NULL);

SELECT * FROM chunk_relation_size(NULL);
SELECT * FROM chunk_relation_size_pretty(NULL);
SELECT * FROM hypertable_relation_size(NULL);
SELECT * FROM hypertable_relation_size_pretty(NULL);
SELECT * FROM indexes_relation_size(NULL);
SELECT * FROM indexes_relation_size_pretty(NULL);

4 changes: 4 additions & 0 deletions test/sql/tablespace.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ INNER JOIN pg_tablespace t ON (c.reltablespace = t.oid)
INNER JOIN _timescaledb_catalog.chunk ch ON (ch.table_name = c.relname);

--check some error conditions
SELECT attach_tablespace(NULL,NULL);
SELECT attach_tablespace('tablespace2', NULL);
SELECT attach_tablespace(NULL, 'tspace_2dim');
SELECT attach_tablespace('none_existing_tablespace', 'tspace_2dim');
SELECT attach_tablespace('tablespace2', 'none_existing_table');
SELECT detach_tablespace(NULL);
SELECT detach_tablespaces(NULL);
SELECT show_tablespaces(NULL);

--attach another tablespace without first creating it --> should generate error
SELECT attach_tablespace('tablespace2', 'tspace_2dim');
Expand Down

0 comments on commit 5e0d1cf

Please sign in to comment.