Skip to content

Commit 529f5d6

Browse files
committed
UInt32 handling
1 parent 766306b commit 529f5d6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

mysql_ch_replicator/converter.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def convert_type(self, mysql_type, parameters):
6767

6868
is_unsigned = 'unsigned' in parameters.lower()
6969

70-
print(" === check mysql_type", mysql_type, parameters)
71-
7270
if mysql_type == 'int':
71+
if is_unsigned:
72+
return 'UInt32'
7373
return 'Int32'
7474
if mysql_type == 'integer':
7575
return 'Int32'
@@ -119,7 +119,9 @@ def convert_type(self, mysql_type, parameters):
119119
return 'Float32'
120120
if 'double' in mysql_type:
121121
return 'Float64'
122-
if 'integer' in mysql_type:
122+
if 'integer' in mysql_type or 'int(' in mysql_type:
123+
if is_unsigned:
124+
return 'UInt32'
123125
return 'Int32'
124126
if 'real' in mysql_type:
125127
return 'Float64'
@@ -134,7 +136,6 @@ def convert_field_type(self, mysql_type, mysql_parameters):
134136
mysql_parameters = mysql_parameters.lower()
135137
not_null = 'not null' in mysql_parameters
136138
clickhouse_type = self.convert_type(mysql_type, mysql_parameters)
137-
print(" === result type:", clickhouse_type)
138139
if not not_null:
139140
clickhouse_type = f'Nullable({clickhouse_type})'
140141
return clickhouse_type
@@ -179,6 +180,8 @@ def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types
179180
clickhouse_field_value = 256 + clickhouse_field_value
180181
if 'mediumint' in mysql_field_type.lower() and clickhouse_field_value < 0:
181182
clickhouse_field_value = 16777216 + clickhouse_field_value
183+
if 'UInt32' in clickhouse_field_type and clickhouse_field_value < 0:
184+
clickhouse_field_value = 4294967296 + clickhouse_field_value
182185
clickhouse_record.append(clickhouse_field_value)
183186
return tuple(clickhouse_record)
184187

test_mysql_ch_replicator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,13 +610,14 @@ def test_numeric_types_and_limits():
610610
test3 TINYINT,
611611
test4 TINYINT UNSIGNED,
612612
test5 MEDIUMINT UNSIGNED,
613+
test6 INT UNSIGNED,
613614
PRIMARY KEY (id)
614615
);
615616
''')
616617

617618
mysql.execute(
618-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5) VALUES "
619-
f"('Ivan', -20000, 50000, -30, 100, 16777200);",
619+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6) VALUES "
620+
f"('Ivan', -20000, 50000, -30, 100, 16777200, 4294967290);",
620621
commit=True,
621622
)
622623

@@ -633,11 +634,13 @@ def test_numeric_types_and_limits():
633634
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 1)
634635

635636
mysql.execute(
636-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5) VALUES "
637-
f"('Peter', -10000, 60000, -120, 250, 16777200);",
637+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6) VALUES "
638+
f"('Peter', -10000, 60000, -120, 250, 16777200, 4294967280);",
638639
commit=True,
639640
)
640641
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)
641642
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test2=60000')) == 1)
642643
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test4=250')) == 1)
643644
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test5=16777200')) == 2)
645+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test6=4294967290')) == 1)
646+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test6=4294967280')) == 1)

0 commit comments

Comments
 (0)