From 6ebe673f5cd3267ab1513f55d513a76910f4cf5b Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Fri, 4 Mar 2022 15:37:13 +0300 Subject: [PATCH] Add tests --- .../regress/expected/function_propagation.out | 35 +++++++++++++++++++ src/test/regress/sql/function_propagation.sql | 29 +++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/test/regress/expected/function_propagation.out b/src/test/regress/expected/function_propagation.out index 7aefbb697..36d36b609 100644 --- a/src/test/regress/expected/function_propagation.out +++ b/src/test/regress/expected/function_propagation.out @@ -1070,6 +1070,41 @@ SELECT create_distributed_table('table_non_for_func_dist', 'a'); (1 row) +-- Show that causing circular dependency via functions are not allowed +CREATE TABLE table_1_for_circ_dep(id int); +select create_distributed_table('table_1_for_circ_dep','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE OR REPLACE FUNCTION func_1_for_circ_dep(col_1 table_1_for_circ_dep) +RETURNS int +LANGUAGE plpgsql AS +$$ +BEGIN +return 1; +END; +$$; +CREATE TABLE table_2_for_circ_dep(id int, col_2 int default func_1_for_circ_dep(NULL::table_1_for_circ_dep)); +select create_distributed_table('table_2_for_circ_dep','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +CREATE OR REPLACE FUNCTION func_2_for_circ_dep(col_3 table_2_for_circ_dep) +RETURNS int +LANGUAGE plpgsql AS +$$ +BEGIN +return 1; +END; +$$; +-- It should error out due to circular dependency +ALTER TABLE table_1_for_circ_dep ADD COLUMN col_2 int default func_2_for_circ_dep(NULL::table_2_for_circ_dep); +ERROR: Citus can not handle circular dependencies between distributed objects +DETAIL: "table table_1_for_circ_dep" circularly depends itself, resolve circular dependency first RESET search_path; SET client_min_messages TO WARNING; DROP SCHEMA function_propagation_schema CASCADE; diff --git a/src/test/regress/sql/function_propagation.sql b/src/test/regress/sql/function_propagation.sql index cd915045f..20617acf8 100644 --- a/src/test/regress/sql/function_propagation.sql +++ b/src/test/regress/sql/function_propagation.sql @@ -710,6 +710,35 @@ CREATE TABLE table_non_for_func_dist ( SELECT create_distributed_table('table_non_for_func_dist', 'a'); + +-- Show that causing circular dependency via functions are not allowed +CREATE TABLE table_1_for_circ_dep(id int); +select create_distributed_table('table_1_for_circ_dep','id'); + +CREATE OR REPLACE FUNCTION func_1_for_circ_dep(col_1 table_1_for_circ_dep) +RETURNS int +LANGUAGE plpgsql AS +$$ +BEGIN +return 1; +END; +$$; + +CREATE TABLE table_2_for_circ_dep(id int, col_2 int default func_1_for_circ_dep(NULL::table_1_for_circ_dep)); +select create_distributed_table('table_2_for_circ_dep','id'); +CREATE OR REPLACE FUNCTION func_2_for_circ_dep(col_3 table_2_for_circ_dep) +RETURNS int +LANGUAGE plpgsql AS +$$ +BEGIN +return 1; +END; +$$; + +-- It should error out due to circular dependency +ALTER TABLE table_1_for_circ_dep ADD COLUMN col_2 int default func_2_for_circ_dep(NULL::table_2_for_circ_dep); + + RESET search_path; SET client_min_messages TO WARNING; DROP SCHEMA function_propagation_schema CASCADE;