New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add invalidations for incomplete aggregates #2403
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,3 +263,50 @@ BEGIN | |
END $$; | ||
|
||
REFRESH MATERIALIZED VIEW mat_ignoreinval; | ||
|
||
-- test new data beyond the invalidation threshold is properly handled -- | ||
CREATE TABLE inval_test (time TIMESTAMPTZ, location TEXT, temperature DOUBLE PRECISION); | ||
SELECT create_hypertable('inval_test', 'time', chunk_time_interval => INTERVAL '1 week'); | ||
|
||
INSERT INTO inval_test | ||
SELECT generate_series('2018-12-01 00:00'::timestamp, '2018-12-20 00:00'::timestamp, '1 day'), 'POR', generate_series(40.5, 50.0, 0.5); | ||
INSERT INTO inval_test | ||
SELECT generate_series('2018-12-01 00:00'::timestamp, '2018-12-20 00:00'::timestamp, '1 day'), 'NYC', generate_series(31.0, 50.0, 1.0); | ||
|
||
DO LANGUAGE PLPGSQL $$ | ||
DECLARE | ||
ts_version TEXT; | ||
BEGIN | ||
SELECT extversion INTO ts_version FROM pg_extension WHERE extname = 'timescaledb'; | ||
|
||
IF ts_version < '2.0.0' THEN | ||
CREATE VIEW mat_inval | ||
WITH ( timescaledb.continuous, timescaledb.materialized_only=true, | ||
timescaledb.refresh_lag='-20 days', | ||
timescaledb.refresh_interval='12 hours', | ||
timescaledb.max_interval_per_job='100000 days' ) | ||
AS | ||
SELECT time_bucket('10 minute', time) as bucket, location, min(temperature) as min_temp, | ||
max(temperature) as max_temp, avg(temperature) as avg_temp | ||
FROM inval_test | ||
GROUP BY bucket, location; | ||
|
||
ELSE | ||
CREATE MATERIALIZED VIEW mat_inval | ||
WITH ( timescaledb.continuous, timescaledb.materialized_only=true ) | ||
AS | ||
SELECT time_bucket('10 minute', time) as bucket, location, min(temperature) as min_temp, | ||
max(temperature) as max_temp, avg(temperature) as avg_temp | ||
FROM inval_test | ||
GROUP BY bucket, location WITH NO DATA; | ||
|
||
PERFORM add_continuous_aggregate_policy('mat_inval', NULL, '-20 days'::interval, '12 hours'); | ||
END IF; | ||
END $$; | ||
|
||
REFRESH MATERIALIZED VIEW mat_inval; | ||
|
||
INSERT INTO inval_test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This time range is not in the original data set . So don't think you have any invalidations for the last completed threshold range.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually intended to all be new data. I believe we already have other tests for existing invalidations, what this test is intended to verify is that we generate a new invalidation that covers new data when updating to 2.0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the refresh and query post upgrade done int test-rerun.v6.sql? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I needed to move that from the post script to the rerun script, as the post script isn't called on the rerun container (the post was just run on the upgraded container and a dump/restore of the upgraded container, both of which had the wrong data and hence no diff). |
||
SELECT generate_series('2118-12-01 00:00'::timestamp, '2118-12-20 00:00'::timestamp, '1 day'), 'POR', generate_series(135.25, 140.0, 0.25); | ||
INSERT INTO inval_test | ||
SELECT generate_series('2118-12-01 00:00'::timestamp, '2118-12-20 00:00'::timestamp, '1 day'), 'NYC', generate_series(131.0, 150.0, 1.0); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- 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. | ||
|
||
\ir test-rerun.v1.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- 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. | ||
|
||
\ir test-rerun.v1.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- 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. | ||
|
||
\ir test-rerun.v1.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- 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. | ||
|
||
\ir test-rerun.v1.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- 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. | ||
|
||
\ir test-rerun.v1.sql | ||
|
||
SELECT count(*) FROM mat_inval; | ||
REFRESH MATERIALIZED VIEW mat_inval; | ||
SELECT count(*) FROM mat_inval; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have a new cagg that has been never refreshed , do we need an entry in the cont agg materialization log that says [-infinity, +infinity) is invalid? (cc @erimatnor )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that's pretty tight window. I believe the background job gets launched as soon as we create the materialized view in 1.7.