public class RedshiftSqlParser extends AbstractSqlParser
This parser handles Redshift-specific SQL syntax including:
Design Notes:
AbstractSqlParser using the template method patternTLexerRedshift for tokenizationTParserRedshift for parsingUsage Example:
// Get Redshift parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvredshift);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvredshift)
.sqlText("SELECT * FROM orders WHERE order_date > CURRENT_DATE - 7")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
SqlParser,
AbstractSqlParser,
TLexerRedshift,
TParserRedshiftAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerRedshift |
flexer
The Redshift lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
RedshiftSqlParser()
Construct Redshift SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call Redshift-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Redshift lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Redshift SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Redshift doesn't have a secondary parser.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform interpretation on parsed statements.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Perform full parsing of statements with syntax checking.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform semantic analysis on parsed statements.
|
protected void |
setupVendorParsersForExtraction()
Setup Redshift parser for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call Redshift-specific tokenization logic.
|
String |
toString() |
afterStatementParsed, attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic TLexerRedshift flexer
public RedshiftSqlParser()
Configures the parser for Redshift database with default delimiter (;).
Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.
protected TCustomLexer getLexer(ParserContext context)
getLexer in class AbstractSqlParsercontext - the parser contextprotected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
getParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens)
Only Oracle uses a secondary parser (PL/SQL parser).
getSecondaryParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected void tokenizeVendorSql()
Delegates to doredshiftsqltexttotokenlist which handles Redshift's specific keyword recognition, PostgreSQL commands, and token generation.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
Redshift uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to doredshiftgetrawsqlstatements which handles Redshift's statement delimiters (semicolon, function delimiters $$, etc.).
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method orchestrates the parsing of all statements.
performParsing in class AbstractSqlParsercontext - the parser contextparser - the main parser instancesecondaryParser - secondary parser (may be null)tokens - the source token listrawStatements - raw statements already extracted (never null)protected void performSemanticAnalysis(ParserContext context, TStatementList statements)
This step resolves column-to-table relationships and performs type checking.
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)protected void performInterpreter(ParserContext context, TStatementList statements)
This step evaluates constant expressions and performs other interpretation tasks.
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)public String toString()
toString in class AbstractSqlParser