Skip to content

Commit 34b5997

Browse files
committed
Fixed table named group
1 parent 50ba885 commit 34b5997

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

mysql_ch_replicator/mysql_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def reconnect_if_required(self, force=False):
4343
self.last_connect_time = curr_time
4444

4545
def drop_database(self, db_name):
46-
self.cursor.execute(f'DROP DATABASE IF EXISTS {db_name}')
46+
self.cursor.execute(f'DROP DATABASE IF EXISTS `{db_name}`')
47+
48+
def drop_table(self, table_name):
49+
self.cursor.execute(f'DROP TABLE IF EXISTS `{table_name}`')
4750

4851
def create_database(self, db_name):
4952
self.cursor.execute(f'CREATE DATABASE {db_name}')
@@ -85,7 +88,7 @@ def get_binlog_files(self):
8588

8689
def get_table_create_statement(self, table_name) -> str:
8790
self.reconnect_if_required()
88-
self.cursor.execute(f'SHOW CREATE TABLE {table_name}')
91+
self.cursor.execute(f'SHOW CREATE TABLE `{table_name}`')
8992
res = self.cursor.fetchall()
9093
create_statement = res[0][1].strip()
9194
return create_statement
@@ -97,7 +100,7 @@ def get_records(self, table_name, order_by, limit, start_value=None):
97100
if start_value is not None:
98101
start_value = ','.join(map(str, start_value))
99102
where = f'WHERE ({order_by}) > ({start_value}) '
100-
query = f'SELECT * FROM {table_name} {where}ORDER BY {order_by} LIMIT {limit}'
103+
query = f'SELECT * FROM `{table_name}` {where}ORDER BY {order_by} LIMIT {limit}'
101104
self.cursor.execute(query)
102105
res = self.cursor.fetchall()
103106
records = [x for x in res]

test_mysql_ch_replicator.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,29 @@ def test_runner():
331331
''')
332332

333333

334+
mysql.execute(f'''
335+
CREATE TABLE `group` (
336+
id int NOT NULL AUTO_INCREMENT,
337+
name varchar(255) NOT NULL,
338+
age int,
339+
rate decimal(10,4),
340+
PRIMARY KEY (id)
341+
);
342+
''')
343+
344+
334345
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Ivan', 42, POINT(10.0, 20.0));", commit=True)
335346
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Peter', 33, POINT(10.0, 20.0));", commit=True)
336347

337348
run_all_runner = RunAllRunner()
338349
run_all_runner.run()
339350

340351
assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
352+
assert_wait(lambda: 'group' in ch.get_databases())
353+
354+
mysql.drop_table('group')
355+
356+
assert_wait(lambda: 'group' not in ch.get_databases())
341357

342358
ch.execute_command(f'USE {TEST_DB_NAME}')
343359

@@ -395,12 +411,11 @@ def test_runner():
395411
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 5)
396412
assert_wait(lambda: ch.select(TEST_TABLE_NAME, "age=1912")[0]['name'] == 'Hällo')
397413

398-
399414
mysql.create_database(TEST_DB_NAME_2)
400415
assert_wait(lambda: TEST_DB_NAME_2 in ch.get_databases())
401416

402417
mysql.execute(f'''
403-
CREATE TABLE test_table_with_index (
418+
CREATE TABLE `group` (
404419
id int NOT NULL AUTO_INCREMENT,
405420
name varchar(255) NOT NULL,
406421
age int,
@@ -409,9 +424,9 @@ def test_runner():
409424
);
410425
''')
411426

412-
assert_wait(lambda: 'test_table_with_index' in ch.get_tables())
427+
assert_wait(lambda: 'group' in ch.get_tables())
413428

414-
create_query = ch.show_create_table('test_table_with_index')
429+
create_query = ch.show_create_table('group')
415430
assert 'INDEX name_idx name TYPE ngrambf_v1' in create_query
416431

417432
run_all_runner.stop()

tests_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ check_db_updated_interval: 3
2222

2323
indexes:
2424
- databases: '*'
25-
tables: ['test_table_with_index']
25+
tables: ['group']
2626
index: 'INDEX name_idx name TYPE ngrambf_v1(5, 65536, 4, 0) GRANULARITY 1'
2727

2828
http_host: 'localhost'

0 commit comments

Comments
 (0)