From 0aec6921939df6c4ec6a29967a36cd3934de751e Mon Sep 17 00:00:00 2001 From: Konstantina Skovola Date: Fri, 10 Feb 2023 10:21:47 +0200 Subject: [PATCH] Support sub-second intervals in hierarchical caggs Previously we used date_part("epoch", interval) and integer division internally to determine whether the top cagg's interval is a multiple of its parent's. This led to precision loss and wrong results in the case of intervals with sub-second components. Fixed by using the `ts_interval_value_to_internal` function to convert intervals to appropriate integer representation for division. Fixes #5277 --- CHANGELOG.md | 1 + tsl/src/continuous_aggs/create.c | 14 +- tsl/test/expected/cagg_on_cagg.out | 417 +++++++++++++++++++++ tsl/test/expected/cagg_on_cagg_dist_ht.out | 417 +++++++++++++++++++++ tsl/test/sql/cagg_on_cagg.sql | 27 ++ tsl/test/sql/cagg_on_cagg_dist_ht.sql | 27 ++ 6 files changed, 895 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df85510df11..2cd9f904c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ accidentally triggering the load of a previous DB version.** * #5317 Fix some incorrect memory handling * #5367 Rename columns in old-style continuous aggregates * #5384 Fix Hierarchical Continuous Aggregates chunk_interval_size +* #5304 Support sub-second intervals in hierarchical caggs **Thanks** * @Medvecrab for discovering an issue with copying NameData when forming heap tuples. diff --git a/tsl/src/continuous_aggs/create.c b/tsl/src/continuous_aggs/create.c index ada8166d1eb..533c926da46 100644 --- a/tsl/src/continuous_aggs/create.c +++ b/tsl/src/continuous_aggs/create.c @@ -1128,7 +1128,7 @@ cagg_query_supported(const Query *query, StringInfo hint, StringInfo detail, con static inline int64 get_bucket_width(CAggTimebucketInfo bucket_info) { - int64 width = 0; + float8 width = 0; /* Calculate the width. */ switch (bucket_info.bucket_width_type) @@ -1151,11 +1151,9 @@ get_bucket_width(CAggTimebucketInfo bucket_info) bucket_info.interval->day = bucket_info.interval->month * DAYS_PER_MONTH; bucket_info.interval->month = 0; } - Datum epoch = DirectFunctionCall2(interval_part, - PointerGetDatum(cstring_to_text("epoch")), - IntervalPGetDatum(bucket_info.interval)); - /* Cast float8 to int8. */ - width = DatumGetInt64(DirectFunctionCall1(dtoi8, epoch)); + + /* Convert Interval to int64 */ + width = ts_interval_value_to_internal(IntervalPGetDatum(bucket_info.interval), INTERVALOID); break; } default: @@ -1546,9 +1544,9 @@ cagg_validate_query(const Query *query, const bool finalized, const char *cagg_s if (bucket_width_parent != 0) { if (bucket_width_parent > bucket_width && bucket_width != 0) - is_multiple_of_parent = ((bucket_width_parent % bucket_width) == 0); + is_multiple_of_parent = (fmod(bucket_width_parent, bucket_width) == 0); else - is_multiple_of_parent = ((bucket_width % bucket_width_parent) == 0); + is_multiple_of_parent = (fmod(bucket_width, bucket_width_parent) == 0); } /* Proceed with validation errors. */ diff --git a/tsl/test/expected/cagg_on_cagg.out b/tsl/test/expected/cagg_on_cagg.out index 08a9fde144a..e5059774cb7 100644 --- a/tsl/test/expected/cagg_on_cagg.out +++ b/tsl/test/expected/cagg_on_cagg.out @@ -4247,3 +4247,420 @@ DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should b DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- bug report 5277 +\set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE +\set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE +-- epoch plus cast to int would compute a bucket width of 0 for parent +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_58.bucket, + _materialized_hypertable_58.temperature + FROM _timescaledb_internal._materialized_hypertable_58 + WHERE _materialized_hypertable_58.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_59.bucket, + _materialized_hypertable_59.temperature + FROM _timescaledb_internal._materialized_hypertable_59 + WHERE _materialized_hypertable_59.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +\set BUCKET_WIDTH_1ST 'INTERVAL \'9344 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'74752 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_60.bucket, + _materialized_hypertable_60.temperature + FROM _timescaledb_internal._materialized_hypertable_60 + WHERE _materialized_hypertable_60.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 9.344 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 9.344 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_61.bucket, + _materialized_hypertable_61.temperature + FROM _timescaledb_internal._materialized_hypertable_61 + WHERE _materialized_hypertable_61.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +\set BUCKET_WIDTH_1ST 'INTERVAL \'74752 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'598016 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_62.bucket, + _materialized_hypertable_62.temperature + FROM _timescaledb_internal._materialized_hypertable_62 + WHERE _materialized_hypertable_62.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_63.bucket, + _materialized_hypertable_63.temperature + FROM _timescaledb_internal._materialized_hypertable_63 + WHERE _materialized_hypertable_63.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- test microseconds - should pass +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 usec\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_64.bucket, + _materialized_hypertable_64.temperature + FROM _timescaledb_internal._materialized_hypertable_64 + WHERE _materialized_hypertable_64.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_65.bucket, + _materialized_hypertable_65.temperature + FROM _timescaledb_internal._materialized_hypertable_65 + WHERE _materialized_hypertable_65.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- test microseconds - SHOULD FAIL +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1160 usec\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_66.bucket, + _materialized_hypertable_66.temperature + FROM _timescaledb_internal._materialized_hypertable_66 + WHERE _materialized_hypertable_66.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 0.00116 secs] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 0.000146 secs]. +\d+ :CAGG_NAME_2TH_LEVEL +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; diff --git a/tsl/test/expected/cagg_on_cagg_dist_ht.out b/tsl/test/expected/cagg_on_cagg_dist_ht.out index ee1b6999ed2..6b2dda76943 100644 --- a/tsl/test/expected/cagg_on_cagg_dist_ht.out +++ b/tsl/test/expected/cagg_on_cagg_dist_ht.out @@ -4279,6 +4279,423 @@ DETAIL: Time bucket width of "public.conditions_summary_2" [@ 30 days] should b DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- bug report 5277 +\set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE +\set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE +-- epoch plus cast to int would compute a bucket width of 0 for parent +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_58.bucket, + _materialized_hypertable_58.temperature + FROM _timescaledb_internal._materialized_hypertable_58 + WHERE _materialized_hypertable_58.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(58)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_59.bucket, + _materialized_hypertable_59.temperature + FROM _timescaledb_internal._materialized_hypertable_59 + WHERE _materialized_hypertable_59.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(59)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1.168 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +\set BUCKET_WIDTH_1ST 'INTERVAL \'9344 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'74752 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_60.bucket, + _materialized_hypertable_60.temperature + FROM _timescaledb_internal._materialized_hypertable_60 + WHERE _materialized_hypertable_60.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 9.344 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(60)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 9.344 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_61.bucket, + _materialized_hypertable_61.temperature + FROM _timescaledb_internal._materialized_hypertable_61 + WHERE _materialized_hypertable_61.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(61)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +\set BUCKET_WIDTH_1ST 'INTERVAL \'74752 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'598016 ms\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_62.bucket, + _materialized_hypertable_62.temperature + FROM _timescaledb_internal._materialized_hypertable_62 + WHERE _materialized_hypertable_62.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 1 min 14.752 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(62)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 1 min 14.752 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_63.bucket, + _materialized_hypertable_63.temperature + FROM _timescaledb_internal._materialized_hypertable_63 + WHERE _materialized_hypertable_63.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(63)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 9 mins 58.016 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- test microseconds - should pass +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 usec\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_64.bucket, + _materialized_hypertable_64.temperature + FROM _timescaledb_internal._materialized_hypertable_64 + WHERE _materialized_hypertable_64.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(64)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_2TH_LEVEL + View "public.conditions_summary_2" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_65.bucket, + _materialized_hypertable_65.temperature + FROM _timescaledb_internal._materialized_hypertable_65 + WHERE _materialized_hypertable_65.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket) AS bucket, + sum(conditions_summary_1.temperature) AS temperature + FROM conditions_summary_1 + WHERE conditions_summary_1.bucket >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(65)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.001168 secs'::interval, conditions_summary_1.bucket)); + +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; +-- test microseconds - SHOULD FAIL +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1160 usec\'' +\ir include/cagg_on_cagg_validations.sql +-- 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. +\set CAGG_NAME_1ST_LEVEL conditions_summary_1 +\set CAGG_NAME_2TH_LEVEL conditions_summary_2 +-- +-- CAGG on hypertable (1st level) +-- +CREATE MATERIALIZED VIEW :CAGG_NAME_1ST_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_1ST + time_bucket(:BUCKET_WIDTH_1ST, "time", :'BUCKET_TZNAME_1ST') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_1ST, "time") AS bucket, + \endif + SUM(temperature) AS temperature +FROM conditions +GROUP BY 1 +WITH NO DATA; +\d+ :CAGG_NAME_1ST_LEVEL + View "public.conditions_summary_1" + Column | Type | Collation | Nullable | Default | Storage | Description +-------------+--------------------------+-----------+----------+---------+---------+------------- + bucket | timestamp with time zone | | | | plain | + temperature | numeric | | | | main | +View definition: + SELECT _materialized_hypertable_66.bucket, + _materialized_hypertable_66.temperature + FROM _timescaledb_internal._materialized_hypertable_66 + WHERE _materialized_hypertable_66.bucket < COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) +UNION ALL + SELECT time_bucket('@ 0.000146 secs'::interval, conditions."time") AS bucket, + sum(conditions.temperature) AS temperature + FROM conditions + WHERE conditions."time" >= COALESCE(_timescaledb_internal.to_timestamp(_timescaledb_internal.cagg_watermark(66)), '-infinity'::timestamp with time zone) + GROUP BY (time_bucket('@ 0.000146 secs'::interval, conditions."time")); + +-- +-- CAGG on CAGG (2th level) +-- +\set VERBOSITY default +\set ON_ERROR_STOP 0 +\echo :WARNING_MESSAGE +-- SHOULD WORK +CREATE MATERIALIZED VIEW :CAGG_NAME_2TH_LEVEL +WITH (timescaledb.continuous) AS +SELECT + \if :IS_TIME_DIMENSION_WITH_TIMEZONE_2TH + time_bucket(:BUCKET_WIDTH_2TH, "bucket", :'BUCKET_TZNAME_2TH') AS bucket, + \else + time_bucket(:BUCKET_WIDTH_2TH, "bucket") AS bucket, + \endif + SUM(temperature) AS temperature +FROM :CAGG_NAME_1ST_LEVEL +GROUP BY 1 +WITH NO DATA; +psql:include/cagg_on_cagg_validations.sql:43: ERROR: cannot create continuous aggregate with incompatible bucket width +DETAIL: Time bucket width of "public.conditions_summary_2" [@ 0.00116 secs] should be multiple of the time bucket width of "public.conditions_summary_1" [@ 0.000146 secs]. +\d+ :CAGG_NAME_2TH_LEVEL +\set ON_ERROR_STOP 1 +\set VERBOSITY terse +-- +-- Cleanup +-- +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_2TH_LEVEL; +psql:include/cagg_on_cagg_validations.sql:53: NOTICE: materialized view "conditions_summary_2" does not exist, skipping +DROP MATERIALIZED VIEW IF EXISTS :CAGG_NAME_1ST_LEVEL; -- Cleanup \c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER; DROP DATABASE :DATA_NODE_1; diff --git a/tsl/test/sql/cagg_on_cagg.sql b/tsl/test/sql/cagg_on_cagg.sql index 1020e443d40..a0025cd186c 100644 --- a/tsl/test/sql/cagg_on_cagg.sql +++ b/tsl/test/sql/cagg_on_cagg.sql @@ -271,3 +271,30 @@ SET timezone TO 'UTC'; \set BUCKET_WIDTH_1ST 'INTERVAL \'1 week\'' \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' \ir include/cagg_on_cagg_validations.sql + +-- bug report 5277 +\set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE +\set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE + +-- epoch plus cast to int would compute a bucket width of 0 for parent +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 ms\'' +\ir include/cagg_on_cagg_validations.sql + +\set BUCKET_WIDTH_1ST 'INTERVAL \'9344 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'74752 ms\'' +\ir include/cagg_on_cagg_validations.sql + +\set BUCKET_WIDTH_1ST 'INTERVAL \'74752 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'598016 ms\'' +\ir include/cagg_on_cagg_validations.sql + +-- test microseconds - should pass +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 usec\'' +\ir include/cagg_on_cagg_validations.sql + +-- test microseconds - SHOULD FAIL +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1160 usec\'' +\ir include/cagg_on_cagg_validations.sql diff --git a/tsl/test/sql/cagg_on_cagg_dist_ht.sql b/tsl/test/sql/cagg_on_cagg_dist_ht.sql index 5350e59e6f7..d3cb4937dbf 100644 --- a/tsl/test/sql/cagg_on_cagg_dist_ht.sql +++ b/tsl/test/sql/cagg_on_cagg_dist_ht.sql @@ -286,6 +286,33 @@ SET timezone TO 'UTC'; \set BUCKET_WIDTH_2TH 'INTERVAL \'1 month\'' \ir include/cagg_on_cagg_validations.sql +-- bug report 5277 +\set IS_TIME_DIMENSION_WITH_TIMEZONE_1ST FALSE +\set IS_TIME_DIMENSION_WITH_TIMEZONE_2TH FALSE + +-- epoch plus cast to int would compute a bucket width of 0 for parent +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 ms\'' +\ir include/cagg_on_cagg_validations.sql + +\set BUCKET_WIDTH_1ST 'INTERVAL \'9344 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'74752 ms\'' +\ir include/cagg_on_cagg_validations.sql + +\set BUCKET_WIDTH_1ST 'INTERVAL \'74752 ms\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'598016 ms\'' +\ir include/cagg_on_cagg_validations.sql + +-- test microseconds - should pass +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1168 usec\'' +\ir include/cagg_on_cagg_validations.sql + +-- test microseconds - SHOULD FAIL +\set BUCKET_WIDTH_1ST 'INTERVAL \'146 usec\'' +\set BUCKET_WIDTH_2TH 'INTERVAL \'1160 usec\'' +\ir include/cagg_on_cagg_validations.sql + -- Cleanup \c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER; DROP DATABASE :DATA_NODE_1;