diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 9fc107a4acb..9492c40f9bc 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -51,6 +51,9 @@ set(SOURCE_FILES restoring.sql timescaledb_fdw.sql remote_txn.sql + job_api.sql + policy_api.sql + policy_internal.sql ) # These files should be pre-pended to update scripts so that they are diff --git a/sql/bgw_scheduler.sql b/sql/bgw_scheduler.sql index 5cdc841406b..039332b1cf0 100644 --- a/sql/bgw_scheduler.sql +++ b/sql/bgw_scheduler.sql @@ -20,96 +20,3 @@ LANGUAGE C VOLATILE; INSERT INTO _timescaledb_config.bgw_job (id, application_name, schedule_interval, max_runtime, max_retries, retry_period, proc_schema, proc_name, owner, scheduled) VALUES (1, 'Telemetry Reporter [1]', INTERVAL '24h', INTERVAL '100s', -1, INTERVAL '1h', '_timescaledb_internal', 'policy_telemetry', CURRENT_ROLE, true) ON CONFLICT (id) DO NOTHING; - -CREATE OR REPLACE FUNCTION add_job( - proc REGPROC, - schedule_interval INTERVAL, - config JSONB DEFAULT NULL, - initial_start TIMESTAMPTZ DEFAULT NULL, - scheduled BOOL DEFAULT true -) RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_job_add' LANGUAGE C VOLATILE; - -CREATE OR REPLACE FUNCTION delete_job(job_id INTEGER) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_job_delete' LANGUAGE C VOLATILE STRICT; -CREATE OR REPLACE PROCEDURE run_job(job_id INTEGER) AS '@MODULE_PATHNAME@', 'ts_job_run' LANGUAGE C; - --- Add a retention policy to a hypertable or continuous aggregate. --- The retention_window (typically an INTERVAL) determines the --- window beyond which data is dropped at the time --- of execution of the policy (e.g., '1 week'). Note that the retention --- window will always align with chunk boundaries, thus the window --- might be larger than the given one, but never smaller. In other --- words, some data beyond the retention window --- might be kept, but data within the window will never be deleted. -CREATE OR REPLACE FUNCTION add_retention_policy( - hypertable REGCLASS, - retention_window "any", - if_not_exists BOOL = false -) -RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_policy_retention_add' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE FUNCTION remove_retention_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID -AS '@MODULE_PATHNAME@', 'ts_policy_retention_remove' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_retention(job_id INTEGER, config JSONB) -AS '@MODULE_PATHNAME@', 'ts_policy_retention_proc' -LANGUAGE C; - -/* reorder policy */ -CREATE OR REPLACE FUNCTION add_reorder_policy(hypertable REGCLASS, index_name NAME, if_not_exists BOOL = false) RETURNS INTEGER -AS '@MODULE_PATHNAME@', 'ts_policy_reorder_add' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE FUNCTION remove_reorder_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID -AS '@MODULE_PATHNAME@', 'ts_policy_reorder_remove' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_reorder(job_id INTEGER, config JSONB) -AS '@MODULE_PATHNAME@', 'ts_policy_reorder_proc' -LANGUAGE C; - -/* compression policy */ -CREATE OR REPLACE FUNCTION add_compression_policy(hypertable REGCLASS, older_than "any", if_not_exists BOOL = false) -RETURNS INTEGER -AS '@MODULE_PATHNAME@', 'ts_policy_compression_add' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE FUNCTION remove_compression_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS BOOL -AS '@MODULE_PATHNAME@', 'ts_policy_compression_remove' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_compression(job_id INTEGER, config JSONB) -AS '@MODULE_PATHNAME@', 'ts_policy_compression_proc' -LANGUAGE C; - -/* continuous aggregates policy */ -CREATE OR REPLACE FUNCTION add_refresh_continuous_aggregate_policy(continuous_aggregate REGCLASS, start_interval "any", end_interval "any" , schedule_interval INTERVAL, if_not_exists BOOL = false) -RETURNS INTEGER -AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_add' -LANGUAGE C VOLATILE ; - -CREATE OR REPLACE FUNCTION remove_refresh_continuous_aggregate_policy(continuous_aggregate REGCLASS, if_not_exists BOOL = false) -RETURNS VOID -AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_remove' -LANGUAGE C VOLATILE STRICT; - -CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_refresh_continuous_aggregate(job_id INTEGER, config JSONB) -AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_proc' -LANGUAGE C; - --- Returns the updated job schedule values -CREATE OR REPLACE FUNCTION alter_job( - job_id INTEGER, - schedule_interval INTERVAL = NULL, - max_runtime INTERVAL = NULL, - max_retries INTEGER = NULL, - retry_period INTERVAL = NULL, - scheduled BOOL = NULL, - config JSONB = NULL, - next_start TIMESTAMPTZ = NULL, - if_exists BOOL = FALSE -) -RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, next_start TIMESTAMPTZ) -AS '@MODULE_PATHNAME@', 'ts_job_alter' -LANGUAGE C VOLATILE; diff --git a/sql/job_api.sql b/sql/job_api.sql new file mode 100644 index 00000000000..e8aa2017362 --- /dev/null +++ b/sql/job_api.sql @@ -0,0 +1,30 @@ +-- This file and its contents are licensed under the Apache License 2.0. +-- Please see the included NOTICE for copyright information and +-- LICENSE-APACHE for a copy of the license. + +CREATE OR REPLACE FUNCTION add_job( + proc REGPROC, + schedule_interval INTERVAL, + config JSONB DEFAULT NULL, + initial_start TIMESTAMPTZ DEFAULT NULL, + scheduled BOOL DEFAULT true +) RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_job_add' LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION delete_job(job_id INTEGER) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_job_delete' LANGUAGE C VOLATILE STRICT; +CREATE OR REPLACE PROCEDURE run_job(job_id INTEGER) AS '@MODULE_PATHNAME@', 'ts_job_run' LANGUAGE C; + +-- Returns the updated job schedule values +CREATE OR REPLACE FUNCTION alter_job( + job_id INTEGER, + schedule_interval INTERVAL = NULL, + max_runtime INTERVAL = NULL, + max_retries INTEGER = NULL, + retry_period INTERVAL = NULL, + scheduled BOOL = NULL, + config JSONB = NULL, + next_start TIMESTAMPTZ = NULL, + if_exists BOOL = FALSE +) +RETURNS TABLE (job_id INTEGER, schedule_interval INTERVAL, max_runtime INTERVAL, max_retries INTEGER, retry_period INTERVAL, scheduled BOOL, config JSONB, next_start TIMESTAMPTZ) +AS '@MODULE_PATHNAME@', 'ts_job_alter' +LANGUAGE C VOLATILE; diff --git a/sql/policy_api.sql b/sql/policy_api.sql new file mode 100644 index 00000000000..4dc9674b395 --- /dev/null +++ b/sql/policy_api.sql @@ -0,0 +1,53 @@ +-- This file and its contents are licensed under the Apache License 2.0. +-- Please see the included NOTICE for copyright information and +-- LICENSE-APACHE for a copy of the license. + +-- Add a retention policy to a hypertable or continuous aggregate. +-- The retention_window (typically an INTERVAL) determines the +-- window beyond which data is dropped at the time +-- of execution of the policy (e.g., '1 week'). Note that the retention +-- window will always align with chunk boundaries, thus the window +-- might be larger than the given one, but never smaller. In other +-- words, some data beyond the retention window +-- might be kept, but data within the window will never be deleted. +CREATE OR REPLACE FUNCTION add_retention_policy( + hypertable REGCLASS, + retention_window "any", + if_not_exists BOOL = false +) +RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_policy_retention_add' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_retention_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID +AS '@MODULE_PATHNAME@', 'ts_policy_retention_remove' +LANGUAGE C VOLATILE STRICT; + +/* reorder policy */ +CREATE OR REPLACE FUNCTION add_reorder_policy(hypertable REGCLASS, index_name NAME, if_not_exists BOOL = false) RETURNS INTEGER +AS '@MODULE_PATHNAME@', 'ts_policy_reorder_add' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_reorder_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID +AS '@MODULE_PATHNAME@', 'ts_policy_reorder_remove' +LANGUAGE C VOLATILE STRICT; + +/* compression policy */ +CREATE OR REPLACE FUNCTION add_compression_policy(hypertable REGCLASS, older_than "any", if_not_exists BOOL = false) +RETURNS INTEGER +AS '@MODULE_PATHNAME@', 'ts_policy_compression_add' +LANGUAGE C VOLATILE STRICT; + +CREATE OR REPLACE FUNCTION remove_compression_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS BOOL +AS '@MODULE_PATHNAME@', 'ts_policy_compression_remove' +LANGUAGE C VOLATILE STRICT; + +/* continuous aggregates policy */ +CREATE OR REPLACE FUNCTION add_continuous_aggregate_policy(continuous_aggregate REGCLASS, start_interval "any", end_interval "any", schedule_interval INTERVAL, if_not_exists BOOL = false) +RETURNS INTEGER +AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_add' +LANGUAGE C VOLATILE; + +CREATE OR REPLACE FUNCTION remove_continuous_aggregate_policy(continuous_aggregate REGCLASS, if_not_exists BOOL = false) +RETURNS VOID +AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_remove' +LANGUAGE C VOLATILE STRICT; diff --git a/sql/policy_internal.sql b/sql/policy_internal.sql new file mode 100644 index 00000000000..c8ae3c28ae4 --- /dev/null +++ b/sql/policy_internal.sql @@ -0,0 +1,19 @@ +-- This file and its contents are licensed under the Apache License 2.0. +-- Please see the included NOTICE for copyright information and +-- LICENSE-APACHE for a copy of the license. + +CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_retention(job_id INTEGER, config JSONB) +AS '@MODULE_PATHNAME@', 'ts_policy_retention_proc' +LANGUAGE C; + +CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_reorder(job_id INTEGER, config JSONB) +AS '@MODULE_PATHNAME@', 'ts_policy_reorder_proc' +LANGUAGE C; + +CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_compression(job_id INTEGER, config JSONB) +AS '@MODULE_PATHNAME@', 'ts_policy_compression_proc' +LANGUAGE C; + +CREATE OR REPLACE PROCEDURE _timescaledb_internal.policy_refresh_continuous_aggregate(job_id INTEGER, config JSONB) +AS '@MODULE_PATHNAME@', 'ts_policy_refresh_cagg_proc' +LANGUAGE C; diff --git a/test/expected/extension.out b/test/expected/extension.out index 9646a8e2954..b62311fa4cb 100644 --- a/test/expected/extension.out +++ b/test/expected/extension.out @@ -17,13 +17,13 @@ WHERE oid IN ( AND classid = 'pg_catalog.pg_proc'::regclass) AND pronamespace = 'public'::regnamespace ORDER BY proname; - proname --------------------------------------------- + proname +------------------------------------ add_compression_policy + add_continuous_aggregate_policy add_data_node add_dimension add_job - add_refresh_continuous_aggregate_policy add_reorder_policy add_retention_policy allow_new_chunks @@ -58,7 +58,7 @@ WHERE oid IN ( move_chunk refresh_continuous_aggregate remove_compression_policy - remove_refresh_continuous_aggregate_policy + remove_continuous_aggregate_policy remove_reorder_policy remove_retention_policy reorder_chunk diff --git a/test/sql/updates/setup.continuous_aggs.sql b/test/sql/updates/setup.continuous_aggs.sql index 2bcb23ed556..36cc55ad64f 100644 --- a/test/sql/updates/setup.continuous_aggs.sql +++ b/test/sql/updates/setup.continuous_aggs.sql @@ -119,7 +119,7 @@ BEGIN FROM conditions_before GROUP BY bucket, location HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA; - PERFORM add_refresh_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h'); + PERFORM add_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h'); END IF; END $$; diff --git a/test/sql/updates/setup.continuous_aggs.v2.sql b/test/sql/updates/setup.continuous_aggs.v2.sql index c39745d736d..601c1054af4 100644 --- a/test/sql/updates/setup.continuous_aggs.v2.sql +++ b/test/sql/updates/setup.continuous_aggs.v2.sql @@ -120,7 +120,7 @@ BEGIN FROM conditions_before GROUP BY bucket, location HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA; - PERFORM add_refresh_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h'); + PERFORM add_continuous_aggregate_policy('mat_before', NULL, '-30 days'::interval, '336 h'); END IF; END $$; @@ -225,7 +225,7 @@ BEGIN FROM conditions_before GROUP BY bucket, location HAVING min(location) >= 'NYC' and avg(temperature) > 2 WITH NO DATA; - PERFORM add_refresh_continuous_aggregate_policy('cagg.realtime_mat', NULL, '-30 days'::interval, '336 h'); + PERFORM add_continuous_aggregate_policy('cagg.realtime_mat', NULL, '-30 days'::interval, '336 h'); END IF; END $$; diff --git a/tsl/test/expected/compression_ddl.out b/tsl/test/expected/compression_ddl.out index f5da686392b..31fa86320e9 100644 --- a/tsl/test/expected/compression_ddl.out +++ b/tsl/test/expected/compression_ddl.out @@ -509,10 +509,10 @@ CREATE MATERIALIZED VIEW test1_cont_view WITH (timescaledb.continuous, timescale AS SELECT time_bucket('1 hour', "Time"), SUM(i) FROM test1 GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test1_cont_view', NULL, '1 hour'::interval, '1 day'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1001 +SELECT add_continuous_aggregate_policy('test1_cont_view', NULL, '1 hour'::interval, '1 day'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1001 (1 row) REFRESH MATERIALIZED VIEW test1_cont_view; diff --git a/tsl/test/expected/continuous_aggs.out b/tsl/test/expected/continuous_aggs.out index 412c16f6ef1..22435239632 100644 --- a/tsl/test/expected/continuous_aggs.out +++ b/tsl/test/expected/continuous_aggs.out @@ -49,10 +49,10 @@ select a, count(b) from foo group by time_bucket(1, a), a WITH NO DATA; NOTICE: adding index _materialized_hypertable_2_a_time_partition_col_idx ON _timescaledb_internal._materialized_hypertable_2 USING BTREE(a, time_partition_col) -SELECT add_refresh_continuous_aggregate_policy('mat_m1', NULL, 2::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1000 +SELECT add_continuous_aggregate_policy('mat_m1', NULL, 2::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1000 (1 row) SELECT * FROM _timescaledb_config.bgw_job; @@ -868,10 +868,10 @@ group by time_bucket('1day', timec), location, humidity, temperature WITH NO DAT NOTICE: adding index _materialized_hypertable_20_grp_5_5_timec_idx ON _timescaledb_internal._materialized_hypertable_20 USING BTREE(grp_5_5, timec) NOTICE: adding index _materialized_hypertable_20_grp_6_6_timec_idx ON _timescaledb_internal._materialized_hypertable_20 USING BTREE(grp_6_6, timec) NOTICE: adding index _materialized_hypertable_20_grp_7_7_timec_idx ON _timescaledb_internal._materialized_hypertable_20 USING BTREE(grp_7_7, timec) -SELECT add_refresh_continuous_aggregate_policy('mat_with_test', NULL, '5 h'::interval, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1001 +SELECT add_continuous_aggregate_policy('mat_with_test', NULL, '5 h'::interval, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1001 (1 row) SELECT alter_job(id, schedule_interval => '1h') FROM _timescaledb_config.bgw_job; @@ -974,10 +974,10 @@ as select time_bucket(100, timec), min(location), sum(temperature),sum(humidity) from conditions group by time_bucket(100, timec) WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('mat_with_test', NULL, 500::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1002 +SELECT add_continuous_aggregate_policy('mat_with_test', NULL, 500::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1002 (1 row) SELECT alter_job(id, schedule_interval => '2h') FROM _timescaledb_config.bgw_job; @@ -1260,10 +1260,10 @@ select * from conditions_grpby_view order by 1, 2; 200 | 75 (4 rows) -CREATE MATERIALIZED VIEW conditions_grpby_view2 with (timescaledb.continuous, timescaledb.refresh_lag = '-200') as +CREATE MATERIALIZED VIEW conditions_grpby_view2 with (timescaledb.continuous, timescaledb.refresh_lag = '-200') as select time_bucket(100, timec), sum(humidity) from conditions -group by time_bucket(100, timec), location +group by time_bucket(100, timec), location having avg(temperature) > 0 WITH NO DATA; NOTICE: adding index _materialized_hypertable_31_grp_3_3_time_bucket_idx ON _timescaledb_internal._materialized_hypertable_31 USING BTREE(grp_3_3, time_bucket) @@ -1345,7 +1345,7 @@ SELECT * FROM mat_test5; --verify that watermark is limited by max value and not by -- the current time (now value)-- SET timescaledb.current_timestamp_mock = '2018-05-11'; -SELECT view_name, completed_threshold, invalidation_threshold +SELECT view_name, completed_threshold, invalidation_threshold FROM timescaledb_information.continuous_aggregate_stats where view_name::text like 'mat_test5'; view_name | completed_threshold | invalidation_threshold @@ -1357,7 +1357,7 @@ REFRESH MATERIALIZED VIEW mat_test5; LOG: new materialization range not found for public.conditions (time column time): not enough new data past completion threshold of Sat Mar 10 16:00:00 2001 PST as of Fri May 11 00:00:00 2018 PDT LOG: materializing continuous aggregate public.mat_test5: nothing to invalidate, no new range LOG: materializing continuous aggregate public.mat_test5: no new range to materialize or invalidations found, exiting early -SELECT view_name, completed_threshold, invalidation_threshold +SELECT view_name, completed_threshold, invalidation_threshold FROM timescaledb_information.continuous_aggregate_stats where view_name::text like 'mat_test5'; view_name | completed_threshold | invalidation_threshold diff --git a/tsl/test/expected/continuous_aggs_bgw.out b/tsl/test/expected/continuous_aggs_bgw.out index 751c9f9c4ae..4ab95013baa 100644 --- a/tsl/test/expected/continuous_aggs_bgw.out +++ b/tsl/test/expected/continuous_aggs_bgw.out @@ -88,10 +88,10 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view AS SELECT time_bucket('2', time), SUM(data) as value FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, 4::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1000 +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, 4::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1000 (1 row) -- even before running, stats shows something @@ -365,10 +365,10 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view AS SELECT time_bucket('2', time), SUM(data) as value FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1001 +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1001 (1 row) SELECT mat_hypertable_id FROM _timescaledb_catalog.continuous_agg \gset @@ -495,10 +495,10 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; NOTICE: adding index _materialized_hypertable_4_get_constant_no_perms_time_bucke_idx ON _timescaledb_internal._materialized_hypertable_4 USING BTREE(get_constant_no_perms, time_bucket) -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1002 +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1002 (1 row) SELECT id AS job_id FROM _timescaledb_config.bgw_job ORDER BY id desc limit 1 \gset @@ -576,10 +576,10 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view_user_2 AS SELECT time_bucket('2', time), SUM(data) as value FROM test_continuous_agg_table_w_grant GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view_user_2', NULL, -2::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1003 +SELECT add_continuous_aggregate_policy('test_continuous_agg_view_user_2', NULL, -2::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1003 (1 row) SELECT id AS job_id FROM _timescaledb_config.bgw_job ORDER BY id desc limit 1 \gset diff --git a/tsl/test/expected/continuous_aggs_permissions.out b/tsl/test/expected/continuous_aggs_permissions.out index b6a10421577..0796bd67494 100644 --- a/tsl/test/expected/continuous_aggs_permissions.out +++ b/tsl/test/expected/continuous_aggs_permissions.out @@ -35,21 +35,21 @@ select location, max(humidity) from conditions group by time_bucket(100, timec), location WITH NO DATA; NOTICE: adding index _materialized_hypertable_2_location_time_partition_col_idx ON _timescaledb_internal._materialized_hypertable_2 USING BTREE(location, time_partition_col) -SELECT add_refresh_continuous_aggregate_policy('mat_refresh_test', NULL, -200::integer, '12 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1000 +SELECT add_continuous_aggregate_policy('mat_refresh_test', NULL, -200::integer, '12 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1000 (1 row) insert into conditions select generate_series(0, 50, 10), 'NYC', 55, 75, 40, 70, NULL; REFRESH MATERIALIZED VIEW mat_refresh_test; SELECT id as cagg_job_id FROM _timescaledb_config.bgw_job order by id desc limit 1 \gset -SELECT materialization_hypertable FROM timescaledb_information.continuous_aggregates WHERE view_name = 'mat_refresh_test'::regclass \gset +SELECT materialization_hypertable FROM timescaledb_information.continuous_aggregates WHERE view_name = 'mat_refresh_test'::regclass \gset SELECT mat_hypertable_id FROM _timescaledb_catalog.continuous_agg WHERE user_view_name = 'mat_refresh_test' \gset -SELECT schema_name as mat_chunk_schema, table_name as mat_chunk_table -FROM _timescaledb_catalog.chunk -WHERE hypertable_id = :mat_hypertable_id +SELECT schema_name as mat_chunk_schema, table_name as mat_chunk_table +FROM _timescaledb_catalog.chunk +WHERE hypertable_id = :mat_hypertable_id ORDER BY id desc LIMIT 1 \gset CREATE TABLE conditions_for_perm_check ( @@ -117,7 +117,7 @@ ALTER MATERIALIZED VIEW mat_refresh_test SET(timescaledb.refresh_lag = '6 h', ti ERROR: must be owner of continuous aggregate "mat_refresh_test" ALTER MATERIALIZED VIEW mat_refresh_test SET(timescaledb.materialized_only = true); ERROR: must be owner of continuous aggregate "mat_refresh_test" -DROP MATERIALIZED VIEW mat_refresh_test; +DROP MATERIALIZED VIEW mat_refresh_test; ERROR: must be owner of view mat_refresh_test REFRESH MATERIALIZED VIEW mat_refresh_test; ERROR: permission denied for table conditions diff --git a/tsl/test/expected/continuous_aggs_policy.out b/tsl/test/expected/continuous_aggs_policy.out index c10ca1640e0..718abf4dd2e 100644 --- a/tsl/test/expected/continuous_aggs_policy.out +++ b/tsl/test/expected/continuous_aggs_policy.out @@ -1,7 +1,7 @@ -- This file and its contents are licensed under the Timescale License. -- Please see the included NOTICE for copyright information and -- LICENSE-TIMESCALE for a copy of the license. --- test add and remove refresh policy apis +-- test add and remove refresh policy apis SET ROLE :ROLE_DEFAULT_PERM_USER; --TEST1 --- --basic test with count @@ -46,30 +46,30 @@ SELECT count(*) FROM _timescaledb_config.bgw_job; (1 row) \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('int_tab', '1 day'::interval, 10 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('int_tab', '1 day'::interval, 10 , '1 h'::interval); ERROR: "int_tab" is not a continuous aggregate -SELECT add_refresh_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 , '1 h'::interval); ERROR: invalid parameter value for start_interval -SELECT add_refresh_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 ); -ERROR: function add_refresh_continuous_aggregate_policy(unknown, interval, integer) does not exist at character 8 -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 10, '1 day'::interval, '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 ); +ERROR: function add_continuous_aggregate_policy(unknown, interval, integer) does not exist at character 8 +SELECT add_continuous_aggregate_policy('mat_m1', 10, '1 day'::interval, '1 h'::interval); ERROR: invalid parameter value for end_interval -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id \gset ---adding again should warn/error -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>false); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id \gset +--adding again should warn/error +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>false); ERROR: refresh policy already exists for continuous aggregate "mat_m1" -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 10, 20, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_m1', 10, 20, '1h'::interval, if_not_exists=>true); WARNING: could not add refresh policy due to existing policy on continuous aggregate with different arguments - add_refresh_continuous_aggregate_policy ------------------------------------------ - -1 + add_continuous_aggregate_policy +--------------------------------- + -1 (1 row) -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); NOTICE: refresh policy already exists on continuous aggregate "mat_m1", skipping - add_refresh_continuous_aggregate_policy ------------------------------------------ - -1 + add_continuous_aggregate_policy +--------------------------------- + -1 (1 row) -- modify config and try to add, should error out @@ -81,7 +81,7 @@ SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; SELECT hypertable_id as mat_id FROM _timescaledb_config.bgw_job where id = :job_id \gset \c :TEST_DBNAME :ROLE_SUPERUSER -UPDATE _timescaledb_config.bgw_job +UPDATE _timescaledb_config.bgw_job SET config = jsonb_build_object('mat_hypertable_id', :mat_id) WHERE id = :job_id; SET ROLE :ROLE_DEFAULT_PERM_USER; @@ -91,30 +91,30 @@ SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; {"mat_hypertable_id": 2} (1 row) -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); ERROR: could not find start_interval in config for existing job -SELECT remove_refresh_continuous_aggregate_policy('int_tab'); +SELECT remove_continuous_aggregate_policy('int_tab'); ERROR: "int_tab" is not a continuous aggregate -SELECT remove_refresh_continuous_aggregate_policy('mat_m1'); - remove_refresh_continuous_aggregate_policy --------------------------------------------- +SELECT remove_continuous_aggregate_policy('mat_m1'); + remove_continuous_aggregate_policy +------------------------------------ (1 row) --this one will fail -SELECT remove_refresh_continuous_aggregate_policy('mat_m1'); +SELECT remove_continuous_aggregate_policy('mat_m1'); ERROR: refresh policy does not exist on continuous aggregate "mat_m1" -SELECT remove_refresh_continuous_aggregate_policy('mat_m1', if_not_exists=>true); +SELECT remove_continuous_aggregate_policy('mat_m1', if_not_exists=>true); NOTICE: refresh policy does not exist on continuous aggregate "mat_m1", skipping - remove_refresh_continuous_aggregate_policy --------------------------------------------- + remove_continuous_aggregate_policy +------------------------------------ (1 row) --now try to add a policy as a different user than the one that created the cagg --should fail SET ROLE :ROLE_DEFAULT_PERM_USER_2; -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id ; +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id ; ERROR: must be owner of continuous aggregate "mat_m1" SET ROLE :ROLE_DEFAULT_PERM_USER; DROP MATERIALIZED VIEW mat_m1; @@ -133,11 +133,11 @@ CREATE MATERIALIZED VIEW max_mat_view_date FROM continuous_agg_max_mat_date GROUP BY 1 WITH NO DATA; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_date', '2 days'::interval, 10 , '1 day'::interval); +SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 days'::interval, 10 , '1 day'::interval); ERROR: invalid parameter value for end_interval \set ON_ERROR_STOP 1 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_date', '2 day'::interval, '1 day'::interval , '1 day'::interval) as job_id \gset -SELECT config FROM _timescaledb_config.bgw_job +SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 day'::interval, '1 day'::interval , '1 day'::interval) as job_id \gset +SELECT config FROM _timescaledb_config.bgw_job WHERE id = :job_id; config ----------------------------------------------------------------------------------- @@ -161,9 +161,9 @@ CREATE MATERIALIZED VIEW max_mat_view_timestamp AS SELECT time_bucket('7 days', time) FROM continuous_agg_timestamp GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 h'::interval , '1 h'::interval) as job_id \gset +SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 h'::interval , '1 h'::interval) as job_id \gset CALL run_job(:job_id); -SELECT config FROM _timescaledb_config.bgw_job +SELECT config FROM _timescaledb_config.bgw_job WHERE id = :job_id; config ------------------------------------------------------------------------------------- @@ -171,7 +171,7 @@ WHERE id = :job_id; (1 row) \c :TEST_DBNAME :ROLE_SUPERUSER -UPDATE _timescaledb_config.bgw_job +UPDATE _timescaledb_config.bgw_job SET config = jsonb_build_object('mat_hypertable_id', :mat_id) WHERE id = :job_id; SET ROLE :ROLE_DEFAULT_PERM_USER; @@ -182,7 +182,7 @@ SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; (1 row) \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 day'::interval, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 day'::interval, '1h'::interval, if_not_exists=>true); ERROR: could not find start_interval in config for job \set ON_ERROR_STOP 1 DROP MATERIALIZED VIEW max_mat_view_timestamp; @@ -209,12 +209,12 @@ SELECT time_bucket( SMALLINT '1', a) , count(*) FROM smallint_tab GROUP BY 1 WITH NO DATA; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15, 0 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_smallint', 15, 0 , '1 h'::interval); ERROR: invalid parameter value for start_interval -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 98898::smallint , 0::smallint, '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_smallint', 98898::smallint , 0::smallint, '1 h'::interval); ERROR: smallint out of range \set ON_ERROR_STOP 1 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15::smallint, 0::smallint , '1 h'::interval) as job_id \gset +SELECT add_continuous_aggregate_policy('mat_smallint', 15::smallint, 0::smallint , '1 h'::interval) as job_id \gset INSERT INTO smallint_tab VALUES(5); INSERT INTO smallint_tab VALUES(10); INSERT INTO smallint_tab VALUES(20); @@ -227,11 +227,11 @@ SELECT * FROM mat_smallint; (2 rows) \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15, 10, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_smallint', 15, 10, '1h'::interval, if_not_exists=>true); WARNING: could not add refresh policy due to existing policy on continuous aggregate with different arguments - add_refresh_continuous_aggregate_policy ------------------------------------------ - -1 + add_continuous_aggregate_policy +--------------------------------- + -1 (1 row) \set ON_ERROR_STOP 1 diff --git a/tsl/test/expected/continuous_aggs_usage.out b/tsl/test/expected/continuous_aggs_usage.out index 4db37591708..7f3ca31e485 100644 --- a/tsl/test/expected/continuous_aggs_usage.out +++ b/tsl/test/expected/continuous_aggs_usage.out @@ -31,10 +31,10 @@ FROM device_readings GROUP BY bucket, device_id WITH NO DATA; --We have to group by the bucket column, but can also add other group-by columns NOTICE: adding index _materialized_hypertable_2_device_id_bucket_idx ON _timescaledb_internal._materialized_hypertable_2 USING BTREE(device_id, bucket) -SELECT add_refresh_continuous_aggregate_policy('device_summary', NULL, '2 h'::interval, '2 h'::interval); - add_refresh_continuous_aggregate_policy ------------------------------------------ - 1000 +SELECT add_continuous_aggregate_policy('device_summary', NULL, '2 h'::interval, '2 h'::interval); + add_continuous_aggregate_policy +--------------------------------- + 1000 (1 row) --Next, insert some data into the raw hypertable diff --git a/tsl/test/sql/compression_ddl.sql b/tsl/test/sql/compression_ddl.sql index bbce12e9644..5ddf43c9be5 100644 --- a/tsl/test/sql/compression_ddl.sql +++ b/tsl/test/sql/compression_ddl.sql @@ -335,7 +335,9 @@ CREATE MATERIALIZED VIEW test1_cont_view WITH (timescaledb.continuous, timescale AS SELECT time_bucket('1 hour', "Time"), SUM(i) FROM test1 GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test1_cont_view', NULL, '1 hour'::interval, '1 day'::interval); + +SELECT add_continuous_aggregate_policy('test1_cont_view', NULL, '1 hour'::interval, '1 day'::interval); + REFRESH MATERIALIZED VIEW test1_cont_view; SELECT count(*) FROM test1_cont_view; @@ -444,4 +446,3 @@ SELECT decompress_chunk(chunk.schema_name|| '.' || chunk.table_name) FROM _timescaledb_catalog.chunk chunk INNER JOIN _timescaledb_catalog.hypertable hypertable ON (chunk.hypertable_id = hypertable.id) WHERE hypertable.table_name like 'test1' ORDER BY chunk.id ) as subq; - diff --git a/tsl/test/sql/continuous_aggs.sql b/tsl/test/sql/continuous_aggs.sql index 0f8ecdccf1b..2ebb003953f 100644 --- a/tsl/test/sql/continuous_aggs.sql +++ b/tsl/test/sql/continuous_aggs.sql @@ -45,7 +45,7 @@ select a, count(b) from foo group by time_bucket(1, a), a WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('mat_m1', NULL, 2::integer, '12 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', NULL, 2::integer, '12 h'::interval); SELECT * FROM _timescaledb_config.bgw_job; SELECT ca.raw_hypertable_id as "RAW_HYPERTABLE_ID", @@ -642,7 +642,7 @@ select time_bucket('1day', timec), min(location), sum(temperature),sum(humidity) from conditions group by time_bucket('1day', timec), location, humidity, temperature WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('mat_with_test', NULL, '5 h'::interval, '12 h'::interval); +SELECT add_continuous_aggregate_policy('mat_with_test', NULL, '5 h'::interval, '12 h'::interval); SELECT alter_job(id, schedule_interval => '1h') FROM _timescaledb_config.bgw_job; SELECT schedule_interval FROM _timescaledb_config.bgw_job; SELECT _timescaledb_internal.to_interval(refresh_lag) FROM _timescaledb_catalog.continuous_agg WHERE user_view_name = 'mat_with_test'; @@ -699,7 +699,7 @@ select time_bucket(100, timec), min(location), sum(temperature),sum(humidity) from conditions group by time_bucket(100, timec) WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('mat_with_test', NULL, 500::integer, '12 h'::interval); +SELECT add_continuous_aggregate_policy('mat_with_test', NULL, 500::integer, '12 h'::interval); SELECT alter_job(id, schedule_interval => '2h') FROM _timescaledb_config.bgw_job; SELECT schedule_interval FROM _timescaledb_config.bgw_job; @@ -885,10 +885,10 @@ group by time_bucket(100, timec), location WITH NO DATA; REFRESH MATERIALIZED VIEW conditions_grpby_view; select * from conditions_grpby_view order by 1, 2; -CREATE MATERIALIZED VIEW conditions_grpby_view2 with (timescaledb.continuous, timescaledb.refresh_lag = '-200') as +CREATE MATERIALIZED VIEW conditions_grpby_view2 with (timescaledb.continuous, timescaledb.refresh_lag = '-200') as select time_bucket(100, timec), sum(humidity) from conditions -group by time_bucket(100, timec), location +group by time_bucket(100, timec), location having avg(temperature) > 0 WITH NO DATA; REFRESH MATERIALIZED VIEW conditions_grpby_view2; @@ -939,10 +939,10 @@ SELECT * FROM mat_test5; --verify that watermark is limited by max value and not by -- the current time (now value)-- SET timescaledb.current_timestamp_mock = '2018-05-11'; -SELECT view_name, completed_threshold, invalidation_threshold +SELECT view_name, completed_threshold, invalidation_threshold FROM timescaledb_information.continuous_aggregate_stats where view_name::text like 'mat_test5'; REFRESH MATERIALIZED VIEW mat_test5; -SELECT view_name, completed_threshold, invalidation_threshold +SELECT view_name, completed_threshold, invalidation_threshold FROM timescaledb_information.continuous_aggregate_stats where view_name::text like 'mat_test5'; diff --git a/tsl/test/sql/continuous_aggs_bgw.sql b/tsl/test/sql/continuous_aggs_bgw.sql index 91cc5de3e02..abc2b3cc434 100644 --- a/tsl/test/sql/continuous_aggs_bgw.sql +++ b/tsl/test/sql/continuous_aggs_bgw.sql @@ -80,7 +80,8 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view AS SELECT time_bucket('2', time), SUM(data) as value FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, 4::integer, '12 h'::interval); + +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, 4::integer, '12 h'::interval); -- even before running, stats shows something SELECT view_name, completed_threshold, invalidation_threshold, job_status, last_run_duration @@ -231,7 +232,7 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); SELECT mat_hypertable_id FROM _timescaledb_catalog.continuous_agg \gset SELECT id AS job_id FROM _timescaledb_config.bgw_job WHERE hypertable_id=:mat_hypertable_id \gset @@ -290,8 +291,8 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view AS SELECT time_bucket('2', time), SUM(data) as value, get_constant_no_perms() FROM test_continuous_agg_table GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); +SELECT add_continuous_aggregate_policy('test_continuous_agg_view', NULL, -2::integer, '12 h'::interval); SELECT id AS job_id FROM _timescaledb_config.bgw_job ORDER BY id desc limit 1 \gset @@ -334,7 +335,8 @@ CREATE MATERIALIZED VIEW test_continuous_agg_view_user_2 AS SELECT time_bucket('2', time), SUM(data) as value FROM test_continuous_agg_table_w_grant GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('test_continuous_agg_view_user_2', NULL, -2::integer, '12 h'::interval); + +SELECT add_continuous_aggregate_policy('test_continuous_agg_view_user_2', NULL, -2::integer, '12 h'::interval); SELECT id AS job_id FROM _timescaledb_config.bgw_job ORDER BY id desc limit 1 \gset diff --git a/tsl/test/sql/continuous_aggs_permissions.sql b/tsl/test/sql/continuous_aggs_permissions.sql index 438153bd718..5ff2d161d92 100644 --- a/tsl/test/sql/continuous_aggs_permissions.sql +++ b/tsl/test/sql/continuous_aggs_permissions.sql @@ -32,7 +32,7 @@ select location, max(humidity) from conditions group by time_bucket(100, timec), location WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('mat_refresh_test', NULL, -200::integer, '12 h'::interval); +SELECT add_continuous_aggregate_policy('mat_refresh_test', NULL, -200::integer, '12 h'::interval); insert into conditions select generate_series(0, 50, 10), 'NYC', 55, 75, 40, 70, NULL; @@ -40,13 +40,13 @@ select generate_series(0, 50, 10), 'NYC', 55, 75, 40, 70, NULL; REFRESH MATERIALIZED VIEW mat_refresh_test; SELECT id as cagg_job_id FROM _timescaledb_config.bgw_job order by id desc limit 1 \gset -SELECT materialization_hypertable FROM timescaledb_information.continuous_aggregates WHERE view_name = 'mat_refresh_test'::regclass \gset +SELECT materialization_hypertable FROM timescaledb_information.continuous_aggregates WHERE view_name = 'mat_refresh_test'::regclass \gset SELECT mat_hypertable_id FROM _timescaledb_catalog.continuous_agg WHERE user_view_name = 'mat_refresh_test' \gset -SELECT schema_name as mat_chunk_schema, table_name as mat_chunk_table -FROM _timescaledb_catalog.chunk -WHERE hypertable_id = :mat_hypertable_id +SELECT schema_name as mat_chunk_schema, table_name as mat_chunk_table +FROM _timescaledb_catalog.chunk +WHERE hypertable_id = :mat_hypertable_id ORDER BY id desc LIMIT 1 \gset @@ -105,7 +105,7 @@ select from alter_job(:cagg_job_id, max_runtime => NULL); ALTER MATERIALIZED VIEW mat_refresh_test SET(timescaledb.refresh_lag = '6 h', timescaledb.refresh_interval = '2h'); ALTER MATERIALIZED VIEW mat_refresh_test SET(timescaledb.materialized_only = true); -DROP MATERIALIZED VIEW mat_refresh_test; +DROP MATERIALIZED VIEW mat_refresh_test; REFRESH MATERIALIZED VIEW mat_refresh_test; SELECT * FROM mat_refresh_test; SELECT * FROM :materialization_hypertable; diff --git a/tsl/test/sql/continuous_aggs_policy.sql b/tsl/test/sql/continuous_aggs_policy.sql index 68b5c6dfa1e..ff2c013bd0a 100644 --- a/tsl/test/sql/continuous_aggs_policy.sql +++ b/tsl/test/sql/continuous_aggs_policy.sql @@ -2,7 +2,7 @@ -- Please see the included NOTICE for copyright information and -- LICENSE-TIMESCALE for a copy of the license. --- test add and remove refresh policy apis +-- test add and remove refresh policy apis SET ROLE :ROLE_DEFAULT_PERM_USER; @@ -40,38 +40,38 @@ SET ROLE :ROLE_DEFAULT_PERM_USER; SELECT count(*) FROM _timescaledb_config.bgw_job; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('int_tab', '1 day'::interval, 10 , '1 h'::interval); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 , '1 h'::interval); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 ); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 10, '1 day'::interval, '1 h'::interval); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id \gset +SELECT add_continuous_aggregate_policy('int_tab', '1 day'::interval, 10 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', '1 day'::interval, 10 ); +SELECT add_continuous_aggregate_policy('mat_m1', 10, '1 day'::interval, '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id \gset ---adding again should warn/error -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>false); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 10, 20, '1h'::interval, if_not_exists=>true); -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); +--adding again should warn/error +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>false); +SELECT add_continuous_aggregate_policy('mat_m1', 10, 20, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); -- modify config and try to add, should error out SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; SELECT hypertable_id as mat_id FROM _timescaledb_config.bgw_job where id = :job_id \gset \c :TEST_DBNAME :ROLE_SUPERUSER -UPDATE _timescaledb_config.bgw_job +UPDATE _timescaledb_config.bgw_job SET config = jsonb_build_object('mat_hypertable_id', :mat_id) WHERE id = :job_id; SET ROLE :ROLE_DEFAULT_PERM_USER; SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval, if_not_exists=>true); -SELECT remove_refresh_continuous_aggregate_policy('int_tab'); -SELECT remove_refresh_continuous_aggregate_policy('mat_m1'); +SELECT remove_continuous_aggregate_policy('int_tab'); +SELECT remove_continuous_aggregate_policy('mat_m1'); --this one will fail -SELECT remove_refresh_continuous_aggregate_policy('mat_m1'); -SELECT remove_refresh_continuous_aggregate_policy('mat_m1', if_not_exists=>true); +SELECT remove_continuous_aggregate_policy('mat_m1'); +SELECT remove_continuous_aggregate_policy('mat_m1', if_not_exists=>true); --now try to add a policy as a different user than the one that created the cagg --should fail SET ROLE :ROLE_DEFAULT_PERM_USER_2; -SELECT add_refresh_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id ; +SELECT add_continuous_aggregate_policy('mat_m1', 20, 10, '1h'::interval) as job_id ; SET ROLE :ROLE_DEFAULT_PERM_USER; DROP MATERIALIZED VIEW mat_m1; @@ -86,10 +86,10 @@ CREATE MATERIALIZED VIEW max_mat_view_date GROUP BY 1 WITH NO DATA; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_date', '2 days'::interval, 10 , '1 day'::interval); +SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 days'::interval, 10 , '1 day'::interval); \set ON_ERROR_STOP 1 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_date', '2 day'::interval, '1 day'::interval , '1 day'::interval) as job_id \gset -SELECT config FROM _timescaledb_config.bgw_job +SELECT add_continuous_aggregate_policy('max_mat_view_date', '2 day'::interval, '1 day'::interval , '1 day'::interval) as job_id \gset +SELECT config FROM _timescaledb_config.bgw_job WHERE id = :job_id; INSERT INTO continuous_agg_max_mat_date @@ -106,21 +106,21 @@ CREATE MATERIALIZED VIEW max_mat_view_timestamp FROM continuous_agg_timestamp GROUP BY 1 WITH NO DATA; -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 h'::interval , '1 h'::interval) as job_id \gset +SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 h'::interval , '1 h'::interval) as job_id \gset CALL run_job(:job_id); -SELECT config FROM _timescaledb_config.bgw_job +SELECT config FROM _timescaledb_config.bgw_job WHERE id = :job_id; \c :TEST_DBNAME :ROLE_SUPERUSER -UPDATE _timescaledb_config.bgw_job +UPDATE _timescaledb_config.bgw_job SET config = jsonb_build_object('mat_hypertable_id', :mat_id) WHERE id = :job_id; SET ROLE :ROLE_DEFAULT_PERM_USER; SELECT config FROM _timescaledb_config.bgw_job where id = :job_id; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 day'::interval, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('max_mat_view_timestamp', '10 day'::interval, '1 day'::interval, '1h'::interval, if_not_exists=>true); \set ON_ERROR_STOP 1 DROP MATERIALIZED VIEW max_mat_view_timestamp; @@ -138,10 +138,10 @@ SELECT time_bucket( SMALLINT '1', a) , count(*) FROM smallint_tab GROUP BY 1 WITH NO DATA; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15, 0 , '1 h'::interval); -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 98898::smallint , 0::smallint, '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_smallint', 15, 0 , '1 h'::interval); +SELECT add_continuous_aggregate_policy('mat_smallint', 98898::smallint , 0::smallint, '1 h'::interval); \set ON_ERROR_STOP 1 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15::smallint, 0::smallint , '1 h'::interval) as job_id \gset +SELECT add_continuous_aggregate_policy('mat_smallint', 15::smallint, 0::smallint , '1 h'::interval) as job_id \gset INSERT INTO smallint_tab VALUES(5); INSERT INTO smallint_tab VALUES(10); INSERT INTO smallint_tab VALUES(20); @@ -149,7 +149,7 @@ CALL run_job(:job_id); SELECT * FROM mat_smallint; \set ON_ERROR_STOP 0 -SELECT add_refresh_continuous_aggregate_policy('mat_smallint', 15, 10, '1h'::interval, if_not_exists=>true); +SELECT add_continuous_aggregate_policy('mat_smallint', 15, 10, '1h'::interval, if_not_exists=>true); \set ON_ERROR_STOP 1 DROP MATERIALIZED VIEW mat_smallint; diff --git a/tsl/test/sql/continuous_aggs_usage.sql b/tsl/test/sql/continuous_aggs_usage.sql index 20a190ec3c6..f0b6bde43a8 100644 --- a/tsl/test/sql/continuous_aggs_usage.sql +++ b/tsl/test/sql/continuous_aggs_usage.sql @@ -30,7 +30,7 @@ FROM device_readings GROUP BY bucket, device_id WITH NO DATA; --We have to group by the bucket column, but can also add other group-by columns -SELECT add_refresh_continuous_aggregate_policy('device_summary', NULL, '2 h'::interval, '2 h'::interval); +SELECT add_continuous_aggregate_policy('device_summary', NULL, '2 h'::interval, '2 h'::interval); --Next, insert some data into the raw hypertable INSERT INTO device_readings SELECT ts, 'device_1', (EXTRACT(EPOCH FROM ts)) from generate_series('2018-12-01 00:00'::timestamp, '2018-12-31 00:00'::timestamp, '30 minutes') ts;