Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions mysql_ch_replicator/enum/ddl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def find_enum_or_set_definition_end(line: str) -> Tuple[int, str, str]:
return end_pos, field_type, field_parameters

# Fallback to splitting by space if we can't find the end
definition = line.split(' ')
field_type = definition[0]
# Use split() instead of split(' ') to handle multiple consecutive spaces
definition = line.split()
field_type = definition[0] if definition else ""
field_parameters = ' '.join(definition[1:]) if len(definition) > 1 else ''

return -1, field_type, field_parameters
Expand All @@ -62,12 +63,14 @@ def parse_enum_or_set_field(line: str, field_name: str, is_backtick_quoted: bool
if line.lower().startswith('enum(') or line.lower().startswith('set('):
end_pos, field_type, field_parameters = find_enum_or_set_definition_end(line)
else:
definition = line.split(' ')
field_type = definition[0]
# Use split() instead of split(' ') to handle multiple consecutive spaces
definition = line.split()
field_type = definition[0] if definition else ""
field_parameters = ' '.join(definition[1:]) if len(definition) > 1 else ''
else:
# For non-backtick quoted fields
definition = line.split(' ')
# Use split() instead of split(' ') to handle multiple consecutive spaces
definition = line.split()
definition = definition[1:] # Skip the field name which was already extracted

if definition and (
Expand Down
46 changes: 46 additions & 0 deletions test_mysql_ch_replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,3 +2607,49 @@ def test_ignore_deletes():
finally:
# Clean up the temporary config file
os.unlink(config_file)

def test_issue_160_unknown_mysql_type_bug():
"""
Test to reproduce the bug from issue #160.

Bug Description: Replication fails when adding a new table during realtime replication
with Exception: unknown mysql type ""

This test should FAIL until the bug is fixed.
When the bug is present: parsing will fail with unknown mysql type and the test will FAIL
When the bug is fixed: parsing will succeed and the test will PASS
"""
# The exact CREATE TABLE statement from the bug report
create_table_query = """create table test_table
(
id bigint not null,
col_a datetime(6) not null,
col_b datetime(6) null,
col_c varchar(255) not null,
col_d varchar(255) not null,
col_e int not null,
col_f decimal(20, 10) not null,
col_g decimal(20, 10) not null,
col_h datetime(6) not null,
col_i date not null,
col_j varchar(255) not null,
col_k varchar(255) not null,
col_l bigint not null,
col_m varchar(50) not null,
col_n bigint null,
col_o decimal(20, 1) null,
col_p date null,
primary key (id, col_e)
);"""

# Create a converter instance
converter = MysqlToClickhouseConverter()

# This should succeed when the bug is fixed
# When the bug is present, this will raise "unknown mysql type """ and the test will FAIL
mysql_structure, ch_structure = converter.parse_create_table_query(create_table_query)

# Verify the parsing worked correctly
assert mysql_structure.table_name == 'test_table'
assert len(mysql_structure.fields) == 17 # All columns should be parsed
assert mysql_structure.primary_keys == ['id', 'col_e']