Skip to content

[BUG] an issue parsing comment COMMENT '事件类型,可选值: ''SYSTEM'', ''BUSINESS''',  #195

@liuhuo23

Description

@liuhuo23

Bug Description

MySQL DDL 解析器在处理包含 ENUM 类型字段的表结构时出现解析错误,导致生成异常的 TableField 对象,其中字段名包含多余的引号,字段类型和参数为空。

Steps to Reproduce

  1. 创建包含 ENUM 类型字段的 MySQL 表(如 audit_logs
  2. 运行 mysql_ch_replicator 进行表结构解析
  3. 观察生成的 TableStructure 对象中的字段信息

Expected Behavior

应该正确解析 ENUM 类型字段,例如:

  • event_type 应解析为 ENUM('SYSTEM', 'BUSINESS') 类型
  • event_result 应解析为 ENUM('SUCCESS', 'FAILURE') 类型
  • 不应产生额外的异常字段

Actual Behavior

解析结果中出现了异常的 TableField 对象:

  • 字段名 ''BUSINESS'''''FAILURE''' 包含多余引号
  • 这些字段的 field_typeparameters 都为空字符串
  • 似乎是将 ENUM 值误解析为独立的字段
# 异常字段示例
TableField(name="''BUSINESS'''", field_type='', parameters='', additional_data=None)
TableField(name="''FAILURE'''", field_type='', parameters='', additional_data=None)

Environment

  • mysql_ch_replicator version: 5.7
  • Operating System: macOS
  • Python version: 3.13.7

MySQL Configuration

# 配置
[mysqld]
server-id = 1
default_authentication_plugin=mysql_native_password
skip-name-resolve
max_allowed_packet=160M
bind-address=0.0.0.0
character-set-server=UTF8
collation-server=utf8_general_ci
slow_query_log=0
long_query_time=10.0
## end of modified
gtid_mode=ON
enforce_gtid_consistency=ON
log_bin=ON
max_connections=3600
[mysql]
default-character-set=utf8

Replicator Configuration

mysql:
  host: 'localhost'
  port: 8306
  user: 'root'
  password: 'root'

clickhouse:
  host: 'localhost'
  port: 8323
  user: 'default'
  password: 'default'

databases: 'your_database_name'

Additional Information

问题分析

这个问题很可能出现在以下模块中:

  • table_structure.py - 表结构解析逻辑
  • mysql_api.py - MySQL DDL 获取和解析

sql

CREATE TABLE `audit_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `event_time` datetime NOT NULL COMMENT '事件时间',
  `event_type` varchar(50) NOT NULL COMMENT '事件类型,可选值: ''SYSTEM'', ''BUSINESS''',
  `event_subtype` varchar(50) NOT NULL COMMENT '事件子类型',
  `event_result` varchar(20) NOT NULL COMMENT '事件结果,可选值: ''SUCCESS'', ''FAILURE''',
  `user_id` int(11) NOT NULL COMMENT '用户ID',
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `ip_address` varchar(50) NOT NULL COMMENT 'IP地址',
  `mac_address` varchar(50) DEFAULT NULL COMMENT 'MAC地址',
  `description` text COMMENT '事件描述',
  `alert_count` int(11) DEFAULT NULL COMMENT '当天相同告警次数',
  `alert_notified` int(11) DEFAULT NULL COMMENT '是否告警通知',
  `alert_message` text COMMENT '告警信息',
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_audit_logs_event_time` (`event_time`),
  KEY `idx_audit_logs_event_type` (`event_type`),
  KEY `idx_audit_logs_ip` (`ip_address`),
  KEY `idx_audit_logs_time_type` (`event_time`,`event_type`),
  KEY `idx_audit_logs_username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=6651 DEFAULT CHARSET=utf8mb4;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions