From dab50aef19f1353b563be1d8e25ed9e39695a701 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Sat, 16 May 2020 01:04:14 +0200 Subject: [PATCH] Add real-time aggregation test to update test This patch adds a continuous aggregate with real-time aggregation enabled to the update test suite since we rebuild view definition for real time aggregation during extension update. The continuous aggregate is in its own schema because all view definitions in the public schema are dumped and those view definitions will change between versions. --- test/sql/updates/post.continuous_aggs.v2.sql | 16 ++++++ test/sql/updates/post.v6-pg10.sql | 2 +- test/sql/updates/post.v6-pg11.sql | 2 +- test/sql/updates/post.v6-pg12.sql | 2 +- test/sql/updates/post.v6-pg96.sql | 2 +- test/sql/updates/setup.continuous_aggs.v2.sql | 53 ++++++++++++++++++- 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 test/sql/updates/post.continuous_aggs.v2.sql diff --git a/test/sql/updates/post.continuous_aggs.v2.sql b/test/sql/updates/post.continuous_aggs.v2.sql new file mode 100644 index 000000000..ad90b19bc --- /dev/null +++ b/test/sql/updates/post.continuous_aggs.v2.sql @@ -0,0 +1,16 @@ +-- 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 post.continuous_aggs.sql + +\d cagg.* + +SELECT * FROM cagg.realtime_mat ORDER BY bucket, location; + +REFRESH MATERIALIZED VIEW cagg.realtime_mat; + +SELECT * FROM cagg.realtime_mat ORDER BY bucket, location; + +SELECT view_name, refresh_lag, refresh_interval, max_interval_per_job, ignore_invalidation_older_than, materialized_only, materialization_hypertable FROM timescaledb_information.continuous_aggregates ORDER BY view_name::text; + diff --git a/test/sql/updates/post.v6-pg10.sql b/test/sql/updates/post.v6-pg10.sql index 5433c2cb2..ddbcc8c92 100644 --- a/test/sql/updates/post.v6-pg10.sql +++ b/test/sql/updates/post.v6-pg10.sql @@ -4,5 +4,5 @@ \ir post.v2.sql \ir post.compression.sql -\ir post.continuous_aggs.sql +\ir post.continuous_aggs.v2.sql diff --git a/test/sql/updates/post.v6-pg11.sql b/test/sql/updates/post.v6-pg11.sql index 89123abbf..a820111df 100644 --- a/test/sql/updates/post.v6-pg11.sql +++ b/test/sql/updates/post.v6-pg11.sql @@ -5,5 +5,5 @@ \ir post.v2.sql \ir catalog_missing_columns.sql \ir post.compression.sql -\ir post.continuous_aggs.sql +\ir post.continuous_aggs.v2.sql diff --git a/test/sql/updates/post.v6-pg12.sql b/test/sql/updates/post.v6-pg12.sql index 198601bd9..826d54f5d 100644 --- a/test/sql/updates/post.v6-pg12.sql +++ b/test/sql/updates/post.v6-pg12.sql @@ -5,4 +5,4 @@ \ir post.v2.sql \ir catalog_missing_columns.sql \ir post.compression.sql -\ir post.continuous_aggs.sql +\ir post.continuous_aggs.v2.sql diff --git a/test/sql/updates/post.v6-pg96.sql b/test/sql/updates/post.v6-pg96.sql index 2c2c872a6..e5bde0791 100644 --- a/test/sql/updates/post.v6-pg96.sql +++ b/test/sql/updates/post.v6-pg96.sql @@ -3,5 +3,5 @@ -- LICENSE-APACHE for a copy of the license. \ir post.v2.sql -\ir post.continuous_aggs.sql +\ir post.continuous_aggs.v2.sql diff --git a/test/sql/updates/setup.continuous_aggs.v2.sql b/test/sql/updates/setup.continuous_aggs.v2.sql index a127f5f1d..d811d04d6 100644 --- a/test/sql/updates/setup.continuous_aggs.v2.sql +++ b/test/sql/updates/setup.continuous_aggs.v2.sql @@ -70,4 +70,55 @@ AS GROUP BY bucket, location HAVING min(location) >= 'NYC' and avg(temperature) > 2; - REFRESH MATERIALIZED VIEW mat_before; +REFRESH MATERIALIZED VIEW mat_before; + +-- we create separate schema for realtime agg since we dump all view definitions in public schema +-- but realtime agg view definition is not stable across versions +CREATE SCHEMA cagg; + +CREATE VIEW cagg.realtime_mat +WITH ( timescaledb.continuous, timescaledb.materialized_only=false, timescaledb.refresh_lag='-30 day', timescaledb.max_interval_per_job ='1000 day') +AS + SELECT time_bucket('1week', timec) as bucket, + location, + min(allnull) as min_allnull, + max(temperature) as max_temp, + sum(temperature)+sum(humidity) as agg_sum_expr, + avg(humidity), + stddev(humidity), + bit_and(bit_int), + bit_or(bit_int), + bool_and(good_life), + every(temperature > 0), + bool_or(good_life), + count(*) as count_rows, + count(temperature) as count_temp, + count(allnull) as count_zero, + corr(temperature, humidity), + covar_pop(temperature, humidity), + covar_samp(temperature, humidity), + regr_avgx(temperature, humidity), + regr_avgy(temperature, humidity), + regr_count(temperature, humidity), + regr_intercept(temperature, humidity), + regr_r2(temperature, humidity), + regr_slope(temperature, humidity), + regr_sxx(temperature, humidity), + regr_sxy(temperature, humidity), + regr_syy(temperature, humidity), + stddev(temperature) as stddev_temp, + stddev_pop(temperature), + stddev_samp(temperature), + variance(temperature), + var_pop(temperature), + var_samp(temperature), + last(temperature, timec) as last_temp, + last(highlow, timec) as last_hl, + first(highlow, timec) as first_hl, + histogram(temperature, 0, 100, 5) + FROM conditions_before + GROUP BY bucket, location + HAVING min(location) >= 'NYC' and avg(temperature) > 2; + +REFRESH MATERIALIZED VIEW cagg.realtime_mat; +