diff --git a/sink-connector-lightweight/tests/integration/regression_auto.py b/sink-connector-lightweight/tests/integration/regression_auto.py index 917b20b8e..622ed1202 100755 --- a/sink-connector-lightweight/tests/integration/regression_auto.py +++ b/sink-connector-lightweight/tests/integration/regression_auto.py @@ -168,12 +168,6 @@ "https://github.com/Altinity/clickhouse-sink-connector/issues/461", ) ], - "/mysql to clickhouse replication/mysql to clickhouse replication auto/datatypes/datetime/*": [ - ( - Fail, - "https://github.com/Altinity/clickhouse-sink-connector/issues/462", - ) - ], "types/enum": [(Fail, "doesn't create table")], } xflags = {} diff --git a/sink-connector-lightweight/tests/integration/tests/datatypes.py b/sink-connector-lightweight/tests/integration/tests/datatypes.py index f85856216..40dbd5922 100644 --- a/sink-connector-lightweight/tests/integration/tests/datatypes.py +++ b/sink-connector-lightweight/tests/integration/tests/datatypes.py @@ -6,6 +6,28 @@ from integration.tests.steps.sql import * +def adjust_precision(datetime_str, precision): + """A function to transform given DATETIME values from MySQL to ClickHouse with given precision.""" + if datetime_str == "NOW()": + return datetime_str + + parts = datetime_str.split(".") + main_part = parts[0] + + if precision == "0": + return main_part + + if len(parts) == 1: + return f"{main_part}.{'0' * int(precision)}" + + microseconds_part = parts[1] + adjusted_microseconds = microseconds_part[: int(precision)].ljust( + int(precision), "0" + ) + + return f"{main_part}.{adjusted_microseconds}" + + @TestStep(Given) def create_table_with_datetime_column(self, table_name, data, precision): """Create MySQL table that contains the datetime column.""" @@ -20,7 +42,10 @@ def create_table_with_datetime_column(self, table_name, data, precision): ) with And(f"inserting data to MySQL {table_name} table"): - mysql_node.query(f"INSERT INTO {table_name} VALUES (1, '{data}');") + if data != "NOW()": + mysql_node.query(f"INSERT INTO {table_name} VALUES (1, '{data}');") + else: + mysql_node.query(f"INSERT INTO {table_name} VALUES (1, {data});") @TestCheck @@ -28,6 +53,8 @@ def check_datetime_column(self, precision, data): table_name = "table_" + getuid() clickhouse_node = self.context.clickhouse_node + data = adjust_precision(datetime_str=data, precision=precision) + with Given( "I create a table with datetime column", description=f""" @@ -42,29 +69,42 @@ def check_datetime_column(self, precision, data): with Then(f"I check that the data is replicated to ClickHouse and is not lost"): for retry in retries(timeout=30): with retry: - if data == "1000-01-01 00:00:00" or data == "1900-01-01 00:00:00": - clickhouse_values = clickhouse_node.query( - f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" - ) - assert ( - clickhouse_values.output.strip().replace('"', "") - == "1900-01-01 00:00:00" - ), error() - elif data == "9999-12-31 23:59:59" or data == "2299-12-31 23:59:59": - clickhouse_values = clickhouse_node.query( - f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" - ) - assert ( - clickhouse_values.output.strip().replace('"', "") - == "2299-12-31 23:59:59" - ), error() - else: - clickhouse_values = clickhouse_node.query( - f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" - ) - assert ( - clickhouse_values.output.strip().replace('"', "") == data - ), error() + clickhouse_values = clickhouse_node.query( + f"SELECT count(date) FROM {self.context.database}.{table_name} FORMAT CSV" + ) + + assert clickhouse_values.output.strip() != "0", error() + + if data == "NOW()": + clickhouse_values = clickhouse_node.query( + f"SELECT count(date) FROM {self.context.database}.{table_name} FORMAT CSV" + ) + assert clickhouse_values.output.strip() != "0", error() + + elif data == "1000-01-01 00:00:00" or data == "1900-01-01 00:00:00": + clickhouse_values = clickhouse_node.query( + f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" + ) + assert clickhouse_values.output.strip().replace( + '"', "" + ) == adjust_precision( + datetime_str="1900-01-01 00:00:00", precision=precision + ), error() + + elif data == "9999-12-31 23:59:59" or data == "2299-12-31 23:59:59": + clickhouse_values = clickhouse_node.query( + f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" + ) + assert clickhouse_values.output.strip().replace( + '"', "" + ) == adjust_precision( + datetime_str="2299-12-31 23:59:59", precision=precision + ), error() + else: + clickhouse_values = clickhouse_node.query( + f"SELECT date FROM {self.context.database}.{table_name} FORMAT CSV" + ) + assert clickhouse_values.output.strip().replace('"', "") == data, error() @TestSketch(Scenario)