Retro Eye care Haitian Deep Dark Default

SQL Parser


SQL is the standard language for users to communicate with databases. The SQL parsing engine is responsible for parsing the SQL string into an abstract syntax tree for Apache ShardingSphere to understand and implement its incremental function. Currently, MySQL, PostgreSQL, SQLServer, Oracle, openGauss and SQL dialects conforming to SQL92 specifications are supported. Due to the complexity of SQL syntax, there are still a few unsupported SQLs. By using SQL parsing in the form of Java API, you can easily integrate into various systems and flexibly customize user requirements.


Class: org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration


name DataType Description
parseTreeCache (?) CacheOption Parse syntax tree local cache configuration
sqlStatementCache (?) CacheOption sql statement local cache configuration

Cache option Configuration



name DataType Description Default Value
initialCapacity int Initial capacity of local cache parser syntax tree local cache default value 128, SQL statement cache default value 2000
maximumSize(?) long Maximum capacity of local cache The default value of local cache for parsing syntax tree is 1024, and the default value of sql statement cache is 65535


  1. Set local cache configuration.
  2. Set resolution configuration.
  3. Use the parsing engine to parse SQL.


CacheOption cacheOption = new CacheOption(128, 1024L);
SQLParserEngine parserEngine = new SQLParserEngine("MySQL", cacheOption);
ParseASTNode parseASTNode = parserEngine.parse("SELECT,, t.age FROM table1 AS t ORDER BY DESC;", false);
SQLStatementVisitorEngine visitorEngine = new SQLStatementVisitorEngine("MySQL");
MySQLStatement sqlStatement = visitorEngine.visit(parseASTNode);