Package org.apache.ignite.internal.sql
Class SqlParserUtils
- java.lang.Object
-
- org.apache.ignite.internal.sql.SqlParserUtils
-
public class SqlParserUtils extends Object
Parser utility methods.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SqlParseExceptionerror(SqlLexerToken token, String msg)Create parse exception referring to current lexer position.static SqlParseExceptionerrorUnexpectedToken(SqlLexer lex, String expToken)Create generic parse exception due to unexpected token.static SqlParseExceptionerrorUnexpectedToken(SqlLexerToken token)Create generic parse exception due to unexpected token.static SqlParseExceptionerrorUnexpectedToken(SqlLexerToken token, String firstExpToken, String... expTokens)Create generic parse exception due to unexpected token.static SqlParseExceptionerrorUnsupported(SqlLexerToken token)Error on unsupported keyword.static voiderrorUnsupportedIfMatchesKeyword(SqlLexerToken token, String keyword)Throw unsupported token exception if passed keyword is found.static voiderrorUnsupportedIfMatchesKeyword(SqlLexerToken token, String... keywords)Throw unsupported token exception if one of passed keywords is found.static booleanisValidIdentifier(SqlLexerToken token)Check if token is identifier.static booleanmatchesKeyword(SqlLexerToken token, String expKeyword)Check if current lexer token matches expected.static booleanparseBoolean(SqlLexer lex)Parse boolean parameter value based on presence of tokens 1, 0, ON, OFF.static StringparseIdentifier(SqlLexer lex, String... additionalExpTokens)Process name.static booleanparseIfExists(SqlLexer lex)Parse IF EXISTS statement.static booleanparseIfNotExists(SqlLexer lex)Parse IF NOT EXISTS statement.static intparseInt(SqlLexer lex)Parse integer value (positive or negative).static SqlQualifiedNameparseQualifiedIdentifier(SqlLexer lex, String... additionalExpTokens)Process qualified name.static StringparseString(SqlLexer lex, String... additionalExpTokens)Process name.static StringparseUsername(SqlLexer lex, String... additionalExpTokens)Process name.static booleanskipCommaOrRightParenthesis(SqlLexer lex)Skip comma or right parenthesis.static voidskipIfMatches(SqlLexer lex, SqlLexerTokenType tokenTyp)Skip next token if it matches expected type.static voidskipIfMatchesKeyword(SqlLexer lex, String expKeyword)Skip token if it matches expected keyword.static booleanskipIfMatchesOptionalKeyword(SqlLexer lex, String expKeyword)Skip token if it matches expected keyword by using lookahead.
-
-
-
Method Detail
-
parseIfExists
public static boolean parseIfExists(SqlLexer lex)
Parse IF EXISTS statement.- Parameters:
lex- Lexer.- Returns:
Trueif statement is found.
-
parseIfNotExists
public static boolean parseIfNotExists(SqlLexer lex)
Parse IF NOT EXISTS statement.- Parameters:
lex- Lexer.- Returns:
Trueif statement is found.
-
skipCommaOrRightParenthesis
public static boolean skipCommaOrRightParenthesis(SqlLexer lex)
Skip comma or right parenthesis.- Parameters:
lex- Lexer.- Returns:
Trueif right parenthesis is found.
-
parseInt
public static int parseInt(SqlLexer lex)
Parse integer value (positive or negative).- Parameters:
lex- Lexer.- Returns:
- Integer value.
-
parseBoolean
public static boolean parseBoolean(SqlLexer lex)
Parse boolean parameter value based on presence of tokens 1, 0, ON, OFF. Not that this is not and is not intended to be routine for parsing a boolean literal from TRUE/FALSE.- Parameters:
lex- Lexer.- Returns:
- Boolean parameter value.
-
parseIdentifier
public static String parseIdentifier(SqlLexer lex, String... additionalExpTokens)
Process name.- Parameters:
lex- Lexer.additionalExpTokens- Additional expected tokens in case of error.- Returns:
- Name.
-
parseUsername
public static String parseUsername(SqlLexer lex, String... additionalExpTokens)
Process name.- Parameters:
lex- Lexer.additionalExpTokens- Additional expected tokens in case of error.- Returns:
- Name.
-
parseString
public static String parseString(SqlLexer lex, String... additionalExpTokens)
Process name.- Parameters:
lex- Lexer.additionalExpTokens- Additional expected tokens in case of error.- Returns:
- Name.
-
parseQualifiedIdentifier
public static SqlQualifiedName parseQualifiedIdentifier(SqlLexer lex, String... additionalExpTokens)
Process qualified name.- Parameters:
lex- Lexer.additionalExpTokens- Additional expected tokens in case of error.- Returns:
- Qualified name.
-
isValidIdentifier
public static boolean isValidIdentifier(SqlLexerToken token)
Check if token is identifier.- Parameters:
token- Token.- Returns:
Trueif we are standing on possible identifier.
-
matchesKeyword
public static boolean matchesKeyword(SqlLexerToken token, String expKeyword)
Check if current lexer token matches expected.- Parameters:
token- Token..expKeyword- Expected keyword.- Returns:
Trueif matches.
-
skipIfMatchesKeyword
public static void skipIfMatchesKeyword(SqlLexer lex, String expKeyword)
Skip token if it matches expected keyword.- Parameters:
lex- Lexer.expKeyword- Expected keyword.
-
skipIfMatchesOptionalKeyword
public static boolean skipIfMatchesOptionalKeyword(SqlLexer lex, String expKeyword)
Skip token if it matches expected keyword by using lookahead. If next token is not what we expect, no shift is done.- Parameters:
lex- Lexer.expKeyword- Expected keyword.- Returns:
trueIn case token mathes,falseotherwise.
-
skipIfMatches
public static void skipIfMatches(SqlLexer lex, SqlLexerTokenType tokenTyp)
Skip next token if it matches expected type.- Parameters:
lex- Lexer.tokenTyp- Expected token type.
-
error
public static SqlParseException error(SqlLexerToken token, String msg)
Create parse exception referring to current lexer position.- Parameters:
token- Token.msg- Message.- Returns:
- Exception.
-
errorUnexpectedToken
public static SqlParseException errorUnexpectedToken(SqlLexerToken token)
Create generic parse exception due to unexpected token.- Parameters:
token- Token.- Returns:
- Exception.
-
errorUnsupportedIfMatchesKeyword
public static void errorUnsupportedIfMatchesKeyword(SqlLexerToken token, String keyword)
Throw unsupported token exception if passed keyword is found.- Parameters:
token- Token.keyword- Keyword.
-
errorUnsupportedIfMatchesKeyword
public static void errorUnsupportedIfMatchesKeyword(SqlLexerToken token, String... keywords)
Throw unsupported token exception if one of passed keywords is found.- Parameters:
token- Token.keywords- Keywords.
-
errorUnsupported
public static SqlParseException errorUnsupported(SqlLexerToken token)
Error on unsupported keyword.- Parameters:
token- Token.- Returns:
- Error.
-
errorUnexpectedToken
public static SqlParseException errorUnexpectedToken(SqlLexer lex, String expToken)
Create generic parse exception due to unexpected token.- Parameters:
lex- Lexer.expToken- Expected token.- Returns:
- Exception.
-
errorUnexpectedToken
public static SqlParseException errorUnexpectedToken(SqlLexerToken token, String firstExpToken, String... expTokens)
Create generic parse exception due to unexpected token.- Parameters:
token- Token.firstExpToken- First expected token.expTokens- Additional expected tokens (if any).- Returns:
- Exception.
-
-