Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail to parse MySql DDL on "DEFAULT CHARSET = utf8mb4" #153

Closed
runzhi214 opened this issue Jul 26, 2022 · 4 comments
Closed

fail to parse MySql DDL on "DEFAULT CHARSET = utf8mb4" #153

runzhi214 opened this issue Jul 26, 2022 · 4 comments
Assignees

Comments

@runzhi214
Copy link

Describe the bug
DDLParser fail to parse Mysql ddl starting from "DEFAULT CHARSET = utf8mb4", and gives empty result.
However the parser is working when this "DEFAULT CHARSET = utf8mb4" expression is removed

To Reproduce
Steps to reproduce the behavior:
Python sys.version = '3.9.12 (main, Apr 5 2022, 01:53:17) \n[Clang 12.0.0 ]'
`
import simple_ddl_parser as sdp

print("this is not working")
mysql_create_sql0 = """CREATE TABLE t_table_records (
id VARCHAR (255) NOT NULL,
create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
creator VARCHAR (32) DEFAULT 'sys' NOT NULL,
current_rows BIGINT,
edit_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
editor VARCHAR (32) DEFAULT 'sys' NOT NULL,
managed_database_database VARCHAR (255) NOT NULL,
managed_database_schema VARCHAR (255),
managed_database_table VARCHAR (255) NOT NULL,
source_database_database VARCHAR (255) NOT NULL,
source_database_jdbc VARCHAR (255) NOT NULL,
source_database_schema VARCHAR (255),
source_database_table VARCHAR (255) NOT NULL,
source_database_type VARCHAR (255) NOT NULL,
source_rows BIGINT,
PRIMARY KEY (id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COMMENT = '导入元数据管理';
"""

print(sdp.DDLParser(mysql_create_sql0).run(output_mode="mysql"))
print("this is not working")
mysql_create_sql1 = """CREATE TABLE t_table_records (
id VARCHAR (255) NOT NULL,
create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
creator VARCHAR (32) DEFAULT 'sys' NOT NULL,
current_rows BIGINT,
edit_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
editor VARCHAR (32) DEFAULT 'sys' NOT NULL,
managed_database_database VARCHAR (255) NOT NULL,
managed_database_schema VARCHAR (255),
managed_database_table VARCHAR (255) NOT NULL,
source_database_database VARCHAR (255) NOT NULL,
source_database_jdbc VARCHAR (255) NOT NULL,
source_database_schema VARCHAR (255),
source_database_table VARCHAR (255) NOT NULL,
source_database_type VARCHAR (255) NOT NULL,
source_rows BIGINT,
PRIMARY KEY (id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4 COMMENT = '导入元数据管理';
"""

print(sdp.DDLParser(mysql_create_sql1).run())

print("this is not working")
mysql_create_sql2 = """CREATE TABLE t_table_records (
id VARCHAR (255) NOT NULL,
create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
creator VARCHAR (32) DEFAULT 'sys' NOT NULL,
current_rows BIGINT,
edit_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
editor VARCHAR (32) DEFAULT 'sys' NOT NULL,
managed_database_database VARCHAR (255) NOT NULL,
managed_database_schema VARCHAR (255),
managed_database_table VARCHAR (255) NOT NULL,
source_database_database VARCHAR (255) NOT NULL,
source_database_jdbc VARCHAR (255) NOT NULL,
source_database_schema VARCHAR (255),
source_database_table VARCHAR (255) NOT NULL,
source_database_type VARCHAR (255) NOT NULL,
source_rows BIGINT,
PRIMARY KEY (id)
) ENGINE = INNODB DEFAULT CHARSET = utf8mb4;
"""

print(sdp.DDLParser(mysql_create_sql2).run())

print("this is working")
mysql_create_sql3 = """CREATE TABLE t_table_records (
id VARCHAR (255) NOT NULL,
create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
creator VARCHAR (32) DEFAULT 'sys' NOT NULL,
current_rows BIGINT,
edit_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
editor VARCHAR (32) DEFAULT 'sys' NOT NULL,
managed_database_database VARCHAR (255) NOT NULL,
managed_database_schema VARCHAR (255),
managed_database_table VARCHAR (255) NOT NULL,
source_database_database VARCHAR (255) NOT NULL,
source_database_jdbc VARCHAR (255) NOT NULL,
source_database_schema VARCHAR (255),
source_database_table VARCHAR (255) NOT NULL,
source_database_type VARCHAR (255) NOT NULL,
source_rows BIGINT,
PRIMARY KEY (id)
) ENGINE = INNODB COMMENT = '导入元数据管理';
"""

print(sdp.DDLParser(mysql_create_sql3).run())
`

Expected behavior
This Default Expr should be identified or ignored if not recognzied

Screenshots
Uploading 截屏2022-07-26 下午4.52.56.png…

Desktop (please complete the following information):

  • OS: iOS - moneterey 12.1
  • Browser chrome
  • IDE: jupyter lab environment with kernel Python sys.version = '3.9.12 (main, Apr 5 2022, 01:53:17) \n[Clang 12.0.0 ]'

Additional context
There are some yacc logs generating at the first time, however it leads to a crash.
After restarting the kernel , the parser returns empty list immediately

@runzhi214
Copy link
Author

version : Simple-ddl-parser version 0.26.5 installed today.
截屏2022-07-26 下午4 54 19

@xnuinside
Copy link
Owner

@runzhi214 Hi! thanks for reporting this issue, I will work on fix

@xnuinside xnuinside self-assigned this Aug 6, 2022
@xnuinside
Copy link
Owner

done in #152

@xnuinside
Copy link
Owner

@runzhi214 fix released in version 0.27.0 (https://pypi.org/project/simple-ddl-parser/), if will be anything else - feel free to open new issue, and thanks for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants