Skip to content

Commit a7a70bf

Browse files
committed
Support for bit(1) type, #31
1 parent 5525162 commit a7a70bf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

mysql_ch_replicator/converter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def convert_type(self, mysql_type, parameters):
8989
return 'Date32'
9090
if mysql_type == 'tinyint(1)':
9191
return 'Bool'
92+
if mysql_type == 'bit(1)':
93+
return 'Bool'
9294
if mysql_type == 'bool':
9395
return 'Bool'
9496
if 'smallint' in mysql_type:

test_mysql_ch_replicator.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,59 @@ def test_numeric_types_and_limits():
694694
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test7=18446744073709551586')) == 2)
695695

696696

697+
def test_different_types_2():
698+
cfg = config.Settings()
699+
cfg.load(CONFIG_FILE)
700+
701+
mysql = mysql_api.MySQLApi(
702+
database=None,
703+
mysql_settings=cfg.mysql,
704+
)
705+
706+
ch = clickhouse_api.ClickhouseApi(
707+
database=TEST_DB_NAME,
708+
clickhouse_settings=cfg.clickhouse,
709+
)
710+
711+
prepare_env(cfg, mysql, ch)
712+
713+
mysql.execute("SET sql_mode = 'ALLOW_INVALID_DATES';")
714+
715+
mysql.execute(f'''
716+
CREATE TABLE {TEST_TABLE_NAME} (
717+
`id` int unsigned NOT NULL AUTO_INCREMENT,
718+
test1 bit(1),
719+
PRIMARY KEY (id)
720+
);
721+
''')
722+
723+
mysql.execute(
724+
f"INSERT INTO {TEST_TABLE_NAME} (test1) VALUES "
725+
f"(0);",
726+
commit=True,
727+
)
728+
729+
binlog_replicator_runner = BinlogReplicatorRunner()
730+
binlog_replicator_runner.run()
731+
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME)
732+
db_replicator_runner.run()
733+
734+
assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
735+
736+
ch.execute_command(f'USE {TEST_DB_NAME}')
737+
738+
assert_wait(lambda: TEST_TABLE_NAME in ch.get_tables())
739+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 1)
740+
741+
mysql.execute(
742+
f"INSERT INTO {TEST_TABLE_NAME} (test1) VALUES "
743+
f"(1);",
744+
commit=True,
745+
)
746+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2)
747+
assert_wait(lambda: len(ch.select(TEST_TABLE_NAME, 'test1=True')) == 1)
748+
749+
697750
def test_json():
698751
cfg = config.Settings()
699752
cfg.load(CONFIG_FILE)

0 commit comments

Comments
 (0)