From 5266c0bfd1cfc71de817f9a31445039e46fedf46 Mon Sep 17 00:00:00 2001 From: Selfeer Date: Tue, 8 Oct 2024 16:23:51 +0400 Subject: [PATCH] remove ADD PRIMARY KEY --- .../tests/integration/helpers/cluster.py | 17 +++++++------- .../integration/helpers/default_config.py | 2 +- .../integration/tests/multiple_databases.py | 23 ------------------- .../integration/tests/steps/clickhouse.py | 18 +++++++++++++-- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/sink-connector-lightweight/tests/integration/helpers/cluster.py b/sink-connector-lightweight/tests/integration/helpers/cluster.py index 717def898..fd6063c88 100755 --- a/sink-connector-lightweight/tests/integration/helpers/cluster.py +++ b/sink-connector-lightweight/tests/integration/helpers/cluster.py @@ -596,14 +596,15 @@ def up(self, timeout=30 * 60): "IMAGE_DEPENDENCY_PROXY", "" ) self.environ["COMPOSE_HTTP_TIMEOUT"] = "300" - self.environ[ - "CLICKHOUSE_TESTS_SERVER_BIN_PATH" - ] = self.clickhouse_binary_path - self.environ[ - "CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH" - ] = self.clickhouse_odbc_bridge_binary_path or os.path.join( - os.path.dirname(self.clickhouse_binary_path), - "clickhouse-odbc-bridge", + self.environ["CLICKHOUSE_TESTS_SERVER_BIN_PATH"] = ( + self.clickhouse_binary_path + ) + self.environ["CLICKHOUSE_TESTS_ODBC_BRIDGE_BIN_PATH"] = ( + self.clickhouse_odbc_bridge_binary_path + or os.path.join( + os.path.dirname(self.clickhouse_binary_path), + "clickhouse-odbc-bridge", + ) ) self.environ["CLICKHOUSE_TESTS_DIR"] = self.configs_dir diff --git a/sink-connector-lightweight/tests/integration/helpers/default_config.py b/sink-connector-lightweight/tests/integration/helpers/default_config.py index 552a19fff..af92e9329 100644 --- a/sink-connector-lightweight/tests/integration/helpers/default_config.py +++ b/sink-connector-lightweight/tests/integration/helpers/default_config.py @@ -47,5 +47,5 @@ "database.serverTimezone": "UTC", "clickhouse.datetime.timezone": "UTC", "auto.create.tables": "true", - "ddl.retry": "true" + "ddl.retry": "true", } diff --git a/sink-connector-lightweight/tests/integration/tests/multiple_databases.py b/sink-connector-lightweight/tests/integration/tests/multiple_databases.py index 7197ce7c9..b8f10b42e 100644 --- a/sink-connector-lightweight/tests/integration/tests/multiple_databases.py +++ b/sink-connector-lightweight/tests/integration/tests/multiple_databases.py @@ -14,8 +14,6 @@ change_column, modify_column, drop_column, - add_primary_key, - drop_primary_key, ) @@ -592,26 +590,6 @@ def drop_column_on_a_database(self, database): check_column(table_name=table_name, database=database, column_name="") -@TestScenario -@Requirements( - RQ_SRS_030_ClickHouse_MySQLToClickHouseReplication_PrimaryKey_Simple("1.0") -) -def add_primary_key_on_a_database(self, database): - """Check that the primary key is added to the table when we add a primary key on a database.""" - table_name = f"table_{getuid()}" - column = "col1" - - with Given("I create a table on multiple databases"): - create_table_and_insert_values(table_name=table_name, database_name=database) - - with When("I add a primary key on the table"): - drop_primary_key(table_name=table_name, database=database) - add_primary_key(table_name=table_name, database=database, column_name=column) - - with Then("I check that the primary key was added to the table"): - check_column(table_name=table_name, database=database, column_name=column) - - @TestOutline def check_different_database_names(self, database_map): """Check that the tables are replicated when we have source and destination databases with different names.""" @@ -755,7 +733,6 @@ def check_alters_on_different_databases(self): change_column_on_a_database, modify_column_on_a_database, drop_column_on_a_database, - add_primary_key_on_a_database, ] check_alters( diff --git a/sink-connector-lightweight/tests/integration/tests/steps/clickhouse.py b/sink-connector-lightweight/tests/integration/tests/steps/clickhouse.py index 96558e9d6..0f4555b28 100644 --- a/sink-connector-lightweight/tests/integration/tests/steps/clickhouse.py +++ b/sink-connector-lightweight/tests/integration/tests/steps/clickhouse.py @@ -17,9 +17,15 @@ def drop_database(self, database_name=None, node=None): @TestStep(Then) def check_column( - self, table_name, column_name, node=None, column_type=None, database=None + self, + table_name, + column_name, + node=None, + column_type=None, + database=None, + is_primary_key=False, ): - """Check if column exists in ClickHouse table.""" + """Check if column exists in ClickHouse table and optionally verify if it is the primary key.""" if database is None: database = "test" @@ -51,6 +57,14 @@ def check_column( assert column.output.strip() == expected_output, error() + if is_primary_key: + primary_key = node.query( + f"SELECT is_in_primary_key FROM system.columns WHERE database = '{database}' AND table = '{table_name}' AND name = '{column_name}' LIMIT 1 FORMAT TabSeparated" + ) + assert primary_key.output.strip() == 1, error( + f"Column {column_name} is not a primary key" + ) + @TestStep(Given) def create_clickhouse_database(self, name=None, node=None):