From 788e09a39aba40367241d92af4e2ab0d2950f3fd Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Mon, 16 Oct 2023 11:38:24 +0200 Subject: [PATCH] Add a test for citus_shards where table names have spaces (#7224) There was a bug reported for previous versions of Citus where shard\_size was returning NULL for tables with spaces in them. It works fine on the main branch though, but I'm still adding a test for this to the main branch because it seems a good test to have. --- src/test/regress/citus_tests/run_test.py | 1 + src/test/regress/expected/citus_shards.out | 37 ++++++++++++++++++++++ src/test/regress/multi_1_schedule | 2 ++ src/test/regress/sql/citus_shards.sql | 17 ++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/test/regress/expected/citus_shards.out create mode 100644 src/test/regress/sql/citus_shards.sql diff --git a/src/test/regress/citus_tests/run_test.py b/src/test/regress/citus_tests/run_test.py index f1e1ec827..6528834ae 100755 --- a/src/test/regress/citus_tests/run_test.py +++ b/src/test/regress/citus_tests/run_test.py @@ -152,6 +152,7 @@ DEPS = { worker_count=6, ), "function_propagation": TestDeps("minimal_schedule"), + "citus_shards": TestDeps("minimal_schedule"), "grant_on_foreign_server_propagation": TestDeps("minimal_schedule"), "multi_modifying_xacts": TestDeps("minimal_schedule"), "multi_mx_modifying_xacts": TestDeps(None, ["multi_mx_create_table"]), diff --git a/src/test/regress/expected/citus_shards.out b/src/test/regress/expected/citus_shards.out new file mode 100644 index 000000000..b434a984b --- /dev/null +++ b/src/test/regress/expected/citus_shards.out @@ -0,0 +1,37 @@ +CREATE SCHEMA citus_shards; +SET search_path TO citus_shards; +SET citus.shard_count TO 4; +SET citus.shard_replication_factor TO 1; +SET citus.next_shard_id TO 99456900; +ALTER SEQUENCE pg_catalog.pg_dist_colocationid_seq RESTART 456900; +CREATE TABLE t1 (i int); +SELECT create_distributed_table('t1', 'i'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE TABLE "t with space" (i int); +SELECT create_distributed_table('"t with space"', 'i'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +INSERT INTO t1 SELECT generate_series(1, 100); +INSERT INTO "t with space" SELECT generate_series(1, 1000); +SELECT * FROM citus_shards; + table_name | shardid | shard_name | citus_table_type | colocation_id | nodename | nodeport | shard_size +--------------------------------------------------------------------- + "t with space" | 99456904 | citus_shards."t with space_99456904" | distributed | 456900 | localhost | 57637 | 40960 + "t with space" | 99456905 | citus_shards."t with space_99456905" | distributed | 456900 | localhost | 57638 | 40960 + "t with space" | 99456906 | citus_shards."t with space_99456906" | distributed | 456900 | localhost | 57637 | 40960 + "t with space" | 99456907 | citus_shards."t with space_99456907" | distributed | 456900 | localhost | 57638 | 40960 + t1 | 99456900 | citus_shards.t1_99456900 | distributed | 456900 | localhost | 57637 | 8192 + t1 | 99456901 | citus_shards.t1_99456901 | distributed | 456900 | localhost | 57638 | 8192 + t1 | 99456902 | citus_shards.t1_99456902 | distributed | 456900 | localhost | 57637 | 8192 + t1 | 99456903 | citus_shards.t1_99456903 | distributed | 456900 | localhost | 57638 | 8192 +(8 rows) + +SET client_min_messages TO WARNING; +DROP SCHEMA citus_shards CASCADE; diff --git a/src/test/regress/multi_1_schedule b/src/test/regress/multi_1_schedule index 4dead5be3..ad70f136e 100644 --- a/src/test/regress/multi_1_schedule +++ b/src/test/regress/multi_1_schedule @@ -53,6 +53,8 @@ test: multi_read_from_secondaries test: grant_on_database_propagation test: alter_database_propagation +test: citus_shards + # ---------- # multi_citus_tools tests utility functions written for citus tools # ---------- diff --git a/src/test/regress/sql/citus_shards.sql b/src/test/regress/sql/citus_shards.sql new file mode 100644 index 000000000..9234ffd2e --- /dev/null +++ b/src/test/regress/sql/citus_shards.sql @@ -0,0 +1,17 @@ +CREATE SCHEMA citus_shards; +SET search_path TO citus_shards; +SET citus.shard_count TO 4; +SET citus.shard_replication_factor TO 1; +SET citus.next_shard_id TO 99456900; +ALTER SEQUENCE pg_catalog.pg_dist_colocationid_seq RESTART 456900; + +CREATE TABLE t1 (i int); +SELECT create_distributed_table('t1', 'i'); +CREATE TABLE "t with space" (i int); +SELECT create_distributed_table('"t with space"', 'i'); +INSERT INTO t1 SELECT generate_series(1, 100); +INSERT INTO "t with space" SELECT generate_series(1, 1000); +SELECT * FROM citus_shards; + +SET client_min_messages TO WARNING; +DROP SCHEMA citus_shards CASCADE;