Skip to content

Commit

Permalink
Fix CAgg migration with timestamp without timezone
Browse files Browse the repository at this point in the history
It was a leftover from the original implementation where we didn't add
tests for time dimension using `timestamp without timezone`.

Fixed it by dealing with this datatype and added regression tests.

Fixes timescale#4956
  • Loading branch information
fabriziomello committed Nov 10, 2022
1 parent 6ad2824 commit ebdac12
Show file tree
Hide file tree
Showing 16 changed files with 1,729 additions and 359 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Expand Up @@ -25,9 +25,11 @@ argument or resolve the type ambiguity by casting to the intended type.
* #4696 Report warning when enabling compression on hypertable
* #4745 Fix FK constraint violation error while insert into hypertable which references partitioned table
* #4756 Improve compression job IO performance
* #4807 Fix segmentation fault during INSERT into compressed hypertable.
* #4807 Fix segmentation fault during INSERT into compressed hypertable
* #4840 Fix performance regressions in the copy code
* #4823 Fix a crash that could occur when using nested user-defined functions with hypertables.
* #4823 Fix a crash that could occur when using nested user-defined functions with hypertables
* #4898 Fix cagg migration failure when trying to resume
* #4955 Fix cagg migration for hypertables using timestamp without timezone

**Thanks**
* @jflambert for reporting a crash with nested user-defined functions.
Expand Down
2 changes: 2 additions & 0 deletions sql/cagg_migrate.sql
Expand Up @@ -367,6 +367,8 @@ BEGIN
CASE _plan_step.config->>'window_start_type'
WHEN 'timestamp with time zone' THEN
CALL @extschema@.refresh_continuous_aggregate(_cagg, (_plan_step.config->>'window_start')::timestamptz, NULL);
WHEN 'timestamp without time zone' THEN
CALL @extschema@.refresh_continuous_aggregate(_cagg, (_plan_step.config->>'window_start')::timestamp, NULL);
WHEN 'bigint' THEN
CALL @extschema@.refresh_continuous_aggregate(_cagg, (_plan_step.config->>'window_start')::bigint, NULL);
WHEN 'integer' THEN
Expand Down
91 changes: 43 additions & 48 deletions tsl/test/expected/cagg_migrate_integer.out

Large diffs are not rendered by default.

91 changes: 43 additions & 48 deletions tsl/test/expected/cagg_migrate_integer_dist_ht.out

Large diffs are not rendered by default.

244 changes: 120 additions & 124 deletions tsl/test/expected/cagg_migrate_timestamp.out

Large diffs are not rendered by default.

244 changes: 120 additions & 124 deletions tsl/test/expected/cagg_migrate_timestamp_dist_ht.out

Large diffs are not rendered by default.

651 changes: 651 additions & 0 deletions tsl/test/expected/cagg_migrate_timestamptz.out

Large diffs are not rendered by default.

691 changes: 691 additions & 0 deletions tsl/test/expected/cagg_migrate_timestamptz_dist_ht.out

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tsl/test/sql/CMakeLists.txt
Expand Up @@ -58,6 +58,8 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
cagg_migrate_integer_dist_ht.sql
cagg_migrate_timestamp.sql
cagg_migrate_timestamp_dist_ht.sql
cagg_migrate_timestamptz.sql
cagg_migrate_timestamptz_dist_ht.sql
cagg_multi.sql
continuous_aggs_deprecated.sql
cagg_tableam.sql
Expand Down
1 change: 1 addition & 0 deletions tsl/test/sql/cagg_migrate_integer.sql
Expand Up @@ -4,5 +4,6 @@

\set IS_DISTRIBUTED FALSE
\set IS_TIME_DIMENSION FALSE
\set TIME_DIMENSION_DATATYPE INTEGER

\ir include/cagg_migrate_common.sql
1 change: 1 addition & 0 deletions tsl/test/sql/cagg_migrate_integer_dist_ht.sql
Expand Up @@ -23,6 +23,7 @@ GRANT USAGE ON FOREIGN SERVER :DATA_NODE_1, :DATA_NODE_2, :DATA_NODE_3 TO PUBLIC

\set IS_DISTRIBUTED TRUE
\set IS_TIME_DIMENSION FALSE
\set TIME_DIMENSION_DATATYPE INTEGER

\ir include/cagg_migrate_common.sql

