Class RedshiftSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles Redshift-specific SQL syntax including:
- PostgreSQL-based syntax (Redshift is based on PostgreSQL 8.0.2)
- PL/pgSQL functions and procedures
- CREATE FUNCTION with LANGUAGE clause
- Function body delimiters ($$)
- Redshift-specific types (ARRAY<type>, %ROWTYPE, etc.)
- Redshift-specific keywords (FILTER, LANGUAGE, etc.)
Design Notes:
- Extends
AbstractSqlParserusing the template method pattern - Uses
TLexerRedshiftfor tokenization - Uses
TParserRedshiftfor parsing - Delimiter character: ';' for SQL statements
Usage 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();
- Since:
- 3.2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
AbstractSqlParser.PreparedSqlReader -
Field Summary
FieldsFields inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCall Redshift-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the Redshift lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the Redshift SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Redshift doesn't have a secondary parser.protected voidperformInterpreter(ParserContext context, TStatementList statements) Perform interpretation on parsed statements.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing of statements with syntax checking.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform semantic analysis on parsed statements.protected voidSetup Redshift parser for raw statement extraction.protected voidCall Redshift-specific tokenization logic.toString()Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
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, towinlinebreak
-
Field Details
-
flexer
The Redshift lexer used for tokenization
-
-
Constructor Details
-
RedshiftSqlParser
public RedshiftSqlParser()Construct Redshift SQL parser.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.
-
-
Method Details
-
getLexer
Return the Redshift lexer instance.- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Return the Redshift SQL parser instance with updated token list.- Specified by:
getParserin classAbstractSqlParser- Parameters:
context- the parser contexttokens- the source token list- Returns:
- configured parser instance (never null)
-
getSecondaryParser
Redshift doesn't have a secondary parser.Only Oracle uses a secondary parser (PL/SQL parser).
- Overrides:
getSecondaryParserin classAbstractSqlParser- Parameters:
context- the parser contexttokens- the source token list- Returns:
- secondary parser instance, or null if not needed
-
tokenizeVendorSql
Call Redshift-specific tokenization logic.Delegates to doredshiftsqltexttotokenlist which handles Redshift's specific keyword recognition, PostgreSQL commands, and token generation.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup Redshift parser for raw statement extraction.Redshift uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call Redshift-specific raw statement extraction logic.Delegates to doredshiftgetrawsqlstatements which handles Redshift's statement delimiters (semicolon, function delimiters $$, etc.).
- Specified by:
extractVendorRawStatementsin classAbstractSqlParser- Parameters:
builder- the result builder to populate with raw statements
-
performParsing
protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing of statements with syntax checking.This method orchestrates the parsing of all statements.
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- the parser contextparser- the main parser instancesecondaryParser- secondary parser (may be null)tokens- the source token listrawStatements- raw statements already extracted (never null)- Returns:
- statement list with parsed AST (never null)
-
performSemanticAnalysis
Perform semantic analysis on parsed statements.This step resolves column-to-table relationships and performs type checking.
- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
performInterpreter
Perform interpretation on parsed statements.This step evaluates constant expressions and performs other interpretation tasks.
- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
toString
- Overrides:
toStringin classAbstractSqlParser
-