diff --git a/src/test/regress/expected/timeseries_get_missing_partition_ranges.out b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out new file mode 100644 index 000000000..f454cd1e1 --- /dev/null +++ b/src/test/regress/expected/timeseries_get_missing_partition_ranges.out @@ -0,0 +1,364 @@ +-- Show get_missing_partition_ranges function can be only callede for timeseries tables +CREATE TABLE date_partitioned_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); +SELECT get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); +ERROR: date_partitioned_table must be timeseries table +CONTEXT: PL/pgSQL function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) line XX at RAISE +-- Show range values for data partitioned table +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 8 days ago | @ 9 days ago + @ 9 days ago | @ 10 days ago + @ 10 days ago | @ 11 days ago + @ 11 days ago | @ 12 days ago + @ 12 days ago | @ 13 days ago + @ 13 days ago | @ 14 days ago + @ 14 days ago | @ 15 days ago + @ 15 days ago | @ 16 days ago +(8 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 15 days | @ 14 days + @ 14 days | @ 13 days + @ 13 days | @ 12 days + @ 12 days | @ 11 days + @ 11 days | @ 10 days + @ 10 days | @ 9 days + @ 9 days | @ 8 days + @ 8 days | @ 7 days + @ 8 days ago | @ 9 days ago + @ 9 days ago | @ 10 days ago + @ 10 days ago | @ 11 days ago + @ 11 days ago | @ 12 days ago + @ 12 days ago | @ 13 days ago + @ 13 days ago | @ 14 days ago + @ 14 days ago | @ 15 days ago + @ 15 days ago | @ 16 days ago +(16 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 45 days | @ 40 days + @ 40 days | @ 35 days + @ 40 days ago | @ 45 days ago + @ 45 days ago | @ 50 days ago +(4 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('week', now()) - range_from_value::date as from_diff, + date_trunc('week', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 63 days | @ 56 days + @ 56 days | @ 49 days + @ 56 days ago | @ 63 days ago + @ 63 days ago | @ 70 days ago +(4 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + from_diff | to_diff +--------------------------------------------------------------------- +(0 rows) + +ROLLBACK; +DROP TABLE date_partitioned_table; +-- Show range values for timestamptz partitioned table +CREATE TABLE tstz_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 8 hours ago | @ 9 hours ago + @ 9 hours ago | @ 10 hours ago + @ 10 hours ago | @ 11 hours ago + @ 11 hours ago | @ 12 hours ago + @ 12 hours ago | @ 13 hours ago + @ 13 hours ago | @ 14 hours ago + @ 14 hours ago | @ 15 hours ago + @ 15 hours ago | @ 16 hours ago + @ 16 hours ago | @ 17 hours ago + @ 17 hours ago | @ 18 hours ago + @ 18 hours ago | @ 19 hours ago + @ 19 hours ago | @ 20 hours ago + @ 20 hours ago | @ 21 hours ago + @ 21 hours ago | @ 22 hours ago + @ 22 hours ago | @ 23 hours ago + @ 23 hours ago | @ 1 day ago + @ 1 day ago | @ 1 day 1 hour ago +(17 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day | @ 23 hours + @ 23 hours | @ 22 hours + @ 22 hours | @ 21 hours + @ 21 hours | @ 20 hours + @ 20 hours | @ 19 hours + @ 19 hours | @ 18 hours + @ 18 hours | @ 17 hours + @ 17 hours | @ 16 hours + @ 16 hours | @ 15 hours + @ 15 hours | @ 14 hours + @ 14 hours | @ 13 hours + @ 13 hours | @ 12 hours + @ 12 hours | @ 11 hours + @ 11 hours | @ 10 hours + @ 10 hours | @ 9 hours + @ 9 hours | @ 8 hours + @ 8 hours | @ 7 hours + @ 8 hours ago | @ 9 hours ago + @ 9 hours ago | @ 10 hours ago + @ 10 hours ago | @ 11 hours ago + @ 11 hours ago | @ 12 hours ago + @ 12 hours ago | @ 13 hours ago + @ 13 hours ago | @ 14 hours ago + @ 14 hours ago | @ 15 hours ago + @ 15 hours ago | @ 16 hours ago + @ 16 hours ago | @ 17 hours ago + @ 17 hours ago | @ 18 hours ago + @ 18 hours ago | @ 19 hours ago + @ 19 hours ago | @ 20 hours ago + @ 20 hours ago | @ 21 hours ago + @ 21 hours ago | @ 22 hours ago + @ 22 hours ago | @ 23 hours ago + @ 23 hours ago | @ 1 day ago + @ 1 day ago | @ 1 day 1 hour ago +(34 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- +(0 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + from_diff | to_diff +--------------------------------------------------------------------- +(0 rows) + +ROLLBACK; +DROP TABLE tstz_partitioned_table; +-- Show range values for timestamp without time zone partitioned table +CREATE TABLE tswtz_partitioned_table( + measureid integer, + eventdatetime timestamp without time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 8 hours ago | @ 9 hours ago + @ 9 hours ago | @ 10 hours ago + @ 10 hours ago | @ 11 hours ago + @ 11 hours ago | @ 12 hours ago + @ 12 hours ago | @ 13 hours ago + @ 13 hours ago | @ 14 hours ago + @ 14 hours ago | @ 15 hours ago + @ 15 hours ago | @ 16 hours ago + @ 16 hours ago | @ 17 hours ago + @ 17 hours ago | @ 18 hours ago + @ 18 hours ago | @ 19 hours ago + @ 19 hours ago | @ 20 hours ago + @ 20 hours ago | @ 21 hours ago + @ 21 hours ago | @ 22 hours ago + @ 22 hours ago | @ 23 hours ago + @ 23 hours ago | @ 1 day ago + @ 1 day ago | @ 1 day 1 hour ago +(17 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- + @ 1 day | @ 23 hours + @ 23 hours | @ 22 hours + @ 22 hours | @ 21 hours + @ 21 hours | @ 20 hours + @ 20 hours | @ 19 hours + @ 19 hours | @ 18 hours + @ 18 hours | @ 17 hours + @ 17 hours | @ 16 hours + @ 16 hours | @ 15 hours + @ 15 hours | @ 14 hours + @ 14 hours | @ 13 hours + @ 13 hours | @ 12 hours + @ 12 hours | @ 11 hours + @ 11 hours | @ 10 hours + @ 10 hours | @ 9 hours + @ 9 hours | @ 8 hours + @ 8 hours | @ 7 hours + @ 8 hours ago | @ 9 hours ago + @ 9 hours ago | @ 10 hours ago + @ 10 hours ago | @ 11 hours ago + @ 11 hours ago | @ 12 hours ago + @ 12 hours ago | @ 13 hours ago + @ 13 hours ago | @ 14 hours ago + @ 14 hours ago | @ 15 hours ago + @ 15 hours ago | @ 16 hours ago + @ 16 hours ago | @ 17 hours ago + @ 17 hours ago | @ 18 hours ago + @ 18 hours ago | @ 19 hours ago + @ 19 hours ago | @ 20 hours ago + @ 20 hours ago | @ 21 hours ago + @ 21 hours ago | @ 22 hours ago + @ 22 hours ago | @ 23 hours ago + @ 23 hours ago | @ 1 day ago + @ 1 day ago | @ 1 day 1 hour ago +(34 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); + from_diff | to_diff +--------------------------------------------------------------------- +(0 rows) + +ROLLBACK; +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); + create_timeseries_table +--------------------------------------------------------------------- + +(1 row) + +SELECT + date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); + from_diff | to_diff +--------------------------------------------------------------------- +(0 rows) + +ROLLBACK; +DROP TABLE tswtz_partitioned_table; \ No newline at end of file diff --git a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql new file mode 100644 index 000000000..288e5d16d --- /dev/null +++ b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql @@ -0,0 +1,128 @@ +-- Show get_missing_partition_ranges function can be only callede for timeseries tables +CREATE TABLE date_partitioned_table( + measureid integer, + eventdate date, + measure_data integer) PARTITION BY RANGE(eventdate); + +SELECT get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); + +-- Show range values for data partitioned table +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); +SELECT + date_trunc('week', now()) - range_from_value::date as from_diff, + date_trunc('week', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); +SELECT + date_trunc('day', now()) - range_from_value::date as from_diff, + date_trunc('day', now()) - range_to_value::date as to_diff +FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); +ROLLBACK; + +DROP TABLE date_partitioned_table; + +-- Show range values for timestamptz partitioned table +CREATE TABLE tstz_partitioned_table( + measureid integer, + eventdatetime timestamp with time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); +SELECT + date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff +FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); +ROLLBACK; + +DROP TABLE tstz_partitioned_table; + +-- Show range values for timestamp without time zone partitioned table +CREATE TABLE tswtz_partitioned_table( + measureid integer, + eventdatetime timestamp without time zone, + measure_data integer) PARTITION BY RANGE(eventdatetime); +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); +SELECT + date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); +ROLLBACK; + +BEGIN; +SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); +SELECT + date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, + date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff +FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); +ROLLBACK; + +DROP TABLE tswtz_partitioned_table; diff --git a/src/test/regress/timeseries_schedule b/src/test/regress/timeseries_schedule index db58a12a2..976997ac7 100644 --- a/src/test/regress/timeseries_schedule +++ b/src/test/regress/timeseries_schedule @@ -3,3 +3,4 @@ test: multi_test_helpers multi_test_helpers_superuser test: multi_test_catalog_views test: timeseries_create_drop_timeseries_table +test: timeseries_get_missing_partition_ranges \ No newline at end of file