Skip to content

Commit f5ffb32

Browse files
committed
Fix tests, handle charset for primary key while erasing entries
1 parent f595623 commit f5ffb32

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

mysql_ch_replicator/converter.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,31 @@ def convert_table_structure(self, mysql_structure: TableStructure) -> TableStruc
222222
clickhouse_structure.preprocess()
223223
return clickhouse_structure
224224

225-
def convert_records(self, mysql_records, mysql_structure: TableStructure, clickhouse_structure: TableStructure):
225+
def convert_records(
226+
self, mysql_records, mysql_structure: TableStructure, clickhouse_structure: TableStructure,
227+
only_primary: bool = False,
228+
):
226229
mysql_field_types = [field.field_type for field in mysql_structure.fields]
227230
clickhouse_filed_types = [field.field_type for field in clickhouse_structure.fields]
228231

229232
clickhouse_records = []
230233
for mysql_record in mysql_records:
231234
clickhouse_record = self.convert_record(
232-
mysql_record, mysql_field_types, clickhouse_filed_types, mysql_structure,
235+
mysql_record, mysql_field_types, clickhouse_filed_types, mysql_structure, only_primary,
233236
)
234237
clickhouse_records.append(clickhouse_record)
235238
return clickhouse_records
236239

237-
def convert_record(self, mysql_record, mysql_field_types, clickhouse_field_types, mysql_structure: TableStructure):
240+
def convert_record(
241+
self, mysql_record, mysql_field_types, clickhouse_field_types, mysql_structure: TableStructure,
242+
only_primary: bool,
243+
):
238244
clickhouse_record = []
239245
for idx, mysql_field_value in enumerate(mysql_record):
246+
if only_primary and idx not in mysql_structure.primary_key_ids:
247+
clickhouse_record.append(mysql_field_value)
248+
continue
249+
240250
clickhouse_field_value = mysql_field_value
241251
mysql_field_type = mysql_field_types[idx]
242252
clickhouse_field_type = clickhouse_field_types[idx]

mysql_ch_replicator/db_replicator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,12 @@ def handle_erase_event(self, event: LogEvent):
459459
self.stats.erase_records_count += len(event.records)
460460

461461
table_structure_ch: TableStructure = self.state.tables_structure[event.table_name][1]
462+
table_structure_mysql: TableStructure = self.state.tables_structure[event.table_name][0]
462463

463-
keys_to_remove = [self._get_record_id(table_structure_ch, record) for record in event.records]
464+
records = self.converter.convert_records(
465+
event.records, table_structure_mysql, table_structure_ch, only_primary=True,
466+
)
467+
keys_to_remove = [self._get_record_id(table_structure_ch, record) for record in records]
464468

465469
current_table_records_to_insert = self.records_to_insert[event.table_name]
466470
current_table_records_to_delete = self.records_to_delete[event.table_name]

0 commit comments

Comments
 (0)