Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eosphoros-ai/sqlgpt-parser
sqlgpt-parser is a Python implementation of an SQL parser that effectively converts SQL statements into Abstract Syntax Trees (AST). By leveraging AST tree comparisons between two SQL queries, it becomes possible to achieve robust evaluation of text-to-SQL models.
https://github.com/eosphoros-ai/sqlgpt-parser
ast nl-to-sql parser python sql text-to-sql
Last synced: 9 days ago
JSON representation
sqlgpt-parser is a Python implementation of an SQL parser that effectively converts SQL statements into Abstract Syntax Trees (AST). By leveraging AST tree comparisons between two SQL queries, it becomes possible to achieve robust evaluation of text-to-SQL models.
- Host: GitHub
- URL: https://github.com/eosphoros-ai/sqlgpt-parser
- Owner: eosphoros-ai
- License: apache-2.0
- Created: 2023-08-31T03:30:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-08T07:06:05.000Z (about 1 year ago)
- Last Synced: 2024-10-13T15:45:29.568Z (about 1 month ago)
- Topics: ast, nl-to-sql, parser, python, sql, text-to-sql
- Language: Python
- Homepage:
- Size: 10.9 MB
- Stars: 26
- Watchers: 2
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlgpt-parser
sqlgpt-parser is a Python implementation of an SQL parser that effectively converts SQL statements into Abstract Syntax Trees (AST). By leveraging AST tree comparisons between two SQL queries, it becomes possible to achieve robust evaluation of text-to-SQL models.
## Quick Start
### Install
```sh
pip install sqlgpt-parser
```
### Parser SQL```python
>> > from sqlgpt_parser.parser.mysql_parser import parser as mysql_parser
>> > mysql_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)
>> > from sqlgpt_parser.parser.oceanbase_parser import parser as oceanbase_parser
>> > oceanbase_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)
>> > from sqlgpt_parser.parser.odps_parser import parser as odps_parser
>> > odps_parser.parse("select * from t")
Query(query_body=QuerySpecification(select=Select(distinct=False, select_items=[
SingleColumn(expression=QualifiedNameReference(name=QualifiedName.of("*")))]),
from_=Table(name=QualifiedName.of("t"), for_update=False), order_by=[], limit=0,
offset=0, for_update=False, nowait_or_wait=False), order_by=[], limit=0, offset=0)
```### Format SQL
```python
>>> from sqlgpt_parser.format.formatter import format_sql
>>> from sqlgpt_parser.parser.mysql_parser import parser
>>> result=parser.parse("select * from t")
>>> format_sql(result)
'SELECT\n *\nFROM\n t'```
## Getting Started with SQL Parser DevelopmentEnglish Document: [SQL Parser Development Guide](https://github.com/eosphoros-ai/sqlgpt-parser/blob/main/docs/docs-en/SQL%20Parser%20Development%20Guide.md)
中文文档:[SQL Parser 开发指南](https://github.com/eosphoros-ai/sqlgpt-parser/blob/main/docs/docs-ch/SQL%20Parser%20%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97.md)