diff --git a/README.md b/README.md index 1f62cea..ffe8dfb 100644 --- a/README.md +++ b/README.md @@ -11,21 +11,21 @@ pip install sqlgpt-parser ### Parser SQL ```python ->>> from sql_parser.mysql_parser import parser as mysql_parser +>>> from sqlgpt_parser.sql_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 sql_parser.oceanbase_parser import parser as oceanbase_parser +>>> from sqlgpt_parser.sql_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 sql_parser.odps_parser import parser as odps_parser +>>> from sqlgpt_parser.sql_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 sql_parser.format.formatter import format_sql ->>> from sql_parser.mysql_parser import parser +>>> from sqlgpt_parser.format.formatter import format_sql +>>> from sqlgpt_parser.mysql_parser import parser >>> result=parser.parse("select * from t") >>> format_sql(result) 'SELECT\n *\nFROM\n t' diff --git a/docs/docs-ch/Parser Module Development Guide.md b/docs/docs-ch/Parser Module Development Guide.md index 07c74bc..6b3d052 100644 --- a/docs/docs-ch/Parser Module Development Guide.md +++ b/docs/docs-ch/Parser Module Development Guide.md @@ -245,8 +245,9 @@ The comment in `p_delete` corresponds to the syntax rule for the `DELETE` statem Once the grammar rules are written, they can be used to parse SQL statements. Taking `mysql_parser` as an example, you can use this grammar rule for parsing SQL statements. ```python -from src.parser.mysql_parser.parser import parser as mysql_parser -from src.parser.mysql_parser.lexer import lexer as mysql_lexer +from sqlgpt_parser.parser.mysql_parser.parser import parser as mysql_parser +from sqlgpt_parser.parser.mysql_parser.lexer import lexer as mysql_lexer + sql = "DELETE FROM t WHERE a=1" result = mysql_parser.parse(sql, lexer=mysql_lexer) ``` diff --git "a/docs/docs-ch/SQL Parser \345\274\200\345\217\221\346\214\207\345\215\227.md" "b/docs/docs-ch/SQL Parser \345\274\200\345\217\221\346\214\207\345\215\227.md" index d12f589..e506895 100644 --- "a/docs/docs-ch/SQL Parser \345\274\200\345\217\221\346\214\207\345\215\227.md" +++ "b/docs/docs-ch/SQL Parser \345\274\200\345\217\221\346\214\207\345\215\227.md" @@ -2,7 +2,7 @@ `parser` 是 `sqlgpt-parser` 的基础模块,它将 SQL 语句按照预定义 SQL 语法规则解析,从文本转换成抽象语法树(`AST`)。 - `sqlgpt-parser` 的 `parser` 基于 [PLY](https://github.com/dabeaz/ply) 编写。PLY 是一个用于构建词法和语法分析器的 Python 工具。它能够根据指定的模式对输入的文本进行分析,它会在程序运行之前,自动编译项目 [sql-parser](../../src/sql_parser/) 文件夹下的词法规则和语法规则文件,生成可执行代码。 + `sqlgpt-parser` 的 `parser` 基于 [PLY](https://github.com/dabeaz/ply) 编写。PLY 是一个用于构建词法和语法分析器的 Python 工具。它能够根据指定的模式对输入的文本进行分析,它会在程序运行之前,自动编译项目 [sql-parser](../../sqlgpt_parser/sql_parser/) 文件夹下的词法规则和语法规则文件,生成可执行代码。 ## 词法解析与语法解析 @@ -161,7 +161,7 @@ def p_expr_paren(p): ## `sqlgpt-parser`的 `parser` 实现 -`sqlgpt-parser` 中共有三个 SQL 语法解析器 ,分别在 [mysql_parser](../../src/sql_parser/mysql_parser)、 [oceanbase_parser](../../src/sql_parser/oceanbase_parser) 和 [odps_parser](../../src/sql_parser/odps_parser) 文件夹下,三个文件夹都包含`lexer.py`,`reserved.py`,`parser.py` 三个文件。 +`sqlgpt-parser` 中共有三个 SQL 语法解析器 ,分别在 [mysql_parser](../../sqlgpt_parser/sql_parser/mysql_parser)、 [oceanbase_parser](../../sqlgpt_parser/sql_parser/oceanbase_parser) 和 [odps_parser](../../sqlgpt_parser/sql_parser/odps_parser) 文件夹下,三个文件夹都包含`lexer.py`,`reserved.py`,`parser.py` 三个文件。 `lexer.py` 和`reserved.py` 文件都用于词法解析。`reserved.py` 中定义了 SQL 的关键字,关键字定义在`reserved` 和 `nonreserved` 两个变量中 ,`reserved` 里面包含了所有 `sql` 中不可用作列名、表名或者别名的关键字,`nonreserved` 则是可以用作列名、表名或者别名的关键字。 @@ -260,7 +260,8 @@ def p_delete(p): 完成语法规则的编写后就可以使用,该语法规则解析 `SQL` 语句,以 `mysql_parser` 为例。 ```python -from src.sql_parser.mysql_parser import parser as mysql_parser +from sqlgpt_parser.sql_parser.mysql_parser import parser as mysql_parser + sql = "DELETE FROM t WHERE a=1" result = mysql_parser.parse(sql) ``` diff --git a/docs/docs-en/SQL Parser Development Guide.md b/docs/docs-en/SQL Parser Development Guide.md index d038fef..8881684 100644 --- a/docs/docs-en/SQL Parser Development Guide.md +++ b/docs/docs-en/SQL Parser Development Guide.md @@ -2,7 +2,7 @@ The `parser` module is the foundational module of `sqlgpt-parser`. It parses SQL statements according to predefined SQL grammar rules, converting them from text into an abstract syntax tree (`AST`). -The `parser` module in `sqlgpt-parser` is written using [PLY](https://github.com/dabeaz/ply). PLY is a Python tool for building lexical and parsing analyzers. It can analyze input text based on specified patterns and automatically compile the lexical and grammar rule files in the [sql-parser](../../src/sql_parser/) folder of the project before the program runs, generating executable code. +The `parser` module in `sqlgpt-parser` is written using [PLY](https://github.com/dabeaz/ply). PLY is a Python tool for building lexical and parsing analyzers. It can analyze input text based on specified patterns and automatically compile the lexical and grammar rule files in the [sql-parser](../../sqlgpt_parser/sql_parser/) folder of the project before the program runs, generating executable code. ## Lexical Analysis and Syntax Analysis @@ -158,7 +158,7 @@ PLY uses the notation `p[position]` to access the stack, where `p[0]` correspond ## Implementation of the `parser` for `sqlgpt-parser` -There are a total of three SQL parsers in `sqlgpt-parser`, located in the [mysql_parser](../../src/sql_parser/mysql_parser), [oceanbase_parser](../../src/sql_parser/oceanbase_parser), and [odps_parser](../../src/sql_parser/odps_parser) folders. Each of these folders contains three files: `lexer.py`, `reserved.py`, and `parser.py`. +There are a total of three SQL parsers in `sqlgpt-parser`, located in the [mysql_parser](../../sqlgpt_parser/sql_parser/mysql_parser), [oceanbase_parser](../../sqlgpt_parser/sql_parser/oceanbase_parser), and [odps_parser](../../sqlgpt_parser/sql_parser/odps_parser) folders. Each of these folders contains three files: `lexer.py`, `reserved.py`, and `parser.py`. The `lexer.py` and `reserved.py` files are both used for lexical analysis. In `reserved.py`, SQL keywords are defined and stored in two variables: `reserved` and `nonreserved`. The `reserved` variable contains all the keywords that cannot be used as column names, table names, or aliases in SQL. On the other hand, `nonreserved` contains keywords that can be used as column names, table names, or aliases. @@ -245,7 +245,8 @@ The comment in `p_delete` corresponds to the syntax rule for the `DELETE` statem Once the grammar rules are written, they can be used to parse SQL statements. Taking `mysql_parser` as an example, you can use this grammar rule for parsing SQL statements. ```python -from src.sql_parser.mysql_parser import parser as mysql_parser +from sqlgpt_parser.sql_parser.mysql_parser import parser as mysql_parser + sql = "DELETE FROM t WHERE a=1" result = mysql_parser.parse(sql) ``` diff --git a/pyproject.toml b/pyproject.toml index a5f8577..47d33d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi" [project] name = "sqlgpt-parser" -version = "0.0.1a1" +version = "0.0.1a2" authors = [ { name="luliwjc", email="chenxiaoxi_wjc@163.com" }, { name="Ifffff", email="tingkai.ztk@antgroup.com" }, @@ -24,8 +24,6 @@ dependencies = [ "ply == 3.11", ] -[tool.flit.module] -name = "sql_parser" [project.urls] "Homepage" = "https://github.com/eosphoros-ai/sqlgpt-parser" "Bug Tracker" = "https://github.com/eosphoros-ai/sqlgpt-parser/issues" diff --git a/sqlgpt_parser/__init__.py b/sqlgpt_parser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/sqlgpt_parser/format/__init__.py b/sqlgpt_parser/format/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/sql_parser/format/formatter.py b/sqlgpt_parser/format/formatter.py similarity index 98% rename from src/sql_parser/format/formatter.py rename to sqlgpt_parser/format/formatter.py index 6c419df..5bb16f1 100644 --- a/src/sql_parser/format/formatter.py +++ b/sqlgpt_parser/format/formatter.py @@ -9,13 +9,13 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ -from src.sql_parser.tree import JsonTableColumn -from src.sql_parser.tree.explain import ExplainFormat, ExplainType -from src.sql_parser.tree.grouping import SimpleGroupBy -from src.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin -from src.sql_parser.tree.table import Table, TableSubquery -from src.sql_parser.tree.visitor import AstVisitor -from src.sql_parser.parser_utils import FIELD_REFERENCE_PREFIX +from sqlgpt_parser.sql_parser.tree import JsonTableColumn +from sqlgpt_parser.sql_parser.tree.explain import ExplainFormat, ExplainType +from sqlgpt_parser.sql_parser.tree.grouping import SimpleGroupBy +from sqlgpt_parser.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin +from sqlgpt_parser.sql_parser.tree.table import Table, TableSubquery +from sqlgpt_parser.sql_parser.tree.visitor import AstVisitor +from sqlgpt_parser.sql_parser.parser_utils import FIELD_REFERENCE_PREFIX class Formatter(AstVisitor): diff --git a/src/__init__.py b/sqlgpt_parser/sql_parser/__init__.py similarity index 87% rename from src/__init__.py rename to sqlgpt_parser/sql_parser/__init__.py index 987c325..d6f93af 100644 --- a/src/__init__.py +++ b/sqlgpt_parser/sql_parser/__init__.py @@ -9,7 +9,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ - -import sys - -sys.path.insert(0, '..') +__path__ = __import__("pkgutil").extend_path(__path__, __name__) \ No newline at end of file diff --git a/src/sql_parser/exceptions.py b/sqlgpt_parser/sql_parser/exceptions.py similarity index 100% rename from src/sql_parser/exceptions.py rename to sqlgpt_parser/sql_parser/exceptions.py diff --git a/__init__.py b/sqlgpt_parser/sql_parser/mysql_parser/__init__.py similarity index 100% rename from __init__.py rename to sqlgpt_parser/sql_parser/mysql_parser/__init__.py diff --git a/src/sql_parser/mysql_parser/lexer.py b/sqlgpt_parser/sql_parser/mysql_parser/lexer.py similarity index 98% rename from src/sql_parser/mysql_parser/lexer.py rename to sqlgpt_parser/sql_parser/mysql_parser/lexer.py index 7e17849..1d3f149 100644 --- a/src/sql_parser/mysql_parser/lexer.py +++ b/sqlgpt_parser/sql_parser/mysql_parser/lexer.py @@ -13,7 +13,7 @@ import re from ply import lex -from src.sql_parser.mysql_parser.reserved import ( +from sqlgpt_parser.sql_parser.mysql_parser.reserved import ( reversed, nonreserved, not_keyword_token, diff --git a/src/sql_parser/mysql_parser/parser.py b/sqlgpt_parser/sql_parser/mysql_parser/parser.py similarity index 98% rename from src/sql_parser/mysql_parser/parser.py rename to sqlgpt_parser/sql_parser/mysql_parser/parser.py index 8dcd9ff..8a6851e 100644 --- a/src/sql_parser/mysql_parser/parser.py +++ b/sqlgpt_parser/sql_parser/mysql_parser/parser.py @@ -14,7 +14,7 @@ import types, threading -from src.sql_parser.tree.window import ( +from sqlgpt_parser.sql_parser.tree.window import ( FrameBound, FrameClause, FrameExpr, @@ -23,9 +23,9 @@ WindowSpec, ) -from src.sql_parser.tree.with_stmt import CommonTableExpr, With, WithHasQuery -from src.sql_parser.tree.index_type import IndexType -from src.sql_parser.tree.expression import ( +from sqlgpt_parser.sql_parser.tree.with_stmt import CommonTableExpr, With, WithHasQuery +from sqlgpt_parser.sql_parser.tree.index_type import IndexType +from sqlgpt_parser.sql_parser.tree.expression import ( AggregateFunc, ArithmeticBinaryExpression, ArithmeticUnaryExpression, @@ -60,9 +60,9 @@ WhenClause, JsonTableColumn, ) -from src.sql_parser.tree.grouping import SimpleGroupBy -from src.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin -from src.sql_parser.tree.literal import ( +from sqlgpt_parser.sql_parser.tree.grouping import SimpleGroupBy +from sqlgpt_parser.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin +from sqlgpt_parser.sql_parser.tree.literal import ( BooleanLiteral, DateLiteral, DoubleLiteral, @@ -73,21 +73,21 @@ DefaultLiteral, ErrorLiteral, ) -from src.sql_parser.tree.node import Node -from src.sql_parser.tree.qualified_name import QualifiedName -from src.sql_parser.tree.query_specification import QuerySpecification -from src.sql_parser.tree.relation import AliasedRelation, Join -from src.sql_parser.tree.select import Select -from src.sql_parser.tree.select_item import Partition, SingleColumn -from src.sql_parser.tree.set_operation import Except, Intersect, Union -from src.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem -from src.sql_parser.tree.statement import Delete, Insert, Query, Update -from src.sql_parser.tree.table import Table -from src.sql_parser.tree.values import Values -from src.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType +from sqlgpt_parser.sql_parser.tree.node import Node +from sqlgpt_parser.sql_parser.tree.qualified_name import QualifiedName +from sqlgpt_parser.sql_parser.tree.query_specification import QuerySpecification +from sqlgpt_parser.sql_parser.tree.relation import AliasedRelation, Join +from sqlgpt_parser.sql_parser.tree.select import Select +from sqlgpt_parser.sql_parser.tree.select_item import Partition, SingleColumn +from sqlgpt_parser.sql_parser.tree.set_operation import Except, Intersect, Union +from sqlgpt_parser.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem +from sqlgpt_parser.sql_parser.tree.statement import Delete, Insert, Query, Update +from sqlgpt_parser.sql_parser.tree.table import Table +from sqlgpt_parser.sql_parser.tree.values import Values +from sqlgpt_parser.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType from ply import yacc -from src.sql_parser.mysql_parser.lexer import tokens, lexer +from sqlgpt_parser.sql_parser.mysql_parser.lexer import tokens, lexer tokens = tokens diff --git a/src/sql_parser/mysql_parser/parser_table.py b/sqlgpt_parser/sql_parser/mysql_parser/parser_table.py similarity index 100% rename from src/sql_parser/mysql_parser/parser_table.py rename to sqlgpt_parser/sql_parser/mysql_parser/parser_table.py diff --git a/src/sql_parser/mysql_parser/reserved.py b/sqlgpt_parser/sql_parser/mysql_parser/reserved.py similarity index 100% rename from src/sql_parser/mysql_parser/reserved.py rename to sqlgpt_parser/sql_parser/mysql_parser/reserved.py diff --git a/src/sql_parser/mysql_parser/__init__.py b/sqlgpt_parser/sql_parser/oceanbase_parser/__init__.py similarity index 100% rename from src/sql_parser/mysql_parser/__init__.py rename to sqlgpt_parser/sql_parser/oceanbase_parser/__init__.py diff --git a/src/sql_parser/odps_parser/lexer.py b/sqlgpt_parser/sql_parser/oceanbase_parser/lexer.py similarity index 97% rename from src/sql_parser/odps_parser/lexer.py rename to sqlgpt_parser/sql_parser/oceanbase_parser/lexer.py index 876e741..0b9a6d1 100644 --- a/src/sql_parser/odps_parser/lexer.py +++ b/sqlgpt_parser/sql_parser/oceanbase_parser/lexer.py @@ -13,7 +13,7 @@ import re from ply import lex -from src.sql_parser.odps_parser.reserved import reserved, nonreserved +from sqlgpt_parser.sql_parser.oceanbase_parser.reserved import reserved, nonreserved tokens = ( [ diff --git a/src/sql_parser/oceanbase_parser/parser.py b/sqlgpt_parser/sql_parser/oceanbase_parser/parser.py similarity index 98% rename from src/sql_parser/oceanbase_parser/parser.py rename to sqlgpt_parser/sql_parser/oceanbase_parser/parser.py index f4a9810..852d0dc 100644 --- a/src/sql_parser/oceanbase_parser/parser.py +++ b/sqlgpt_parser/sql_parser/oceanbase_parser/parser.py @@ -13,7 +13,7 @@ from __future__ import print_function import types, threading -from src.sql_parser.tree.window import ( +from sqlgpt_parser.sql_parser.tree.window import ( FrameBound, FrameClause, FrameExpr, @@ -23,9 +23,9 @@ ) from ply import yacc -from src.sql_parser.tree.index_type import IndexType -from src.sql_parser.oceanbase_parser.lexer import tokens, lexer -from src.sql_parser.tree.expression import ( +from sqlgpt_parser.sql_parser.tree.index_type import IndexType +from sqlgpt_parser.sql_parser.oceanbase_parser.lexer import tokens, lexer +from sqlgpt_parser.sql_parser.tree.expression import ( AggregateFunc, ArithmeticBinaryExpression, ArithmeticUnaryExpression, @@ -60,9 +60,9 @@ WhenClause, JsonTableColumn, ) -from src.sql_parser.tree.grouping import SimpleGroupBy -from src.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin -from src.sql_parser.tree.literal import ( +from sqlgpt_parser.sql_parser.tree.grouping import SimpleGroupBy +from sqlgpt_parser.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin +from sqlgpt_parser.sql_parser.tree.literal import ( BooleanLiteral, DateLiteral, DoubleLiteral, @@ -73,19 +73,19 @@ DefaultLiteral, ErrorLiteral, ) -from src.sql_parser.tree.node import Node -from src.sql_parser.tree.qualified_name import QualifiedName -from src.sql_parser.tree.query_specification import QuerySpecification -from src.sql_parser.tree.relation import AliasedRelation, Join -from src.sql_parser.tree.select import Select -from src.sql_parser.tree.select_item import Partition, SingleColumn -from src.sql_parser.tree.set_operation import Except, Intersect, Union -from src.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem -from src.sql_parser.tree.statement import Delete, Insert, Query, Update -from src.sql_parser.tree.table import Table -from src.sql_parser.tree.values import Values -from src.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType -from src.sql_parser.tree.with_stmt import With, CommonTableExpr, WithHasQuery +from sqlgpt_parser.sql_parser.tree.node import Node +from sqlgpt_parser.sql_parser.tree.qualified_name import QualifiedName +from sqlgpt_parser.sql_parser.tree.query_specification import QuerySpecification +from sqlgpt_parser.sql_parser.tree.relation import AliasedRelation, Join +from sqlgpt_parser.sql_parser.tree.select import Select +from sqlgpt_parser.sql_parser.tree.select_item import Partition, SingleColumn +from sqlgpt_parser.sql_parser.tree.set_operation import Except, Intersect, Union +from sqlgpt_parser.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem +from sqlgpt_parser.sql_parser.tree.statement import Delete, Insert, Query, Update +from sqlgpt_parser.sql_parser.tree.table import Table +from sqlgpt_parser.sql_parser.tree.values import Values +from sqlgpt_parser.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType +from sqlgpt_parser.sql_parser.tree.with_stmt import With, CommonTableExpr, WithHasQuery tokens = tokens diff --git a/src/sql_parser/oceanbase_parser/parser_table.py b/sqlgpt_parser/sql_parser/oceanbase_parser/parser_table.py similarity index 100% rename from src/sql_parser/oceanbase_parser/parser_table.py rename to sqlgpt_parser/sql_parser/oceanbase_parser/parser_table.py diff --git a/src/sql_parser/oceanbase_parser/reserved.py b/sqlgpt_parser/sql_parser/oceanbase_parser/reserved.py similarity index 100% rename from src/sql_parser/oceanbase_parser/reserved.py rename to sqlgpt_parser/sql_parser/oceanbase_parser/reserved.py diff --git a/src/sql_parser/oceanbase_parser/__init__.py b/sqlgpt_parser/sql_parser/odps_parser/__init__.py similarity index 100% rename from src/sql_parser/oceanbase_parser/__init__.py rename to sqlgpt_parser/sql_parser/odps_parser/__init__.py diff --git a/src/sql_parser/oceanbase_parser/lexer.py b/sqlgpt_parser/sql_parser/odps_parser/lexer.py similarity index 97% rename from src/sql_parser/oceanbase_parser/lexer.py rename to sqlgpt_parser/sql_parser/odps_parser/lexer.py index 9be43c9..61c25c3 100644 --- a/src/sql_parser/oceanbase_parser/lexer.py +++ b/sqlgpt_parser/sql_parser/odps_parser/lexer.py @@ -13,7 +13,7 @@ import re from ply import lex -from src.sql_parser.oceanbase_parser.reserved import reserved, nonreserved +from sqlgpt_parser.sql_parser.odps_parser.reserved import reserved, nonreserved tokens = ( [ diff --git a/src/sql_parser/odps_parser/parser.py b/sqlgpt_parser/sql_parser/odps_parser/parser.py similarity index 98% rename from src/sql_parser/odps_parser/parser.py rename to sqlgpt_parser/sql_parser/odps_parser/parser.py index b89c391..6c96e9e 100644 --- a/src/sql_parser/odps_parser/parser.py +++ b/sqlgpt_parser/sql_parser/odps_parser/parser.py @@ -13,7 +13,7 @@ from __future__ import print_function import types, threading -from src.sql_parser.tree.window import ( +from sqlgpt_parser.sql_parser.tree.window import ( FrameBound, FrameClause, FrameExpr, @@ -24,9 +24,9 @@ from ply import yacc -from src.sql_parser.tree.index_type import IndexType -from src.sql_parser.odps_parser.lexer import tokens, lexer -from src.sql_parser.tree.expression import ( +from sqlgpt_parser.sql_parser.tree.index_type import IndexType +from sqlgpt_parser.sql_parser.odps_parser.lexer import tokens, lexer +from sqlgpt_parser.sql_parser.tree.expression import ( AggregateFunc, ArithmeticBinaryExpression, ArithmeticUnaryExpression, @@ -61,9 +61,9 @@ WhenClause, JsonTableColumn, ) -from src.sql_parser.tree.grouping import SimpleGroupBy -from src.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin -from src.sql_parser.tree.literal import ( +from sqlgpt_parser.sql_parser.tree.grouping import SimpleGroupBy +from sqlgpt_parser.sql_parser.tree.join_criteria import JoinOn, JoinUsing, NaturalJoin +from sqlgpt_parser.sql_parser.tree.literal import ( BooleanLiteral, DateLiteral, DoubleLiteral, @@ -74,19 +74,19 @@ DefaultLiteral, ErrorLiteral, ) -from src.sql_parser.tree.node import Node -from src.sql_parser.tree.qualified_name import QualifiedName -from src.sql_parser.tree.query_specification import QuerySpecification -from src.sql_parser.tree.relation import AliasedRelation, Join -from src.sql_parser.tree.select import Select -from src.sql_parser.tree.select_item import Partition, SingleColumn -from src.sql_parser.tree.set_operation import Except, Intersect, Union -from src.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem -from src.sql_parser.tree.statement import Delete, Insert, Query, Update -from src.sql_parser.tree.table import Table -from src.sql_parser.tree.values import Values -from src.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType -from src.sql_parser.tree.with_stmt import With, CommonTableExpr, WithHasQuery +from sqlgpt_parser.sql_parser.tree.node import Node +from sqlgpt_parser.sql_parser.tree.qualified_name import QualifiedName +from sqlgpt_parser.sql_parser.tree.query_specification import QuerySpecification +from sqlgpt_parser.sql_parser.tree.relation import AliasedRelation, Join +from sqlgpt_parser.sql_parser.tree.select import Select +from sqlgpt_parser.sql_parser.tree.select_item import Partition, SingleColumn +from sqlgpt_parser.sql_parser.tree.set_operation import Except, Intersect, Union +from sqlgpt_parser.sql_parser.tree.sort_item import ByItem, PartitionByClause, SortItem +from sqlgpt_parser.sql_parser.tree.statement import Delete, Insert, Query, Update +from sqlgpt_parser.sql_parser.tree.table import Table +from sqlgpt_parser.sql_parser.tree.values import Values +from sqlgpt_parser.sql_parser.tree.field_type import UNSPECIFIEDLENGTH, FieldType, SQLType +from sqlgpt_parser.sql_parser.tree.with_stmt import With, CommonTableExpr, WithHasQuery tokens = tokens diff --git a/src/sql_parser/odps_parser/parser_table.py b/sqlgpt_parser/sql_parser/odps_parser/parser_table.py similarity index 100% rename from src/sql_parser/odps_parser/parser_table.py rename to sqlgpt_parser/sql_parser/odps_parser/parser_table.py diff --git a/src/sql_parser/odps_parser/reserved.py b/sqlgpt_parser/sql_parser/odps_parser/reserved.py similarity index 100% rename from src/sql_parser/odps_parser/reserved.py rename to sqlgpt_parser/sql_parser/odps_parser/reserved.py diff --git a/src/sql_parser/parser_utils.py b/sqlgpt_parser/sql_parser/parser_utils.py similarity index 97% rename from src/sql_parser/parser_utils.py rename to sqlgpt_parser/sql_parser/parser_utils.py index 1b619ac..d17c2aa 100644 --- a/src/sql_parser/parser_utils.py +++ b/sqlgpt_parser/sql_parser/parser_utils.py @@ -10,11 +10,11 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. """ -from src.sql_parser.tree.grouping import GroupingSets, SimpleGroupBy -from src.sql_parser.tree.literal import StringLiteral -from src.sql_parser.tree.select_item import SingleColumn -from src.sql_parser.tree.visitor import DefaultTraversalVisitor -from src.sql_parser.tree.expression import ( +from sqlgpt_parser.sql_parser.tree.grouping import GroupingSets, SimpleGroupBy +from sqlgpt_parser.sql_parser.tree.literal import StringLiteral +from sqlgpt_parser.sql_parser.tree.select_item import SingleColumn +from sqlgpt_parser.sql_parser.tree.visitor import DefaultTraversalVisitor +from sqlgpt_parser.sql_parser.tree.expression import ( FunctionCall, InListExpression, QualifiedNameReference, diff --git a/src/sql_parser/tree/__init__.py b/sqlgpt_parser/sql_parser/tree/__init__.py similarity index 100% rename from src/sql_parser/tree/__init__.py rename to sqlgpt_parser/sql_parser/tree/__init__.py diff --git a/src/sql_parser/tree/approximate.py b/sqlgpt_parser/sql_parser/tree/approximate.py similarity index 100% rename from src/sql_parser/tree/approximate.py rename to sqlgpt_parser/sql_parser/tree/approximate.py diff --git a/src/sql_parser/tree/call_argument.py b/sqlgpt_parser/sql_parser/tree/call_argument.py similarity index 100% rename from src/sql_parser/tree/call_argument.py rename to sqlgpt_parser/sql_parser/tree/call_argument.py diff --git a/src/sql_parser/tree/explain.py b/sqlgpt_parser/sql_parser/tree/explain.py similarity index 100% rename from src/sql_parser/tree/explain.py rename to sqlgpt_parser/sql_parser/tree/explain.py diff --git a/src/sql_parser/tree/expression.py b/sqlgpt_parser/sql_parser/tree/expression.py similarity index 100% rename from src/sql_parser/tree/expression.py rename to sqlgpt_parser/sql_parser/tree/expression.py diff --git a/src/sql_parser/tree/field_type.py b/sqlgpt_parser/sql_parser/tree/field_type.py similarity index 100% rename from src/sql_parser/tree/field_type.py rename to sqlgpt_parser/sql_parser/tree/field_type.py diff --git a/src/sql_parser/tree/grouping.py b/sqlgpt_parser/sql_parser/tree/grouping.py similarity index 100% rename from src/sql_parser/tree/grouping.py rename to sqlgpt_parser/sql_parser/tree/grouping.py diff --git a/src/sql_parser/tree/index_type.py b/sqlgpt_parser/sql_parser/tree/index_type.py similarity index 100% rename from src/sql_parser/tree/index_type.py rename to sqlgpt_parser/sql_parser/tree/index_type.py diff --git a/src/sql_parser/tree/join_criteria.py b/sqlgpt_parser/sql_parser/tree/join_criteria.py similarity index 100% rename from src/sql_parser/tree/join_criteria.py rename to sqlgpt_parser/sql_parser/tree/join_criteria.py diff --git a/src/sql_parser/tree/literal.py b/sqlgpt_parser/sql_parser/tree/literal.py similarity index 100% rename from src/sql_parser/tree/literal.py rename to sqlgpt_parser/sql_parser/tree/literal.py diff --git a/src/sql_parser/tree/node.py b/sqlgpt_parser/sql_parser/tree/node.py similarity index 100% rename from src/sql_parser/tree/node.py rename to sqlgpt_parser/sql_parser/tree/node.py diff --git a/src/sql_parser/tree/qualified_name.py b/sqlgpt_parser/sql_parser/tree/qualified_name.py similarity index 100% rename from src/sql_parser/tree/qualified_name.py rename to sqlgpt_parser/sql_parser/tree/qualified_name.py diff --git a/src/sql_parser/tree/query_specification.py b/sqlgpt_parser/sql_parser/tree/query_specification.py similarity index 100% rename from src/sql_parser/tree/query_specification.py rename to sqlgpt_parser/sql_parser/tree/query_specification.py diff --git a/src/sql_parser/tree/relation.py b/sqlgpt_parser/sql_parser/tree/relation.py similarity index 100% rename from src/sql_parser/tree/relation.py rename to sqlgpt_parser/sql_parser/tree/relation.py diff --git a/src/sql_parser/tree/rewrite.py b/sqlgpt_parser/sql_parser/tree/rewrite.py similarity index 100% rename from src/sql_parser/tree/rewrite.py rename to sqlgpt_parser/sql_parser/tree/rewrite.py diff --git a/src/sql_parser/tree/select.py b/sqlgpt_parser/sql_parser/tree/select.py similarity index 100% rename from src/sql_parser/tree/select.py rename to sqlgpt_parser/sql_parser/tree/select.py diff --git a/src/sql_parser/tree/select_item.py b/sqlgpt_parser/sql_parser/tree/select_item.py similarity index 100% rename from src/sql_parser/tree/select_item.py rename to sqlgpt_parser/sql_parser/tree/select_item.py diff --git a/src/sql_parser/tree/set_operation.py b/sqlgpt_parser/sql_parser/tree/set_operation.py similarity index 100% rename from src/sql_parser/tree/set_operation.py rename to sqlgpt_parser/sql_parser/tree/set_operation.py diff --git a/src/sql_parser/tree/sort_item.py b/sqlgpt_parser/sql_parser/tree/sort_item.py similarity index 100% rename from src/sql_parser/tree/sort_item.py rename to sqlgpt_parser/sql_parser/tree/sort_item.py diff --git a/src/sql_parser/tree/statement.py b/sqlgpt_parser/sql_parser/tree/statement.py similarity index 100% rename from src/sql_parser/tree/statement.py rename to sqlgpt_parser/sql_parser/tree/statement.py diff --git a/src/sql_parser/tree/table.py b/sqlgpt_parser/sql_parser/tree/table.py similarity index 100% rename from src/sql_parser/tree/table.py rename to sqlgpt_parser/sql_parser/tree/table.py diff --git a/src/sql_parser/tree/table_element.py b/sqlgpt_parser/sql_parser/tree/table_element.py similarity index 100% rename from src/sql_parser/tree/table_element.py rename to sqlgpt_parser/sql_parser/tree/table_element.py diff --git a/src/sql_parser/tree/transaction.py b/sqlgpt_parser/sql_parser/tree/transaction.py similarity index 100% rename from src/sql_parser/tree/transaction.py rename to sqlgpt_parser/sql_parser/tree/transaction.py diff --git a/src/sql_parser/tree/values.py b/sqlgpt_parser/sql_parser/tree/values.py similarity index 100% rename from src/sql_parser/tree/values.py rename to sqlgpt_parser/sql_parser/tree/values.py diff --git a/src/sql_parser/tree/visitor.py b/sqlgpt_parser/sql_parser/tree/visitor.py similarity index 100% rename from src/sql_parser/tree/visitor.py rename to sqlgpt_parser/sql_parser/tree/visitor.py diff --git a/src/sql_parser/tree/window.py b/sqlgpt_parser/sql_parser/tree/window.py similarity index 100% rename from src/sql_parser/tree/window.py rename to sqlgpt_parser/sql_parser/tree/window.py diff --git a/src/sql_parser/tree/with_stmt.py b/sqlgpt_parser/sql_parser/tree/with_stmt.py similarity index 100% rename from src/sql_parser/tree/with_stmt.py rename to sqlgpt_parser/sql_parser/tree/with_stmt.py diff --git a/src/sql_parser/__init__.py b/src/sql_parser/__init__.py deleted file mode 100644 index e0b2f2a..0000000 --- a/src/sql_parser/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -# coding=utf-8 -""" - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -""" - - -def parser(sql, engine, tracking=False): - try: - return engine.parse(sql, tracking) - except Exception: - raise diff --git a/src/sql_parser/odps_parser/__init__.py b/src/sql_parser/odps_parser/__init__.py deleted file mode 100644 index a6dd6d3..0000000 --- a/src/sql_parser/odps_parser/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -# coding=utf-8 -""" - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -""" diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/format/test_sql_formatter.py b/test/format/test_sql_formatter.py index 84b73fe..3a9a0b3 100644 --- a/test/format/test_sql_formatter.py +++ b/test/format/test_sql_formatter.py @@ -1,7 +1,7 @@ import unittest -from src.sql_parser.format.formatter import format_sql -from src.sql_parser.mysql_parser import parser +from sqlgpt_parser.format.formatter import format_sql +from sqlgpt_parser.sql_parser.mysql_parser import parser class MyTestCase(unittest.TestCase): diff --git a/test/parser/test_parser_ddl.py b/test/parser/test_parser_ddl.py index 71f439c..9f3cb3f 100644 --- a/test/parser/test_parser_ddl.py +++ b/test/parser/test_parser_ddl.py @@ -14,7 +14,8 @@ import unittest -from src.sql_parser.mysql_parser import parser + +from sqlgpt_parser.sql_parser.mysql_parser import parser class MyTestCase(unittest.TestCase): diff --git a/test/parser/test_parser_dml.py b/test/parser/test_parser_dml.py index 566d86f..fa23c93 100644 --- a/test/parser/test_parser_dml.py +++ b/test/parser/test_parser_dml.py @@ -14,12 +14,12 @@ import unittest -from src.sql_parser.tree.with_stmt import WithHasQuery +from sqlgpt_parser.sql_parser.tree.with_stmt import WithHasQuery -from src.sql_parser.mysql_parser import parser as mysql_parser -from src.sql_parser.oceanbase_parser import parser as oceanbase_parser -from src.sql_parser.tree.expression import ComparisonExpression -from src.sql_parser.tree.statement import Statement +from sqlgpt_parser.sql_parser.mysql_parser import parser as mysql_parser +from sqlgpt_parser.sql_parser.oceanbase_parser import parser as oceanbase_parser +from sqlgpt_parser.sql_parser.tree.expression import ComparisonExpression +from sqlgpt_parser.sql_parser.tree.statement import Statement import warnings diff --git a/test/parser/test_parser_dql.py b/test/parser/test_parser_dql.py index 460f13e..4305433 100644 --- a/test/parser/test_parser_dql.py +++ b/test/parser/test_parser_dql.py @@ -14,13 +14,13 @@ import unittest -from src.sql_parser.mysql_parser import parser as mysql_parser -from src.sql_parser.oceanbase_parser import parser as oceanbase_parser -from src.sql_parser.odps_parser import parser as odps_parser -from src.sql_parser.tree.expression import LikePredicate, ExistsPredicate -from src.sql_parser.tree.relation import Join -from src.sql_parser.tree.set_operation import Union -from src.sql_parser.tree.statement import Statement +from sqlgpt_parser.sql_parser.mysql_parser import parser as mysql_parser +from sqlgpt_parser.sql_parser.oceanbase_parser import parser as oceanbase_parser +from sqlgpt_parser.sql_parser.odps_parser import parser as odps_parser +from sqlgpt_parser.sql_parser.tree.expression import LikePredicate, ExistsPredicate +from sqlgpt_parser.sql_parser.tree.relation import Join +from sqlgpt_parser.sql_parser.tree.set_operation import Union +from sqlgpt_parser.sql_parser.tree.statement import Statement class MyTestCase(unittest.TestCase):