Expand Down
1 change: 1 addition & 0 deletions tsl/test/sql/cagg_migrate_timestamp.sql
Expand Up @@ -4,5 +4,6 @@

\set IS_DISTRIBUTED FALSE
\set IS_TIME_DIMENSION TRUE
\set TIME_DIMENSION_DATATYPE TIMESTAMP

\ir include/cagg_migrate_common.sql
1 change: 1 addition & 0 deletions tsl/test/sql/cagg_migrate_timestamp_dist_ht.sql
Expand Up @@ -23,6 +23,7 @@ GRANT USAGE ON FOREIGN SERVER :DATA_NODE_1, :DATA_NODE_2, :DATA_NODE_3 TO PUBLIC

\set IS_DISTRIBUTED TRUE
\set IS_TIME_DIMENSION TRUE
\set TIME_DIMENSION_DATATYPE TIMESTAMP

\ir include/cagg_migrate_common.sql

Expand Down
9 changes: 9 additions & 0 deletions tsl/test/sql/cagg_migrate_timestamptz.sql
@@ -0,0 +1,9 @@
-- 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 IS_DISTRIBUTED FALSE
\set IS_TIME_DIMENSION TRUE
\set TIME_DIMENSION_DATATYPE TIMESTAMPTZ

\ir include/cagg_migrate_common.sql
34 changes: 34 additions & 0 deletions tsl/test/sql/cagg_migrate_timestamptz_dist_ht.sql
@@ -0,0 +1,34 @@
-- 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 up a distributed environment
------------------------------------
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER

\set DATA_NODE_1 :TEST_DBNAME _1
\set DATA_NODE_2 :TEST_DBNAME _2
\set DATA_NODE_3 :TEST_DBNAME _3

\ir include/remote_exec.sql

SELECT node_name, database, node_created, database_created, extension_created
FROM (
SELECT (add_data_node(name, host => 'localhost', DATABASE => name)).*
FROM (VALUES (:'DATA_NODE_1'), (:'DATA_NODE_2'), (:'DATA_NODE_3')) v(name)
) a;

GRANT USAGE ON FOREIGN SERVER :DATA_NODE_1, :DATA_NODE_2, :DATA_NODE_3 TO PUBLIC;

\set IS_DISTRIBUTED TRUE
\set IS_TIME_DIMENSION TRUE
\set TIME_DIMENSION_DATATYPE TIMESTAMPTZ

\ir include/cagg_migrate_common.sql

-- cleanup
\c :TEST_DBNAME :ROLE_CLUSTER_SUPERUSER;
DROP DATABASE :DATA_NODE_1;
DROP DATABASE :DATA_NODE_2;
DROP DATABASE :DATA_NODE_3;
19 changes: 6 additions & 13 deletions tsl/test/sql/include/cagg_migrate_common.sql
Expand Up @@ -10,14 +10,8 @@
\echo 'Running local hypertable tests'
\endif

\if :IS_TIME_DIMENSION
\set TIME_DATATYPE TIMESTAMPTZ
\else
\set TIME_DATATYPE INTEGER
\endif

CREATE TABLE conditions (
"time" :TIME_DATATYPE NOT NULL,
"time" :TIME_DIMENSION_DATATYPE NOT NULL,
temperature NUMERIC
);

Expand All @@ -42,18 +36,17 @@ CREATE TABLE conditions (
0.25;
\else
CREATE OR REPLACE FUNCTION integer_now()
RETURNS integer LANGUAGE SQL STABLE AS
RETURNS :TIME_DIMENSION_DATATYPE LANGUAGE SQL STABLE AS
$$
SELECT coalesce(max(time), 0)
FROM public.conditions
$$;

\if :IS_DISTRIBUTED
CALL distributed_exec (
$DIST$
CREATE OR REPLACE FUNCTION integer_now() RETURNS integer LANGUAGE SQL STABLE AS $$ SELECT coalesce(max(time), 0) FROM public.conditions $$;
$DIST$
);
SELECT
'CREATE OR REPLACE FUNCTION integer_now() RETURNS '||:'TIME_DIMENSION_DATATYPE'||' LANGUAGE SQL STABLE AS $$ SELECT coalesce(max(time), 0) FROM public.conditions $$;' AS "STMT"
\gset
CALL distributed_exec (:'STMT');
\endif

SELECT set_integer_now_func('conditions', 'integer_now');
Expand Down

0 comments on commit ebdac12

Please sign in to comment.