Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testflows test updates #467

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
88 changes: 64 additions & 24 deletions sink-connector-lightweight/tests/integration/tests/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -20,14 +42,19 @@ 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
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"""
Expand All @@ -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)
Expand Down
Loading