wu-sheng commented on a change in pull request #8138:
URL: https://github.com/apache/shardingsphere/pull/8138#discussion_r522977479
##########
File path: docs/document/content/features/sharding/principle/parse.en.md
##########
@@ -25,10 +25,56 @@ At last, through traversing the abstract syntax tree, the
context needed by shar
## SQL Parser
+### History
+
As the core of database sharding and table sharding, SQL parser takes the
performance and compatibility as its most important index. ShardingSphere SQL
parser has undergone the upgrade and iteration of 3 generations of products.
To pursue good performance and quick achievement, the first generation of SQL
parser uses `Druid` before 1.4.x version. As tested in practice, its
performance exceeds other parsers a lot.
The second generation of SQL parsing engine begins from 1.5.x version,
ShardingSphere has adopted fully self-developed parsing engine ever since. Due
to different purposes, ShardingSphere does not need to transform SQL into a
totally abstract syntax tree or traverse twice through visitor. Using `half
parsing` method, it only extracts the context required by data sharding, so the
performance and compatibility of SQL parsing is further improved.
-The third generation of SQL parsing engine begins from 3.0.x version.
ShardingSphere tries to adopts ANTLR as the SQL parsing engine, and uses Visit
to obtain SQL Statement from AST. Starting from version 5.0.x, the architecture
of the parsing engine has been refactored. At the same time, it is convenient
to directly obtain the parsing results of the same SQL to improve parsing
efficiency by putting the AST obtained from the first parsing into the cache.
Therefore, we recommend that users adopt `PreparedStatement` this SQL
pre-compilation method to improve performance. Currently, users can also use
ShardingSphere's SQL parsing engine independently to obtain AST and SQL
Statements for a variety of mainstream relational databases. In the future, the
SQL parsing engine will continue to provide powerful functions such as SQL
formatting and SQL templating.
+The third generation of SQL parsing engine begins from 3.0.x version.
ShardingSphere tries to adopts ANTLR as a generator for the SQL parsing engine,
and uses Visit to obtain SQL Statement from AST. Starting from version 5.0.x,
the architecture of the parsing engine has been refactored. At the same time,
it is convenient to directly obtain the parsing results of the same SQL to
improve parsing efficiency by putting the AST obtained from the first parsing
into the cache. Therefore, we recommend that users adopt `PreparedStatement`
this SQL pre-compilation method to improve performance. Currently, users can
also use ShardingSphere's SQL parsing engine independently to obtain AST and
SQL Statements for a variety of mainstream relational databases. In the future,
the SQL parsing engine will continue to provide powerful functions such as SQL
formatting and SQL templating.
+
+### Features
+
+* Independent SQL parsing engine
+* Support multiple dialects
+
+| DB | Status |
+|----------|--------|
+|MySQL |supported|
+|PostgreSQL|supported|
+|SQLServer |supported|
+|Oracle |supported|
+|SQL92 |supported|
+
+* SQL format (developing)
+* SQL parameterize (developing)
+
+### Advantages
+The syntax rules can be easily expanded and modified by using `ANTLR`
+
+### API Usage
+
+Maven config
+```
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-engine</artifactId>
+ <version>${project.version}</version>
+</dependency>
+// According to the needs, introduce the parsing module of the specified
dialect (take MySQL as an example)
+<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-mysql</artifactId>
+ <version>${project.version}</version>
+</dependency>
+```
+
+demo:
+
+1. Get AST
+
+```
+ParseTree tree = new SQLParserEngine(databaseType).parse(sql, false)
Review comment:
+1, Look forward to a simpler return value rather than a tree, maybe?
From the SkyWalking analysis requirements,
https://github.com/apache/skywalking/issues/5838, we need
1. DML type, create/delete/update. Or it is a DDL.
1. A listener mode or a way to iterate the table lists. I am not sure which
way do you provide for now.
The basic idea is, SkyWalking as an APM, doesn't intend to do routing,
sharding, or anything similar, we are planning to leverage this to get the
basic profile of the executed SQL statements which were captured by the
SkyWalking agents.
Also, I remember there is a cache mechanism in the parser engine, do you
have an LRU cache to keep memory safe? Or could I provide an implementation for
the cache by following your interface?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]