public class SqlParser
extends java.lang.Object
SqlParser
parses a SQL statement.Modifier and Type | Class and Description |
---|---|
static interface |
SqlParser.Config
Interface to define the configuration for a SQL parser.
|
static class |
SqlParser.ConfigBuilder
Builder for a
SqlParser.Config . |
private static class |
SqlParser.ConfigImpl
Implementation of
SqlParser.Config . |
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_ALLOW_BANG_EQUAL
Deprecated.
|
static int |
DEFAULT_IDENTIFIER_MAX_LENGTH |
private SqlAbstractParserImpl |
parser |
Modifier | Constructor and Description |
---|---|
private |
SqlParser(SqlAbstractParserImpl parser,
SqlParser.Config config) |
Modifier and Type | Method and Description |
---|---|
static SqlParser.ConfigBuilder |
configBuilder()
Builder for a
SqlParser.Config . |
static SqlParser.ConfigBuilder |
configBuilder(SqlParser.Config config)
Builder for a
SqlParser.Config that starts with an existing Config . |
static SqlParser |
create(java.io.Reader reader,
SqlParser.Config config)
Creates a
SqlParser to parse the given string using the
parser implementation created from given SqlParserImplFactory
with given quoting syntax and casing policies for identifiers. |
static SqlParser |
create(java.lang.String s)
Creates a
SqlParser to parse the given string using
Calcite's parser implementation. |
static SqlParser |
create(java.lang.String sql,
SqlParser.Config config)
Creates a
SqlParser to parse the given string using the
parser implementation created from given SqlParserImplFactory
with given quoting syntax and casing policies for identifiers. |
SqlAbstractParserImpl.Metadata |
getMetadata()
Get the parser metadata.
|
private SqlParseException |
handleException(java.lang.Throwable ex)
Normalizes a SQL exception.
|
SqlNode |
parseExpression()
Parses a SQL expression.
|
SqlNode |
parseQuery()
Parses a
SELECT statement. |
SqlNode |
parseQuery(java.lang.String sql)
Parses a
SELECT statement and reuses parser. |
SqlNode |
parseStmt()
Parses an SQL statement.
|
SqlNodeList |
parseStmtList()
Parses a list of SQL statements separated by semicolon.
|
public static final int DEFAULT_IDENTIFIER_MAX_LENGTH
@Deprecated public static final boolean DEFAULT_ALLOW_BANG_EQUAL
private final SqlAbstractParserImpl parser
private SqlParser(SqlAbstractParserImpl parser, SqlParser.Config config)
public static SqlParser create(java.lang.String s)
SqlParser
to parse the given string using
Calcite's parser implementation.
The default lexical policy is similar to Oracle.
s
- An SQL statement or expression to parse.Lex.ORACLE
public static SqlParser create(java.lang.String sql, SqlParser.Config config)
SqlParser
to parse the given string using the
parser implementation created from given SqlParserImplFactory
with given quoting syntax and casing policies for identifiers.sql
- A SQL statement or expression to parseconfig
- The parser configuration (identifier max length, etc.)public static SqlParser create(java.io.Reader reader, SqlParser.Config config)
SqlParser
to parse the given string using the
parser implementation created from given SqlParserImplFactory
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 "?".
reader
- The source for the SQL statement or expression to parseconfig
- The parser configuration (identifier max length, etc.)public SqlNode parseExpression() throws SqlParseException
SqlParseException
- if there is a parse errorprivate SqlParseException handleException(java.lang.Throwable ex)
public SqlNode parseQuery() throws SqlParseException
SELECT
statement.SqlSelect
for a regular
SELECT
statement; a SqlBinaryOperator
for a UNION
, INTERSECT
, or EXCEPT
.SqlParseException
- if there is a parse errorpublic SqlNode parseQuery(java.lang.String sql) throws SqlParseException
SELECT
statement and reuses parser.sql
- sql to parseSqlSelect
for a regular
SELECT
statement; a SqlBinaryOperator
for a UNION
, INTERSECT
, or EXCEPT
.SqlParseException
- if there is a parse errorpublic SqlNode parseStmt() throws SqlParseException
SqlParseException
- if there is a parse errorpublic SqlNodeList parseStmtList() throws SqlParseException
SqlParseException
- if there is a parse errorpublic SqlAbstractParserImpl.Metadata getMetadata()
SqlAbstractParserImpl.Metadata
implementation of
underlying parser.public static SqlParser.ConfigBuilder configBuilder()
SqlParser.Config
.public static SqlParser.ConfigBuilder configBuilder(SqlParser.Config config)
SqlParser.Config
that starts with an existing Config
.Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.