Calcite - Sql Parser

1 - About

The ''calcite SQL Parser is a LL(k) parser that build a Sql tree (SqlNode)

3 - 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

4 - Custom

To parse specific SQL, you probably need to create:

  • a library (for functions)
  • a conformance
  • a new constant Lex.MY_SOURCE (may be).

5 - How to parse a SQL statement

5.1 - Query planning Utility

As shown in the getting_started, you can parse a SQL with the query planning utility

SqlNode sqlNode = planner.parse("select, count(emps.empid) from emps inner join depts on emps.deptno = depts.deptno group by depts.deptno, order by");

5.2 - SqlParser

Directly with a SqlParser Object

// Parser config with no case sensitivity (TABLE is the same than table)
SqlParser.Config parserConfig = SqlParser.configBuilder()
// 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

5.3 - JDBC prepare

See also the Prepare function of JDBC CalcitePrepareImpl#prepare2_ function

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap