Package org.apache.calcite.sql.parser
Class SqlParser
- java.lang.Object
-
- org.apache.calcite.sql.parser.SqlParser
-
public class SqlParser extends java.lang.Object
ASqlParser
parses a SQL statement.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SqlParser.Config
Interface to define the configuration for a SQL parser.static class
SqlParser.ConfigBuilder
Builder for aSqlParser.Config
.private static class
SqlParser.ConfigImpl
Implementation ofSqlParser.Config
.
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_ALLOW_BANG_EQUAL
Deprecated.static int
DEFAULT_IDENTIFIER_MAX_LENGTH
private SqlAbstractParserImpl
parser
-
Constructor Summary
Constructors Modifier Constructor Description private
SqlParser(SqlAbstractParserImpl parser, SqlParser.Config config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SqlParser.ConfigBuilder
configBuilder()
Builder for aSqlParser.Config
.static SqlParser.ConfigBuilder
configBuilder(SqlParser.Config config)
Builder for aSqlParser.Config
that starts with an existingConfig
.static SqlParser
create(java.io.Reader reader, SqlParser.Config config)
Creates aSqlParser
to parse the given string using the parser implementation created from givenSqlParserImplFactory
with given quoting syntax and casing policies for identifiers.static SqlParser
create(java.lang.String s)
Creates aSqlParser
to parse the given string using Calcite's parser implementation.static SqlParser
create(java.lang.String sql, SqlParser.Config config)
Creates aSqlParser
to parse the given string using the parser implementation created from givenSqlParserImplFactory
with given quoting syntax and casing policies for identifiers.SqlAbstractParserImpl.Metadata
getMetadata()
Get the parser metadata.SqlNode
parseExpression()
Parses a SQL expression.SqlNode
parseQuery()
Parses aSELECT
statement.SqlNode
parseQuery(java.lang.String sql)
Parses aSELECT
statement and reuses parser.SqlNode
parseStmt()
Parses an SQL statement.
-
-
-
Field Detail
-
DEFAULT_IDENTIFIER_MAX_LENGTH
public static final int DEFAULT_IDENTIFIER_MAX_LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_ALLOW_BANG_EQUAL
@Deprecated public static final boolean DEFAULT_ALLOW_BANG_EQUAL
Deprecated.
-
parser
private final SqlAbstractParserImpl parser
-
-
Constructor Detail
-
SqlParser
private SqlParser(SqlAbstractParserImpl parser, SqlParser.Config config)
-
-
Method Detail
-
create
public static SqlParser create(java.lang.String s)
Creates aSqlParser
to parse the given string using Calcite's parser implementation.The default lexical policy is similar to Oracle.
- Parameters:
s
- An SQL statement or expression to parse.- Returns:
- A parser
- See Also:
Lex.ORACLE
-
create
public static SqlParser create(java.lang.String sql, SqlParser.Config config)
Creates aSqlParser
to parse the given string using the parser implementation created from givenSqlParserImplFactory
with given quoting syntax and casing policies for identifiers.- Parameters:
sql
- A SQL statement or expression to parseconfig
- The parser configuration (identifier max length, etc.)- Returns:
- A parser
-
create
public static SqlParser create(java.io.Reader reader, SqlParser.Config config)
Creates aSqlParser
to parse the given string using the parser implementation created from givenSqlParserImplFactory
with given quoting syntax and casing policies for identifiers.Unlike
create(java.lang.String, org.apache.calcite.sql.parser.SqlParser.Config)
, the parser is not able to return the original query string, but will instead return "?".- Parameters:
reader
- The source for the SQL statement or expression to parseconfig
- The parser configuration (identifier max length, etc.)- Returns:
- A parser
-
parseExpression
public SqlNode parseExpression() throws SqlParseException
Parses a SQL expression.- Throws:
SqlParseException
- if there is a parse error
-
parseQuery
public SqlNode parseQuery() throws SqlParseException
Parses aSELECT
statement.- Returns:
- A
SqlSelect
for a regularSELECT
statement; aSqlBinaryOperator
for aUNION
,INTERSECT
, orEXCEPT
. - Throws:
SqlParseException
- if there is a parse error
-
parseQuery
public SqlNode parseQuery(java.lang.String sql) throws SqlParseException
Parses aSELECT
statement and reuses parser.- Parameters:
sql
- sql to parse- Returns:
- A
SqlSelect
for a regularSELECT
statement; aSqlBinaryOperator
for aUNION
,INTERSECT
, orEXCEPT
. - Throws:
SqlParseException
- if there is a parse error
-
parseStmt
public SqlNode parseStmt() throws SqlParseException
Parses an SQL statement.- Returns:
- top-level SqlNode representing stmt
- Throws:
SqlParseException
- if there is a parse error
-
getMetadata
public SqlAbstractParserImpl.Metadata getMetadata()
Get the parser metadata.- Returns:
SqlAbstractParserImpl.Metadata
implementation of underlying parser.
-
configBuilder
public static SqlParser.ConfigBuilder configBuilder()
Builder for aSqlParser.Config
.
-
configBuilder
public static SqlParser.ConfigBuilder configBuilder(SqlParser.Config config)
Builder for aSqlParser.Config
that starts with an existingConfig
.
-
-