Package org.apache.calcite.sql

Provides a SQL parser and object model.

This package, and the dependent org.apache.calcite.sql.parser package, are independent of the other Calcite packages, so may be used standalone.

Parser

SqlParser parses a SQL string to a parse tree. It only performs the most basic syntactic validation.

Object model

Every node in the parse tree is a SqlNode. Sub-types are:

A SqlOperator describes the behavior of a node in the tree, such as how to un-parse a SqlCall into a SQL string. It is important to note that operators are metadata, not data: there is only one SqlOperator instance representing the '=' operator, even though there may be many calls to it.

SqlOperator has several derived classes which make it easy to define new operators: SqlFunction, SqlBinaryOperator, SqlPrefixOperator, SqlPostfixOperator. And there are singleton classes for special syntactic constructs SqlSelectOperator and SqlJoin.SqlJoinOperator. (These special operators even have their own sub-types of SqlCall: SqlSelect and SqlJoin.)

A SqlOperatorTable is a collection of operators. By supplying your own operator table, you can customize the dialect of SQL without modifying the parser.

Validation

SqlValidator checks that a tree of SqlNodes is semantically valid. You supply a SqlOperatorTable to describe the available functions and operators, and a SqlValidatorCatalogReader for access to the database's catalog.

Generating SQL

A SqlWriter converts a tree of SqlNodes into a SQL string. A SqlDialect defines how this happens.

Skip navigation links

Copyright © 2012–2017 The Apache Software Foundation. All rights reserved.