public class GreenplumSqlParser extends AbstractSqlParser
This parser handles Greenplum-specific SQL syntax including:
Design Notes:
AbstractSqlParser using the template method patternTLexerGreenplum for tokenizationTParserGreenplum for parsingUsage Example:
// Get Greenplum parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvgreenplum);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvgreenplum)
.sqlText("SELECT * FROM employees WHERE dept_id = 10")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
SqlParser,
AbstractSqlParser,
TLexerGreenplum,
TParserGreenplumAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerGreenplum |
flexer
The Greenplum lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
GreenplumSqlParser()
Construct Greenplum SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Hook method called after each statement is parsed.
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call Greenplum-specific raw statement extraction.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Greenplum lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Greenplum SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Greenplum doesn't use secondary parser (unlike Oracle with PL/SQL parser).
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser mainParser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Parse all statements in the statement list.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform semantic analysis on parsed statements.
|
protected void |
setupVendorParsersForExtraction()
Setup vendor parsers before raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call Greenplum-specific tokenization logic.
|
attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performInterpreter, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, toString, towinlinebreakpublic TLexerGreenplum flexer
public GreenplumSqlParser()
Configures the parser for Greenplum 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)
getSecondaryParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected void tokenizeVendorSql()
Delegates to dogreenplumtexttotokenlist which handles Greenplum's tokenization including backslash commands, dollar-quoted strings, and PostgreSQL-compatible syntax.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
Injects sqlcmds and sourcetokenlist into the Greenplum parser.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to dogreenplumgetrawsqlstatements which handles: - PL/pgSQL block boundaries (dollar-quoted strings) - Backslash meta commands - Semicolon-separated statements
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser mainParser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This is the main parsing loop that processes each raw statement and converts it into a fully parsed AST.
performParsing in class AbstractSqlParsercontext - the parser contextmainParser - 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 runs the TSQLResolver to resolve column-to-table relationships, data flow analysis, and other semantic checks.
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)protected void afterStatementParsed(TCustomSqlStatement stmt)
Greenplum doesn't need special post-processing, so this is a no-op.
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsed