Make function parameter names consistent

Renaming the parameter `hypertable_or_cagg` in functions `drop_chunks`
and `show_chunks` to `relation` and changing parameter name from
`main_table` to `hypertable` or `relation` depending on context.
This commit is contained in:
Mats Kindahl 2020-09-30 16:35:40 +02:00 committed by Mats Kindahl
parent b341506cb2
commit da97ce6e8b
11 changed files with 52 additions and 46 deletions

View File

@ -6,7 +6,7 @@
-- Converts a regular postgres table to a hypertable.
--
-- main_table - The OID of the table to be converted
-- relation - The OID of the table to be converted
-- time_column_name - Name of the column that contains time for a given record
-- partitioning_column - Name of the column to partition data by
-- number_partitions - (Optional) Number of partitions for data
@ -23,7 +23,7 @@
-- replication_factor - (Optional) A value of 1 or greater makes this hypertable distributed
-- data_nodes - (Optional) The specific data nodes to distribute this hypertable across
CREATE OR REPLACE FUNCTION create_hypertable(
main_table REGCLASS,
relation REGCLASS,
time_column_name NAME,
partitioning_column NAME = NULL,
number_partitions INTEGER = NULL,
@ -43,7 +43,7 @@ CREATE OR REPLACE FUNCTION create_hypertable(
-- Same functionality as create_hypertable, only must have a replication factor > 0 (defaults to 1)
CREATE OR REPLACE FUNCTION create_distributed_hypertable(
main_table REGCLASS,
relation REGCLASS,
time_column_name NAME,
partitioning_column NAME = NULL,
number_partitions INTEGER = NULL,
@ -71,20 +71,20 @@ CREATE OR REPLACE FUNCTION set_adaptive_chunking(
-- Update chunk_time_interval for a hypertable.
--
-- main_table - The OID of the table corresponding to a hypertable whose time
-- hypertable - The OID of the table corresponding to a hypertable whose time
-- interval should be updated
-- chunk_time_interval - The new time interval. For hypertables with integral
-- time columns, this must be an integral type. For hypertables with a
-- TIMESTAMP/TIMESTAMPTZ/DATE type, it can be integral which is treated as
-- microseconds, or an INTERVAL type.
CREATE OR REPLACE FUNCTION set_chunk_time_interval(
main_table REGCLASS,
hypertable REGCLASS,
chunk_time_interval ANYELEMENT,
dimension_name NAME = NULL
) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_dimension_set_interval' LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION set_number_partitions(
main_table REGCLASS,
hypertable REGCLASS,
number_partitions INTEGER,
dimension_name NAME = NULL
) RETURNS VOID AS '@MODULE_PATHNAME@', 'ts_dimension_set_num_slices' LANGUAGE C VOLATILE;
@ -92,7 +92,7 @@ CREATE OR REPLACE FUNCTION set_number_partitions(
-- Drop chunks older than the given timestamp for the specific
-- hypertable or continuous aggregate.
CREATE OR REPLACE FUNCTION drop_chunks(
hypertable_or_cagg REGCLASS,
relation REGCLASS,
older_than "any" = NULL,
newer_than "any" = NULL,
verbose BOOLEAN = FALSE
@ -100,9 +100,9 @@ CREATE OR REPLACE FUNCTION drop_chunks(
LANGUAGE C VOLATILE PARALLEL UNSAFE;
-- show chunks older than or newer than a specific time.
-- `hypertable` must be a valid hypertable or continuous aggregate.
-- `relation` must be a valid hypertable or continuous aggregate.
CREATE OR REPLACE FUNCTION show_chunks(
hypertable_or_cagg REGCLASS,
relation REGCLASS,
older_than "any" = NULL,
newer_than "any" = NULL
) RETURNS SETOF REGCLASS AS '@MODULE_PATHNAME@', 'ts_chunk_show_chunks'
@ -110,14 +110,14 @@ LANGUAGE C STABLE PARALLEL SAFE;
-- Add a dimension (of partitioning) to a hypertable
--
-- main_table - OID of the table to add a dimension to
-- hypertable - OID of the table to add a dimension to
-- column_name - NAME of the column to use in partitioning for this dimension
-- number_partitions - Number of partitions, for non-time dimensions
-- interval_length - Size of intervals for time dimensions (can be integral or INTERVAL)
-- partitioning_func - Function used to partition the column
-- if_not_exists - If set, and the dimension already exists, generate a notice instead of an error
CREATE OR REPLACE FUNCTION add_dimension(
main_table REGCLASS,
hypertable REGCLASS,
column_name NAME,
number_partitions INTEGER = NULL,
chunk_time_interval ANYELEMENT = NULL::BIGINT,

View File

@ -11,14 +11,17 @@
-- words, some data beyond the retention window
-- might be kept, but data within the window will never be deleted.
CREATE OR REPLACE FUNCTION add_retention_policy(
hypertable REGCLASS,
relation REGCLASS,
drop_after "any",
if_not_exists BOOL = false
)
RETURNS INTEGER AS '@MODULE_PATHNAME@', 'ts_policy_retention_add'
LANGUAGE C VOLATILE STRICT;
CREATE OR REPLACE FUNCTION remove_retention_policy(hypertable REGCLASS, if_exists BOOL = false) RETURNS VOID
CREATE OR REPLACE FUNCTION remove_retention_policy(
relation REGCLASS,
if_exists BOOL = false
) RETURNS VOID
AS '@MODULE_PATHNAME@', 'ts_policy_retention_remove'
LANGUAGE C VOLATILE STRICT;

View File

@ -153,16 +153,16 @@ $BODY$;
-- Get relation size of hypertable
-- like pg_relation_size(hypertable)
--
-- main_table - hypertable to get size of
-- hypertable - hypertable to get size of
--
-- Returns:
-- table_bytes - Disk space used by main_table (like pg_relation_size(main_table))
-- table_bytes - Disk space used by hypertable (like pg_relation_size(hypertable))
-- index_bytes - Disk space used by indexes
-- toast_bytes - Disk space of toast tables
-- total_bytes - Total disk space used by the specified table, including all indexes and TOAST data
CREATE OR REPLACE FUNCTION hypertable_detailed_size(
main_table REGCLASS
hypertable REGCLASS
)
RETURNS TABLE (table_bytes BIGINT,
index_bytes BIGINT,
@ -182,7 +182,7 @@ BEGIN
FROM pg_class c
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname AND ht.table_name = c.relname)
WHERE c.OID = main_table;
WHERE c.OID = hypertable;
CASE WHEN is_distributed THEN
RETURN QUERY SELECT * FROM _timescaledb_internal.hypertable_remote_size(schema_name, table_name);
@ -194,7 +194,7 @@ $BODY$;
--- returns total-bytes for a hypertable (includes table + index)
CREATE OR REPLACE FUNCTION hypertable_size(
main_table REGCLASS
hypertable REGCLASS
)
RETURNS BIGINT
LANGUAGE PLPGSQL VOLATILE STRICT AS
@ -203,7 +203,7 @@ DECLARE
num_bytes BIGINT;
BEGIN
SELECT sum(hd.total_bytes) INTO STRICT num_bytes
FROM hypertable_detailed_size(main_table) hd;
FROM hypertable_detailed_size(hypertable) hd;
RETURN num_bytes;
END;
$BODY$;
@ -288,7 +288,7 @@ END;
$BODY$;
-- Get relation size of the chunks of an hypertable
-- main_table - hypertable to get size of
-- hypertable - hypertable to get size of
--
-- Returns:
-- chunk_schema - schema name for chunk
@ -300,7 +300,7 @@ $BODY$;
-- node_name - node on which chunk lives if this is
-- a distributed hypertable.
CREATE OR REPLACE FUNCTION chunks_detailed_size(
main_table REGCLASS
hypertable REGCLASS
)
RETURNS TABLE (
chunk_schema NAME,
@ -322,7 +322,7 @@ BEGIN
FROM pg_class c
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname AND ht.table_name = c.relname)
WHERE c.OID = main_table;
WHERE c.OID = hypertable;
CASE WHEN is_distributed THEN
RETURN QUERY SELECT ch.chunk_schema, ch.chunk_name, ch.table_bytes, ch.index_bytes,
@ -367,7 +367,7 @@ $BODY$;
-- Convenience function to return approximate row count
--
-- main_table - table or hypertable to get approximate row count for
-- relation - table or hypertable to get approximate row count for
--
-- Returns:
-- Estimated number of rows according to catalog tables
@ -539,7 +539,7 @@ $BODY$;
-- Get per chunk compression statistics for a hypertable that has
-- compression enabled
CREATE OR REPLACE FUNCTION chunk_compression_stats (main_table REGCLASS)
CREATE OR REPLACE FUNCTION chunk_compression_stats (hypertable REGCLASS)
RETURNS TABLE (
chunk_schema name,
chunk_name name,
@ -573,7 +573,7 @@ BEGIN
INNER JOIN _timescaledb_catalog.hypertable ht ON (ht.schema_name = n.nspname
AND ht.table_name = c.relname)
WHERE
c.OID = main_table;
c.OID = hypertable;
CASE WHEN is_distributed THEN
RETURN QUERY
SELECT
@ -593,7 +593,7 @@ $BODY$;
-- Get compression statistics for a hypertable that has
-- compression enabled
CREATE OR REPLACE FUNCTION hypertable_compression_stats (main_table REGCLASS)
CREATE OR REPLACE FUNCTION hypertable_compression_stats (hypertable REGCLASS)
RETURNS TABLE (
total_chunks bigint,
number_compressed_chunks bigint,
@ -624,7 +624,7 @@ BEGIN
sum(ch.after_compression_total_bytes)::bigint AS after_compression_total_bytes,
ch.node_name
FROM
chunk_compression_stats (main_table) ch
chunk_compression_stats (hypertable) ch
GROUP BY
ch.node_name;
END;

View File

@ -24,6 +24,9 @@ DROP FUNCTION IF EXISTS show_chunks;
DROP FUNCTION IF EXISTS add_compress_chunks_policy;
DROP FUNCTION IF EXISTS remove_compress_chunks_policy;
DROP FUNCTION IF EXISTS alter_job_schedule;
DROP FUNCTION IF EXISTS set_chunk_time_interval;
DROP FUNCTION IF EXISTS set_number_partitions;
DROP FUNCTION IF EXISTS add_dimension;
DROP FUNCTION IF EXISTS _timescaledb_internal.enterprise_enabled;
DROP FUNCTION IF EXISTS _timescaledb_internal.current_license_key;
DROP FUNCTION IF EXISTS _timescaledb_internal.license_expiration_time;

View File

@ -1177,7 +1177,7 @@ TS_FUNCTION_INFO_V1(ts_dimension_set_interval);
/*
* Update chunk_time_interval for a hypertable.
*
* main_table - The OID of the table corresponding to a hypertable whose time
* hypertable - The OID of the table corresponding to a hypertable whose time
* interval should be updated
* chunk_time_interval - The new time interval. For hypertables with integral
* time columns, this must be an integral type. For hypertables with a

View File

@ -1761,7 +1761,7 @@ TS_FUNCTION_INFO_V1(ts_hypertable_distributed_create);
* Create a hypertable from an existing table.
*
* Arguments:
* main_table REGCLASS
* relation REGCLASS
* time_column_name NAME
* partitioning_column NAME = NULL
* number_partitions INTEGER = NULL

View File

@ -874,7 +874,7 @@ BEGIN;
_timescaledb_internal._hyper_5_21_chunk
(1 row)
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable_or_cagg => \'drop_chunk_test_tstz\')::NAME'
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', relation => \'drop_chunk_test_tstz\')::NAME'
\set QUERY2 'SELECT drop_chunks(\'drop_chunk_test_tstz\', interval \'1 minute\')::NAME'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2

View File

@ -112,7 +112,7 @@ SELECT AVG(temp) AS avg_tmp, "testSchema0".time_bucket('1 day', time, INTERVAL '
-- testing time_bucket END
-- testing drop_chunks START
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => \'2017-03-01\'::timestamp, hypertable_or_cagg => \'test_ts\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => \'2017-03-01\'::timestamp, relation => \'test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_ts\', \'2017-03-01\'::timestamp)::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
@ -129,7 +129,7 @@ SELECT * FROM test_ts ORDER BY time;
Mon Mar 20 09:37:00.936242 2017 | 30 | dev3
(4 rows)
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', hypertable_or_cagg => \'test_tz\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', relation => \'test_tz\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_tz\', interval \'1 minutes\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2
@ -142,7 +142,7 @@ SELECT * FROM test_tz ORDER BY time;
------+------+--------
(0 rows)
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', hypertable_or_cagg => \'test_dt\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', relation => \'test_dt\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_dt\', interval \'1 minutes\')::TEXT'
\set ECHO errors
Different Rows | Total Rows from Query 1 | Total Rows from Query 2

View File

@ -314,7 +314,7 @@ BEGIN;
SELECT show_chunks('drop_chunk_test_tstz', newer_than => now() - interval '1 minute');
SELECT show_chunks('drop_chunk_test_tstz', older_than => now() - interval '1 minute');
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', hypertable_or_cagg => \'drop_chunk_test_tstz\')::NAME'
\set QUERY1 'SELECT show_chunks(older_than => interval \'1 minute\', relation => \'drop_chunk_test_tstz\')::NAME'
\set QUERY2 'SELECT drop_chunks(\'drop_chunk_test_tstz\', interval \'1 minute\')::NAME'
\set ECHO errors
\ir :QUERY_RESULT_TEST_EQUAL_RELPATH

View File

@ -52,19 +52,19 @@ SELECT AVG(temp) AS avg_tmp, "testSchema0".time_bucket('1 day', time, INTERVAL '
-- testing drop_chunks START
-- show_chunks and drop_chunks output should be the same
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => \'2017-03-01\'::timestamp, hypertable_or_cagg => \'test_ts\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => \'2017-03-01\'::timestamp, relation => \'test_ts\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_ts\', \'2017-03-01\'::timestamp)::TEXT'
\set ECHO errors
\ir :QUERY_RESULT_TEST_EQUAL_RELPATH
\set ECHO all
SELECT * FROM test_ts ORDER BY time;
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', hypertable_or_cagg => \'test_tz\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', relation => \'test_tz\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_tz\', interval \'1 minutes\')::TEXT'
\set ECHO errors
\ir :QUERY_RESULT_TEST_EQUAL_RELPATH
\set ECHO all
SELECT * FROM test_tz ORDER BY time;
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', hypertable_or_cagg => \'test_dt\')::REGCLASS::TEXT'
\set QUERY1 'SELECT "testSchema0".show_chunks(older_than => interval \'1 minutes\', relation => \'test_dt\')::REGCLASS::TEXT'
\set QUERY2 'SELECT "testSchema0".drop_chunks(\'test_dt\', interval \'1 minutes\')::TEXT'
\set ECHO errors
\ir :QUERY_RESULT_TEST_EQUAL_RELPATH

View File

@ -11,21 +11,21 @@
-- test drop_chunks function deparsing
SELECT * FROM tsl_test_deparse_drop_chunks('myschema.table10', '2019-01-01'::timestamptz, verbose => true);
tsl_test_deparse_drop_chunks
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(hypertable_or_cagg => 'myschema.table10',older_than => 'Tue Jan 01 00:00:00 2019 PST'::timestamp with time zone,newer_than => NULL,verbose => 't')
tsl_test_deparse_drop_chunks
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(relation => 'myschema.table10',older_than => 'Tue Jan 01 00:00:00 2019 PST'::timestamp with time zone,newer_than => NULL,verbose => 't')
(1 row)
SELECT * FROM tsl_test_deparse_drop_chunks('table1', newer_than => 12345);
tsl_test_deparse_drop_chunks
------------------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(hypertable_or_cagg => 'public.table1',older_than => NULL,newer_than => '12345'::integer,verbose => 'f')
tsl_test_deparse_drop_chunks
--------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(relation => 'public.table1',older_than => NULL,newer_than => '12345'::integer,verbose => 'f')
(1 row)
SELECT * FROM tsl_test_deparse_drop_chunks('table1', older_than => interval '2 years', newer_than => '2015-01-01'::timestamp);
tsl_test_deparse_drop_chunks
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(hypertable_or_cagg => 'public.table1',older_than => '@ 2 years'::interval,newer_than => 'Thu Jan 01 00:00:00 2015'::timestamp without time zone,verbose => 'f')
tsl_test_deparse_drop_chunks
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT * FROM public.drop_chunks(relation => 'public.table1',older_than => '@ 2 years'::interval,newer_than => 'Thu Jan 01 00:00:00 2015'::timestamp without time zone,verbose => 'f')
(1 row)
-- test generalized deparsing function