From e4fbcfe3cf1de4dd53f09a5f314b23c015bbb650 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Fri, 27 Aug 2021 12:21:45 +0300 Subject: [PATCH] EditorConfig --- .../udfs/create_missing_partitions/10.2-1.sql | 2 +- .../udfs/create_missing_partitions/latest.sql | 2 +- .../get_missing_partition_ranges/10.2-1.sql | 5 ++-- .../get_missing_partition_ranges/latest.sql | 5 ++-- .../expected/upgrade_list_citus_objects.out | 8 +++++- ...imeseries_create_drop_timeseries_table.sql | 26 +++++++++---------- .../timeseries_create_missing_partitions.sql | 26 +++++++++---------- ...imeseries_get_missing_partition_ranges.sql | 24 ++++++++--------- src/test/regress/timeseries_schedule | 2 +- 9 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/backend/timeseries/sql/udfs/create_missing_partitions/10.2-1.sql b/src/backend/timeseries/sql/udfs/create_missing_partitions/10.2-1.sql index bf3e41aef..89a086a11 100644 --- a/src/backend/timeseries/sql/udfs/create_missing_partitions/10.2-1.sql +++ b/src/backend/timeseries/sql/udfs/create_missing_partitions/10.2-1.sql @@ -29,7 +29,7 @@ BEGIN SELECT * FROM get_missing_partition_ranges(table_name, to_date, start_from) LOOP - current_partition_name := table_name::text || '_' || current_partition_count::text; + current_partition_name := table_name::text || '_' || current_partition_count::text; EXECUTE format('CREATE TABLE %I PARTITION OF %I FOR VALUES FROM (''%I'') TO (''%I'')', current_partition_name, table_name::text, range_values_record.range_from_value, range_values_record.range_to_value); current_partition_count := current_partition_count + 1; END LOOP; diff --git a/src/backend/timeseries/sql/udfs/create_missing_partitions/latest.sql b/src/backend/timeseries/sql/udfs/create_missing_partitions/latest.sql index bf3e41aef..89a086a11 100644 --- a/src/backend/timeseries/sql/udfs/create_missing_partitions/latest.sql +++ b/src/backend/timeseries/sql/udfs/create_missing_partitions/latest.sql @@ -29,7 +29,7 @@ BEGIN SELECT * FROM get_missing_partition_ranges(table_name, to_date, start_from) LOOP - current_partition_name := table_name::text || '_' || current_partition_count::text; + current_partition_name := table_name::text || '_' || current_partition_count::text; EXECUTE format('CREATE TABLE %I PARTITION OF %I FOR VALUES FROM (''%I'') TO (''%I'')', current_partition_name, table_name::text, range_values_record.range_from_value, range_values_record.range_to_value); current_partition_count := current_partition_count + 1; END LOOP; diff --git a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql index 6c366be91..7bd63adf2 100644 --- a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql +++ b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/10.2-1.sql @@ -111,7 +111,8 @@ BEGIN * Since partition interval can be given as, we are converting all variables to timestamptz to make sure * that we are comparing same type of parameters */ - PERFORM * FROM pg_catalog.time_partitions WHERE from_value::timestamptz = current_range_from_value::timestamptz AND to_value::timestamptz = current_range_to_value::timestamptz; + PERFORM * FROM pg_catalog.time_partitions + WHERE from_value::timestamptz = current_range_from_value::timestamptz AND to_value::timestamptz = current_range_to_value::timestamptz; IF found THEN current_range_from_value := current_range_to_value; current_range_to_value := current_range_to_value + table_partition_interval; @@ -122,7 +123,7 @@ BEGIN * Check whether any other partition covers from_value or to_value * That means some partitions have been created manually and we must error out. */ - PERFORM * FROM pg_catalog.time_partitions + PERFORM * FROM pg_catalog.time_partitions WHERE (current_range_from_value::timestamptz > from_value::timestamptz AND current_range_from_value < to_value::timestamptz) OR (current_range_to_value::timestamptz > from_value::timestamptz AND current_range_to_value::timestamptz < to_value::timestamptz); IF found THEN diff --git a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql index 6c366be91..7bd63adf2 100644 --- a/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql +++ b/src/backend/timeseries/sql/udfs/get_missing_partition_ranges/latest.sql @@ -111,7 +111,8 @@ BEGIN * Since partition interval can be given as, we are converting all variables to timestamptz to make sure * that we are comparing same type of parameters */ - PERFORM * FROM pg_catalog.time_partitions WHERE from_value::timestamptz = current_range_from_value::timestamptz AND to_value::timestamptz = current_range_to_value::timestamptz; + PERFORM * FROM pg_catalog.time_partitions + WHERE from_value::timestamptz = current_range_from_value::timestamptz AND to_value::timestamptz = current_range_to_value::timestamptz; IF found THEN current_range_from_value := current_range_to_value; current_range_to_value := current_range_to_value + table_partition_interval; @@ -122,7 +123,7 @@ BEGIN * Check whether any other partition covers from_value or to_value * That means some partitions have been created manually and we must error out. */ - PERFORM * FROM pg_catalog.time_partitions + PERFORM * FROM pg_catalog.time_partitions WHERE (current_range_from_value::timestamptz > from_value::timestamptz AND current_range_from_value < to_value::timestamptz) OR (current_range_to_value::timestamptz > from_value::timestamptz AND current_range_to_value::timestamptz < to_value::timestamptz); IF found THEN diff --git a/src/test/regress/expected/upgrade_list_citus_objects.out b/src/test/regress/expected/upgrade_list_citus_objects.out index 6ee6a3084..627690ef0 100644 --- a/src/test/regress/expected/upgrade_list_citus_objects.out +++ b/src/test/regress/expected/upgrade_list_citus_objects.out @@ -116,8 +116,11 @@ ORDER BY 1; function create_distributed_function(regprocedure,text,text) function create_distributed_table(regclass,text,citus.distribution_type,text,integer) function create_intermediate_result(text,text) + function create_missing_partitions(regclass,timestamp with time zone,timestamp with time zone) function create_reference_table(regclass) + function create_timeseries_table(regclass,interval,integer,integer,timestamp with time zone,interval,interval) function distributed_tables_colocated(regclass,regclass) + function drop_timeseries_table(regclass) function dump_global_wait_edges() function dump_local_wait_edges() function fetch_intermediate_results(text[],text,integer) @@ -128,6 +131,7 @@ ORDER BY 1; function get_colocated_table_array(regclass) function get_current_transaction_id() function get_global_active_transactions() + function get_missing_partition_ranges(regclass,timestamp with time zone,timestamp with time zone) function get_rebalance_progress() function get_rebalance_table_shards_plan(regclass,real,integer,bigint[],boolean,name,real) function get_shard_id_for_distribution_column(regclass,"any") @@ -217,6 +221,7 @@ ORDER BY 1; function worker_save_query_explain_analyze(text,jsonb) schema citus schema citus_internal + schema citus_timeseries schema columnar sequence columnar.storageid_seq sequence pg_dist_colocationid_seq @@ -225,6 +230,7 @@ ORDER BY 1; sequence pg_dist_placement_placementid_seq sequence pg_dist_shardid_seq table citus.pg_dist_object + table citus_timeseries.citus_timeseries_tables table columnar.chunk table columnar.chunk_group table columnar.options @@ -254,5 +260,5 @@ ORDER BY 1; view citus_worker_stat_activity view pg_dist_shard_placement view time_partitions -(238 rows) +(244 rows) diff --git a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql index 95f9bd8e2..d06f5b886 100644 --- a/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql +++ b/src/test/regress/sql/timeseries_create_drop_timeseries_table.sql @@ -78,7 +78,7 @@ ROLLBACK; DROP TABLE date_partitioned_table; --- 2) retention threshold must be greater than compression threshold and +-- 2) retention threshold must be greater than compression threshold and -- compresstion threshold must be greater than partition interval -- With date partitioned table @@ -183,37 +183,37 @@ CREATE TABLE range_check_test_partitioned_table( BEGIN; SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 hour'); - SELECT partition, + SELECT partition, date_trunc('hour',now()) - from_value::timestamptz as from_diff, - date_trunc('hour', now()) - to_value::timestamptz as to_diff - FROM pg_catalog.time_partitions + date_trunc('hour', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions ORDER BY 1; ROLLBACK; BEGIN; SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 day', postmake_interval_count => 5); - SELECT partition, + SELECT partition, date_trunc('day',now()) - from_value::timestamptz as from_diff, - date_trunc('day', now()) - to_value::timestamptz as to_diff - FROM pg_catalog.time_partitions + date_trunc('day', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions ORDER BY 1; ROLLBACK; BEGIN; SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', premake_interval_count => 3); - SELECT partition, + SELECT partition, date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff - FROM pg_catalog.time_partitions + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions ORDER BY 1; ROLLBACK; BEGIN; SELECT create_timeseries_table('range_check_test_partitioned_table', INTERVAL '1 week', start_from => now() - INTERVAL '4 weeks'); - SELECT partition, + SELECT partition, date_trunc('week',now()) - from_value::timestamptz as from_diff, - date_trunc('week', now()) - to_value::timestamptz as to_diff - FROM pg_catalog.time_partitions + date_trunc('week', now()) - to_value::timestamptz as to_diff + FROM pg_catalog.time_partitions ORDER BY 1; ROLLBACK; diff --git a/src/test/regress/sql/timeseries_create_missing_partitions.sql b/src/test/regress/sql/timeseries_create_missing_partitions.sql index 0801685f3..dc04a3542 100644 --- a/src/test/regress/sql/timeseries_create_missing_partitions.sql +++ b/src/test/regress/sql/timeseries_create_missing_partitions.sql @@ -10,7 +10,7 @@ SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '15 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::date as from_diff, date_trunc('day', now()) - to_value::date as to_diff FROM pg_catalog.time_partitions @@ -21,7 +21,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '10 days', now() + INTERVAL '10 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::date as from_diff, date_trunc('day', now()) - to_value::date as to_diff FROM pg_catalog.time_partitions @@ -32,7 +32,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '45 days', now() + INTERVAL '45 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::date as from_diff, date_trunc('day', now()) - to_value::date as to_diff FROM pg_catalog.time_partitions @@ -43,7 +43,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '65 days', now() + INTERVAL '65 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::date as from_diff, date_trunc('day', now()) - to_value::date as to_diff FROM pg_catalog.time_partitions @@ -54,7 +54,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); SELECT create_missing_partitions('date_partitioned_table', now() + INTERVAL '5 days', now() + INTERVAL '5 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::date as from_diff, date_trunc('day', now()) - to_value::date as to_diff FROM pg_catalog.time_partitions @@ -73,7 +73,7 @@ CREATE TABLE tstz_partitioned_table( BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff FROM pg_catalog.time_partitions @@ -84,7 +84,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff FROM pg_catalog.time_partitions @@ -95,7 +95,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '6 hours'); SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp with time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp with time zone as to_diff FROM pg_catalog.time_partitions @@ -106,7 +106,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); SELECT create_missing_partitions('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::timestamp with time zone as from_diff, date_trunc('day', now()) - to_value::timestamp with time zone as to_diff FROM pg_catalog.time_partitions @@ -124,7 +124,7 @@ CREATE TABLE tswtz_partitioned_table( BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff FROM pg_catalog.time_partitions @@ -135,7 +135,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff FROM pg_catalog.time_partitions @@ -146,7 +146,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day'); - SELECT + SELECT date_trunc('hour', now()) - from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - to_value::timestamp without time zone as to_diff FROM pg_catalog.time_partitions @@ -157,7 +157,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); SELECT create_missing_partitions('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days'); - SELECT + SELECT date_trunc('day', now()) - from_value::timestamp without time zone as from_diff, date_trunc('day', now()) - to_value::timestamp without time zone as to_diff FROM pg_catalog.time_partitions diff --git a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql index b2313d41a..14084be9f 100644 --- a/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql +++ b/src/test/regress/sql/timeseries_get_missing_partition_ranges.sql @@ -9,7 +9,7 @@ SELECT get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL ' -- Show range values for data partitioned table BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days') @@ -18,7 +18,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '15 days', now() - INTERVAL '15 days') @@ -27,7 +27,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '5 days'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '45 days', now() - INTERVAL '45 days') @@ -36,7 +36,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 week'); - SELECT + SELECT date_trunc('week', now()) - range_from_value::date as from_diff, date_trunc('week', now()) - range_to_value::date as to_diff FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '65 days', now() - INTERVAL '65 days') @@ -45,7 +45,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('date_partitioned_table', INTERVAL '1 day'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::date as from_diff, date_trunc('day', now()) - range_to_value::date as to_diff FROM get_missing_partition_ranges('date_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') @@ -62,7 +62,7 @@ CREATE TABLE tstz_partitioned_table( BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); - SELECT + SELECT date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day') @@ -71,7 +71,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 hour'); - SELECT + SELECT date_trunc('hour', now()) - range_from_value::timestamp with time zone as from_diff, date_trunc('hour', now()) - range_to_value::timestamp with time zone as to_diff FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') @@ -89,7 +89,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tstz_partitioned_table', INTERVAL '1 day'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::timestamp with time zone as from_diff, date_trunc('day', now()) - range_to_value::timestamp with time zone as to_diff FROM get_missing_partition_ranges('tstz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') @@ -106,7 +106,7 @@ CREATE TABLE tswtz_partitioned_table( BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); - SELECT + SELECT date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day') @@ -115,7 +115,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 hour'); - SELECT + SELECT date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') @@ -124,7 +124,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '6 hours'); - SELECT + SELECT date_trunc('hour', now()) - range_from_value::timestamp without time zone as from_diff, date_trunc('hour', now()) - range_to_value::timestamp without time zone as to_diff FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '1 day', now() - INTERVAL '1 day') @@ -133,7 +133,7 @@ ROLLBACK; BEGIN; SELECT create_timeseries_table('tswtz_partitioned_table', INTERVAL '1 day'); - SELECT + SELECT date_trunc('day', now()) - range_from_value::timestamp without time zone as from_diff, date_trunc('day', now()) - range_to_value::timestamp without time zone as to_diff FROM get_missing_partition_ranges('tswtz_partitioned_table', now() + INTERVAL '5 days', now() - INTERVAL '5 days') diff --git a/src/test/regress/timeseries_schedule b/src/test/regress/timeseries_schedule index cd30f6f6e..89500e2e7 100644 --- a/src/test/regress/timeseries_schedule +++ b/src/test/regress/timeseries_schedule @@ -4,4 +4,4 @@ test: multi_test_catalog_views test: timeseries_create_drop_timeseries_table test: timeseries_get_missing_partition_ranges -test: timeseries_create_missing_partitions \ No newline at end of file +test: timeseries_create_missing_partitions