About
The ''calcite SQL Parser is a LL(k) parser that build a Sql tree (SqlNode)
Articles Related
Config
The parserConfig parameters control the parse process.
For example:
- identifiers (quoted using brackets, or back-ticks or double-quotes),
- how to treat the case of quoted and unquoted identifiers
Custom
To parse specific SQL, you probably need to create:
- a new constant Lex.MY_SOURCE (may be).
How to parse a SQL statement
Query planning Utility
As shown in the getting_started, you can parse a SQL with the query planning utility
SqlNode sqlNode = planner.parse("select depts.name, count(emps.empid) from emps inner join depts on emps.deptno = depts.deptno group by depts.deptno, depts.name order by depts.name");
SqlParser
Directly with a SqlParser Object
// Parser config with no case sensitivity (TABLE is the same than table)
SqlParser.Config parserConfig = SqlParser.configBuilder()
.setCaseSensitive(false)
.build();
// Create
SqlParser parser = SqlParser.create(sql, parserConfig)
// Parse
SqlNode sqlNode = parser.parseStmt() // for a statement
SqlNode sqlNode = parser.parseQuery() // if you known that it's a query
...
JDBC prepare
See also the Prepare function of JDBC CalcitePrepareImpl#prepare2_ function