@@ -63,7 +63,12 @@ class MysqlToClickhouseConverter:
6363 def __init__ (self , db_replicator : 'DbReplicator' = None ):
6464 self .db_replicator = db_replicator
6565
66- def convert_type (self , mysql_type ):
66+ def convert_type (self , mysql_type , parameters ):
67+
68+ is_unsigned = 'unsigned' in parameters .lower ()
69+
70+ print (" === check mysql_type" , mysql_type , parameters )
71+
6772 if mysql_type == 'int' :
6873 return 'Int32'
6974 if mysql_type == 'integer' :
@@ -82,10 +87,14 @@ def convert_type(self, mysql_type):
8287 return 'Bool'
8388 if mysql_type == 'bool' :
8489 return 'Bool'
85- if mysql_type == 'smallint' :
90+ if 'smallint' in mysql_type :
91+ if is_unsigned :
92+ return 'UInt16'
8693 return 'Int16'
8794 if 'tinyint' in mysql_type :
88- return 'Int16'
95+ if is_unsigned :
96+ return 'UInt8'
97+ return 'Int8'
8998 if 'datetime' in mysql_type :
9099 return mysql_type .replace ('datetime' , 'DateTime64' )
91100 if 'longtext' in mysql_type :
@@ -120,7 +129,8 @@ def convert_field_type(self, mysql_type, mysql_parameters):
120129 mysql_type = mysql_type .lower ()
121130 mysql_parameters = mysql_parameters .lower ()
122131 not_null = 'not null' in mysql_parameters
123- clickhouse_type = self .convert_type (mysql_type )
132+ clickhouse_type = self .convert_type (mysql_type , mysql_parameters )
133+ print (" === result type:" , clickhouse_type )
124134 if not not_null :
125135 clickhouse_type = f'Nullable({ clickhouse_type } )'
126136 return clickhouse_type
@@ -159,6 +169,10 @@ def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types
159169 if mysql_field_type == 'json' and 'String' in clickhouse_field_type :
160170 if not isinstance (clickhouse_field_value , str ):
161171 clickhouse_field_value = json .dumps (convert_bytes (clickhouse_field_value ))
172+ if 'UInt16' in clickhouse_field_type and clickhouse_field_value < 0 :
173+ clickhouse_field_value = 65536 + clickhouse_field_value
174+ if 'UInt8' in clickhouse_field_type and clickhouse_field_value < 0 :
175+ clickhouse_field_value = 256 + clickhouse_field_value
162176 clickhouse_record .append (clickhouse_field_value )
163177 return tuple (clickhouse_record )
164178
0 commit comments