Class SqlParser

java.lang.Object
org.apache.calcite.sql.parser.SqlParser

@Enclosing public class SqlParser extends Object
A SqlParser parses a SQL statement.
  • Field Details

    • DEFAULT_IDENTIFIER_MAX_LENGTH

      public static final int DEFAULT_IDENTIFIER_MAX_LENGTH
      See Also:
    • DEFAULT_ALLOW_BANG_EQUAL

      @Deprecated public static final boolean DEFAULT_ALLOW_BANG_EQUAL
      Deprecated.
  • Method Details

    • create

      public static SqlParser create(String s)
      Creates a SqlParser 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:
    • create

      public static SqlParser create(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.
      Parameters:
      sql - A SQL statement or expression to parse
      config - The parser configuration (identifier max length, etc.)
      Returns:
      A parser
    • create

      public static SqlParser create(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.

      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 parse
      config - 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 a SELECT statement.
      Returns:
      A SqlSelect for a regular SELECT statement; a SqlBinaryOperator for a UNION, INTERSECT, or EXCEPT.
      Throws:
      SqlParseException - if there is a parse error
    • parseQuery

      public SqlNode parseQuery(String sql) throws SqlParseException
      Parses a SELECT statement and reuses parser.
      Parameters:
      sql - sql to parse
      Returns:
      A SqlSelect for a regular SELECT statement; a SqlBinaryOperator for a UNION, INTERSECT, or EXCEPT.
      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
    • parseStmtList

      public SqlNodeList parseStmtList() throws SqlParseException
      Parses a list of SQL statements separated by semicolon. The semicolon is required between statements, but is optional at the end.
      Returns:
      list of SqlNodeList representing the list of SQL statements
      Throws:
      SqlParseException - if there is a parse error
    • getMetadata

      public org.apache.calcite.sql.parser.SqlAbstractParserImpl.Metadata getMetadata()
      Get the parser metadata.
      Returns:
      SqlAbstractParserImpl.Metadata implementation of underlying parser.
    • getWarnings

      public List<CalciteContextException> getWarnings()
      Returns the warnings that were generated by the previous invocation of the parser.
    • config

      public static SqlParser.Config config()
      Returns a default SqlParser.Config.
    • configBuilder

      @Deprecated public static SqlParser.ConfigBuilder configBuilder()
      Deprecated.
      Builder for a SqlParser.Config.
    • configBuilder

      @Deprecated public static SqlParser.ConfigBuilder configBuilder(SqlParser.Config config)
      Deprecated.
      Use config, and modify it using its mutator methods
      Builder for a SqlParser.Config that starts with an existing Config.