Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7d3c0f

Browse files
committedNov 5, 2024·
Fix for UNSIGNED NULL
1 parent 908d53f commit e7d3c0f

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
 

‎mysql_ch_replicator/converter.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,19 @@ def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types
182182
if mysql_field_type == 'json' and 'String' in clickhouse_field_type:
183183
if not isinstance(clickhouse_field_value, str):
184184
clickhouse_field_value = json.dumps(convert_bytes(clickhouse_field_value))
185-
if 'UInt16' in clickhouse_field_type and clickhouse_field_value < 0:
186-
clickhouse_field_value = 65536 + clickhouse_field_value
187-
if 'UInt8' in clickhouse_field_type and clickhouse_field_value < 0:
188-
clickhouse_field_value = 256 + clickhouse_field_value
189-
if 'mediumint' in mysql_field_type.lower() and clickhouse_field_value < 0:
190-
clickhouse_field_value = 16777216 + clickhouse_field_value
191-
if 'UInt32' in clickhouse_field_type and clickhouse_field_value < 0:
192-
clickhouse_field_value = 4294967296 + clickhouse_field_value
193-
if 'UInt64' in clickhouse_field_type and clickhouse_field_value < 0:
194-
clickhouse_field_value = 18446744073709551616 + clickhouse_field_value
185+
186+
if clickhouse_field_value is not None:
187+
if 'UInt16' in clickhouse_field_type and clickhouse_field_value < 0:
188+
clickhouse_field_value = 65536 + clickhouse_field_value
189+
if 'UInt8' in clickhouse_field_type and clickhouse_field_value < 0:
190+
clickhouse_field_value = 256 + clickhouse_field_value
191+
if 'mediumint' in mysql_field_type.lower() and clickhouse_field_value < 0:
192+
clickhouse_field_value = 16777216 + clickhouse_field_value
193+
if 'UInt32' in clickhouse_field_type and clickhouse_field_value < 0:
194+
clickhouse_field_value = 4294967296 + clickhouse_field_value
195+
if 'UInt64' in clickhouse_field_type and clickhouse_field_value < 0:
196+
clickhouse_field_value = 18446744073709551616 + clickhouse_field_value
197+
195198
clickhouse_record.append(clickhouse_field_value)
196199
return tuple(clickhouse_record)
197200

‎test_mysql_ch_replicator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,14 @@ def test_numeric_types_and_limits():
613613
test5 MEDIUMINT UNSIGNED,
614614
test6 INT UNSIGNED,
615615
test7 BIGINT UNSIGNED,
616+
test8 MEDIUMINT UNSIGNED NULL,
616617
PRIMARY KEY (id)
617618
);
618619
''')
619620

620621
mysql.execute(
621-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6, test7) VALUES "
622-
f"('Ivan', -20000, 50000, -30, 100, 16777200, 4294967290, 18446744073709551586);",
622+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6, test7, test8) VALUES "
623+
f"('Ivan', -20000, 50000, -30, 100, 16777200, 4294967290, 18446744073709551586, NULL);",
623624
commit=True,
624625
)
625626

@@ -636,8 +637,8 @@ def test_numeric_types_and_limits():
636637
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 1)
637638

638639
mysql.execute(
639-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6, test7) VALUES "
640-
f"('Peter', -10000, 60000, -120, 250, 16777200, 4294967280, 18446744073709551586);",
640+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6, test7, test8) VALUES "
641+
f"('Peter', -10000, 60000, -120, 250, 16777200, 4294967280, 18446744073709551586, NULL);",
641642
commit=True,
642643
)
643644
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)

0 commit comments

Comments
 (0)
Please sign in to comment.