Skip to content

Commit 52786d7

Browse files
authored
Ignore SPATIAL KEY during replication (#52)
1 parent 3eb6d4e commit 52786d7

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

mysql_ch_replicator/converter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ def parse_mysql_table_structure(self, create_statement, required_table_name=None
600600
continue
601601
if line.lower().startswith('fulltext'):
602602
continue
603+
if line.lower().startswith('spatial'):
604+
continue
603605
if line.lower().startswith('primary key'):
604606
# Define identifier to match column names, handling backticks and unquoted names
605607
identifier = (Suppress('`') + Word(alphas + alphanums + '_') + Suppress('`')) | Word(

test_mysql_ch_replicator.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,17 @@ def test_runner():
315315
name varchar(255),
316316
age int,
317317
rate decimal(10,4),
318+
coordinate point NOT NULL,
318319
KEY `IDX_age` (`age`),
319320
FULLTEXT KEY `IDX_name` (`name`),
320-
PRIMARY KEY (id)
321+
PRIMARY KEY (id),
322+
SPATIAL KEY `coordinate` (`coordinate`)
321323
) ENGINE=InnoDB AUTO_INCREMENT=2478808 DEFAULT CHARSET=latin1;
322324
''')
323325

324326

325-
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age) VALUES ('Ivan', 42);", commit=True)
326-
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age) VALUES ('Peter', 33);", commit=True)
327+
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Ivan', 42, POINT(10.0, 20.0));", commit=True)
328+
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Peter', 33, POINT(10.0, 20.0));", commit=True)
327329

328330
run_all_runner = RunAllRunner()
329331
run_all_runner.run()
@@ -335,7 +337,7 @@ def test_runner():
335337
assert_wait(lambda: TEST_TABLE_NAME in ch.get_tables())
336338
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)
337339

338-
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age) VALUES ('Filipp', 50);", commit=True)
340+
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Filipp', 50, POINT(10.0, 20.0));", commit=True)
339341
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 3)
340342
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="name='Filipp'")[0]['age'] == 50)
341343

@@ -346,7 +348,7 @@ def test_runner():
346348
kill_process(binlog_repl_pid)
347349
kill_process(db_repl_pid, force=True)
348350

349-
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, rate) VALUES ('John', 12.5);", commit=True)
351+
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, rate, coordinate) VALUES ('John', 12.5, POINT(10.0, 20.0));", commit=True)
350352
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 4)
351353
assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="name='John'")[0]['rate'] == 12.5)
352354

@@ -362,14 +364,14 @@ def test_runner():
362364
mysql.execute(f"UPDATE {TEST_TABLE_NAME} SET age=88 WHERE name='Ivan'", commit=True)
363365
assert_wait(lambda: ch.select(TEST_TABLE_NAME, "name='Ivan'")[0]['age'] == 88)
364366

365-
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age) VALUES ('Vlad', 99);", commit=True)
367+
mysql.execute(f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES ('Vlad', 99, POINT(10.0, 20.0));", commit=True)
366368

367369
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 4)
368370

369371
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, final=False)) == 4)
370372

371373
mysql.execute(
372-
command=f"INSERT INTO {TEST_TABLE_NAME} (name, age) VALUES (%s, %s);",
374+
command=f"INSERT INTO {TEST_TABLE_NAME} (name, age, coordinate) VALUES (%s, %s, POINT(10.0, 20.0));",
373375
args=(b'H\xe4llo'.decode('latin-1'), 1912),
374376
commit=True,
375377
)

0 commit comments

Comments
 (0)