Skip to content

Commit 71aa8de

Browse files
committed
Bigint support
1 parent 7146067 commit 71aa8de

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

mysql_ch_replicator/converter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def convert_type(self, mysql_type, parameters):
7272
return 'UInt32'
7373
return 'Int32'
7474
if mysql_type == 'integer':
75+
if is_unsigned:
76+
return 'UInt32'
7577
return 'Int32'
7678
if mysql_type == 'bigint':
79+
if is_unsigned:
80+
return 'UInt64'
7781
return 'Int64'
7882
if mysql_type == 'double':
7983
return 'Float64'
@@ -123,6 +127,10 @@ def convert_type(self, mysql_type, parameters):
123127
if is_unsigned:
124128
return 'UInt32'
125129
return 'Int32'
130+
if 'bigint' in mysql_type:
131+
if is_unsigned:
132+
return 'UInt64'
133+
return 'Int64'
126134
if 'real' in mysql_type:
127135
return 'Float64'
128136
if mysql_type.startswith('time'):
@@ -182,6 +190,8 @@ def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types
182190
clickhouse_field_value = 16777216 + clickhouse_field_value
183191
if 'UInt32' in clickhouse_field_type and clickhouse_field_value < 0:
184192
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
185195
clickhouse_record.append(clickhouse_field_value)
186196
return tuple(clickhouse_record)
187197

test_mysql_ch_replicator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -611,13 +611,14 @@ def test_numeric_types_and_limits():
611611
test4 TINYINT UNSIGNED,
612612
test5 MEDIUMINT UNSIGNED,
613613
test6 INT UNSIGNED,
614+
test7 BIGINT UNSIGNED,
614615
PRIMARY KEY (id)
615616
);
616617
''')
617618

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

@@ -634,8 +635,8 @@ def test_numeric_types_and_limits():
634635
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 1)
635636

636637
mysql.execute(
637-
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6) VALUES "
638-
f"('Peter', -10000, 60000, -120, 250, 16777200, 4294967280);",
638+
f"INSERT INTO {TEST_TABLE_NAME} (name, test1, test2, test3, test4, test5, test6, test7) VALUES "
639+
f"('Peter', -10000, 60000, -120, 250, 16777200, 4294967280, 18446744073709551586);",
639640
commit=True,
640641
)
641642
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)
@@ -644,3 +645,4 @@ def test_numeric_types_and_limits():
644645
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test5=16777200')) == 2)
645646
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test6=4294967290')) == 1)
646647
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test6=4294967280')) == 1)
648+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test7=18446744073709551586')) == 2)

0 commit comments

Comments
 (0)