Class GreenplumSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles Greenplum-specific SQL syntax including:
- PL/pgSQL blocks (procedures, functions, triggers)
- Dollar-quoted strings ($$ ... $$)
- Backslash meta commands (\d, \dt, etc.)
- PostgreSQL-compatible syntax extensions
- Special token handling (INNER, NOT DEFERRABLE, etc.)
Design Notes:
- Extends
AbstractSqlParserusing the template method pattern - Uses
TLexerGreenplumfor tokenization - Uses
TParserGreenplumfor parsing - Delimiter character: '/' for PL/pgSQL blocks
Usage 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();
- Since:
- 3.3.1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
AbstractSqlParser.PreparedSqlReader -
Field Summary
FieldsModifier and TypeFieldDescriptionThe Greenplum lexer used for tokenizationFields 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 voidHook method called after each statement is parsed.protected voidCall Greenplum-specific raw statement extraction.protected TCustomLexergetLexer(ParserContext context) Return the Greenplum lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the Greenplum SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Greenplum doesn't use secondary parser (unlike Oracle with PL/SQL parser).protected TStatementListperformParsing(ParserContext context, TCustomParser mainParser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Parse all statements in the statement list.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform semantic analysis on parsed statements.protected voidSetup vendor parsers before raw statement extraction.protected voidCall Greenplum-specific tokenization logic.Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
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, towinlinebreak
-
Field Details
-
flexer
The Greenplum lexer used for tokenization
-
-
Constructor Details
-
GreenplumSqlParser
public GreenplumSqlParser()Construct Greenplum SQL parser.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.
-
-
Method Details
-
getLexer
Return the Greenplum lexer instance.- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Return the Greenplum 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
Greenplum doesn't use secondary parser (unlike Oracle with 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 Greenplum-specific tokenization logic.Delegates to dogreenplumtexttotokenlist which handles Greenplum's tokenization including backslash commands, dollar-quoted strings, and PostgreSQL-compatible syntax.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup vendor parsers before raw statement extraction.Injects sqlcmds and sourcetokenlist into the Greenplum parser.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call Greenplum-specific raw statement extraction.Delegates to dogreenplumgetrawsqlstatements which handles: - PL/pgSQL block boundaries (dollar-quoted strings) - Backslash meta commands - Semicolon-separated statements
- Specified by:
extractVendorRawStatementsin classAbstractSqlParser- Parameters:
builder- the result builder to populate with raw statements
-
performParsing
protected TStatementList performParsing(ParserContext context, TCustomParser mainParser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Parse all statements in the statement list.This is the main parsing loop that processes each raw statement and converts it into a fully parsed AST.
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- the parser contextmainParser- 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 runs the TSQLResolver to resolve column-to-table relationships, data flow analysis, and other semantic checks.
- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
afterStatementParsed
Hook method called after each statement is parsed.Greenplum doesn't need special post-processing, so this is a no-op.
- Overrides:
afterStatementParsedin classAbstractSqlParser- Parameters:
stmt- the statement that was just parsed
-