Skip to content

Commit 2954e00

Browse files
committed
Medium int handling
1 parent b7e7a6c commit 2954e00

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

mysql_ch_replicator/converter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def convert_type(self, mysql_type, parameters):
9595
if is_unsigned:
9696
return 'UInt8'
9797
return 'Int8'
98+
if 'mediumint' in mysql_type:
99+
if is_unsigned:
100+
return 'UInt32'
101+
return 'Int32'
98102
if 'datetime' in mysql_type:
99103
return mysql_type.replace('datetime', 'DateTime64')
100104
if 'longtext' in mysql_type:
@@ -173,6 +177,8 @@ def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types
173177
clickhouse_field_value = 65536 + clickhouse_field_value
174178
if 'UInt8' in clickhouse_field_type and clickhouse_field_value < 0:
175179
clickhouse_field_value = 256 + clickhouse_field_value
180+
if 'mediumint' in mysql_field_type.lower() and clickhouse_field_value < 0:
181+
clickhouse_field_value = 16777216 + clickhouse_field_value
176182
clickhouse_record.append(clickhouse_field_value)
177183
return tuple(clickhouse_record)
178184

test_mysql_ch_replicator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,14 @@ def test_numeric_types_and_limits():
609609
test2 smallint unsigned,
610610
test3 TINYINT,
611611
test4 TINYINT UNSIGNED,
612+
test5 MEDIUMINT UNSIGNED,
612613
PRIMARY KEY (id)
613614
);
614615
''')
615616

616617
mysql.execute(
617-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4) VALUES ('Ivan', -20000, 50000, -30, 100);",
618+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5) VALUES "
619+
f"('Ivan', -20000, 50000, -30, 100, 16777200);",
618620
commit=True,
619621
)
620622

@@ -631,10 +633,11 @@ def test_numeric_types_and_limits():
631633
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 1)
632634

633635
mysql.execute(
634-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4) VALUES ('Peter', -10000, 60000, -120, 250);",
636+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5) VALUES "
637+
f"('Peter', -10000, 60000, -120, 250, 16777200);",
635638
commit=True,
636639
)
637640
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)
638641
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test2=60000')) == 1)
639-
640642
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test4=250')) == 1)
643+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test5=16777200')) == 2)

0 commit comments

Comments
 (0)