Skip to content

Commit

Permalink
Added tests and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shhnwz committed Jun 24, 2024
1 parent 93e24b8 commit ea70065
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sql/timeseries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ CREATE TABLE @[email protected]_config(
compression_duration interval,
CONSTRAINT policy_duration_order_check
CHECK(compression_duration < tier_duration
AND tier_duration < retention_duration));
AND tier_duration < retention_duration
AND compression_duration < retention_duration));

-- Enhances an existing table with our time-series best practices. Basically
-- the entry point to this extension. Minimally, a user must create a table
Expand Down Expand Up @@ -706,7 +707,9 @@ BEGIN
part_row.partition_tablename);

IF part_end < (now() - comp_offset) THEN
EXECUTE SELECT tier.table(target_table_id);
EXECUTE 'SELECT tier.table(' ||
chr(39)|| part_row.partition_schemaname || '.' || part_row.partition_tablename ||
chr(39)|| ')';
END IF;
END LOOP;
END;
Expand Down
63 changes: 63 additions & 0 deletions test/sql/basic_usage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,66 @@ FROM date_bin_table(NULL::events, '1 minute',
'(2020-11-04 15:50:00-08, 2020-11-04 16:00:00-08)')
GROUP BY 3
ORDER BY 3;

create table sensor_data(
sensor_id integer not null,
time timestamptz not null,
cpu double precision null,
temperature double precision null
) PARTITION BY RANGE (time);

SELECT enable_ts_table('sensor_data');

--Set and Verify tier policy
SELECT set_ts_tier_policy('sensor_data', '180 days');
SELECT tier_duration FROM ts_config WHERE table_id='sensor_data'::regclass;

--Clear and Verify tier policy
SELECT clear_ts_tier_policy('sensor_data');
SELECT tier_duration FROM ts_config WHERE table_id='sensor_data'::regclass;

--Check compatibility when retention < tier
SELECT set_ts_retention_policy('sensor_data', '90 days');
SELECT set_ts_tier_policy('sensor_data', '180 days');
SELECT clear_ts_retention_policy('sensor_data');

--Check compatibility when compression > tier
SELECT set_ts_compression_policy('sensor_data', '90 days');
SELECT set_ts_tier_policy('sensor_data', '60 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_tier_policy('sensor_data');

--Check compatibility when compression < tier
SELECT set_ts_compression_policy('sensor_data', '90 days');
SELECT set_ts_tier_policy('sensor_data', '180 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_tier_policy('sensor_data');

--Check compatibility when compression < retention
SELECT set_ts_compression_policy('sensor_data', '90 days');
SELECT set_ts_retention_policy('sensor_data', '180 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_retention_policy('sensor_data');

--Check compatibility when compression > retention
SELECT set_ts_compression_policy('sensor_data', '180 days');
SELECT set_ts_retention_policy('sensor_data', '90 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_retention_policy('sensor_data');

--Check compatibility when compression < retention < tier
SELECT set_ts_compression_policy('sensor_data', '90 days');
SELECT set_ts_retention_policy('sensor_data', '180 days');
SELECT set_ts_tier_policy('sensor_data', '270 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_retention_policy('sensor_data');
SELECT clear_ts_tier_policy('sensor_data');

--Check compatibility when compression < tier < retention
SELECT set_ts_compression_policy('sensor_data', '90 days');
SELECT set_ts_tier_policy('sensor_data', '180 days');
SELECT set_ts_retention_policy('sensor_data', '270 days');
SELECT clear_ts_compression_policy('sensor_data');
SELECT clear_ts_retention_policy('sensor_data');
SELECT clear_ts_tier_policy('sensor_data');

0 comments on commit ea70065

Please sign in to comment.