-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ChangxingJiang/28-feature
更新仓库 README 文档 + 调整 demo 位置
- Loading branch information
Showing
15 changed files
with
205 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
词法解析 Demo | ||
<AMTSingle source="SELECT" marks=> | ||
<AMTSingle source="column1" marks=NAME> | ||
<AMTSingle source="," marks=> | ||
<AMTSingle source="'2'" marks=NAME|LITERAL> | ||
<AMTSingle source="FROM" marks=> | ||
<AMTSingle source="table_1" marks=NAME> | ||
""" | ||
|
||
from metasequoia_sql import FSMMachine | ||
|
||
amt_tree = FSMMachine.parse("SELECT column1, '2' FROM table_1") | ||
for node in amt_tree: | ||
print(node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
词法解析 Demo | ||
<AMTSingle source="SELECT" marks=> | ||
<AMTSingle source="column1" marks=NAME> | ||
<AMTSingle source="," marks=> | ||
<AMTParenthesis children=[<AMTSingle source="column2" marks=NAME>, <AMTSingle source="+" marks=>, <AMTSingle source="1" marks=LITERAL|LITERAL_INT>] marks=PARENTHESIS> | ||
<AMTSingle source="*" marks=> | ||
<AMTSingle source="2" marks=LITERAL|LITERAL_INT> | ||
<AMTSingle source="FROM" marks=> | ||
<AMTSingle source="table_1" marks=NAME> | ||
""" | ||
|
||
from metasequoia_sql import FSMMachine | ||
|
||
amt_tree = FSMMachine.parse("SELECT column1, (column2 + 1) * 2 FROM table_1") | ||
for node in amt_tree: | ||
print(node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
语法解析 Demo | ||
""" | ||
|
||
from metasequoia_sql import SQLParser | ||
|
||
statement = SQLParser.parse_select_statement("SELECT column1, '2' FROM table_1") | ||
print(statement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
语法解析 Demo | ||
""" | ||
|
||
from metasequoia_sql import SQLParser | ||
|
||
statements = SQLParser.parse_statements("SELECT column1 FROM table_1; SELECT column2 FROM table_2") | ||
for statement in statements: | ||
print(statement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
语法解析 Demo | ||
""" | ||
|
||
from metasequoia_sql import SQLParser | ||
|
||
expression = SQLParser.parse_logical_and_level_expression("(`column1` > 2) AND (`column2` > 1)") | ||
print(expression) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
应用样例:数据血缘分析 | ||
""" | ||
|
||
from metasequoia_sql import * | ||
from metasequoia_sql.analyzer import CreateTableStatementGetter | ||
from metasequoia_sql.analyzer.data_linage.table_lineage_analyzer import TableLineageAnalyzer | ||
|
||
table_lineage_analyzer = TableLineageAnalyzer(CreateTableStatementGetter(...)) | ||
for statement in SQLParser.parse_statements("your sql"): | ||
if isinstance(statement, ASTInsertSelectStatement): | ||
result = table_lineage_analyzer.get_insert_table_lineage(statement) | ||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
MyBatis 插件 Demo | ||
""" | ||
|
||
from metasequoia_sql.plugins.mybaitis import SQLParserMyBatis | ||
|
||
statements = SQLParserMyBatis.parse_statements("SELECT column_1 FROM Shohin " | ||
"WHERE #{column_2} > 500 " | ||
"GROUP BY #{column_3}") | ||
for statement in statements: | ||
print(statement) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters