Class GaussDbSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles GaussDB-specific SQL syntax including:
- PostgreSQL-based SQL syntax with Oracle compatibility
- Stored procedures and functions (Oracle-style and PostgreSQL-style)
- Package specifications and bodies
- SQL*Plus-like commands
- Dynamic delimiter support
Implementation Status: MIGRATED
- Completed: Migrated from TGSqlParser to AbstractSqlParser
- Current: Fully self-contained GaussDB parser
Design Notes:
- Extends
AbstractSqlParserusing template method pattern - Uses single parser:
TParserGaussDB - Primary delimiter: semicolon (;)
- Supports both Oracle-style and PostgreSQL-style routines
- Handles package specifications and bodies with GaussDB-specific state tracking
- 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 vendor-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Get the lexer for this vendor.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Get the main parser for this vendor.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Get secondary parser (e.g., PL/SQL for Oracle).Get the database vendor this parser handles.protected voidGaussDB-specific statement completion logic.protected voidperformInterpreter(ParserContext context, TStatementList statements) Perform interpretation/evaluation on parsed statements.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform actual parsing with syntax checking.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform semantic analysis on parsed statements.protected voidSetup vendor-specific parsers for raw statement extraction.protected voidCall vendor-specific tokenization logic.toString()Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
afterStatementParsed, attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreak
-
Field Details
-
flexer
The GaussDB lexer used for tokenization
-
-
Constructor Details
-
GaussDbSqlParser
public GaussDbSqlParser()Construct GaussDB SQL parser.Configures the parser for GaussDB database with semicolon (;) as the default delimiter.
-
-
Method Details
-
getLexer
Description copied from class:AbstractSqlParserGet the lexer for this vendor.Subclass Responsibility: Return vendor-specific lexer instance. The lexer may be created fresh or cached/reused for performance.
Example:
protected TCustomLexer getLexer(ParserContext context) { TLexerOracle lexer = new TLexerOracle(); lexer.delimiterchar = delimiterChar; lexer.defaultDelimiterStr = defaultDelimiterStr; return lexer; }- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Description copied from class:AbstractSqlParserGet the main parser for this vendor.Subclass Responsibility: Return vendor-specific parser instance. The parser may be created fresh or cached/reused for performance. If reusing, the token list should be updated.
Example:
protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens) { TParserOracleSql parser = new TParserOracleSql(tokens); parser.lexer = getLexer(context); return parser; }- Specified by:
getParserin classAbstractSqlParser- Parameters:
context- the parser contexttokens- the source token list- Returns:
- configured parser instance (never null)
-
getSecondaryParser
Description copied from class:AbstractSqlParserGet secondary parser (e.g., PL/SQL for Oracle).Hook Method: Default implementation returns null. Override if vendor needs a secondary parser. The parser may be created fresh or cached/reused for performance.
Example (Oracle):
protected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens) { TParserOraclePLSql plsqlParser = new TParserOraclePLSql(tokens); plsqlParser.lexer = getLexer(context); return plsqlParser; }- Overrides:
getSecondaryParserin classAbstractSqlParser- Parameters:
context- the parser contexttokens- the source token list- Returns:
- secondary parser instance, or null if not needed
-
tokenizeVendorSql
Description copied from class:AbstractSqlParserCall vendor-specific tokenization logic.Hook Method: Called by
AbstractSqlParser.performTokenization(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TCustomLexer)to execute vendor-specific SQL-to-token conversion logic.Subclass Responsibility: Call the vendor-specific tokenization method (e.g., dooraclesqltexttotokenlist, domssqlsqltexttotokenlist) which reads from lexer and populates sourcetokenlist.
Example (Oracle):
protected void tokenizeVendorSql() { dooraclesqltexttotokenlist(); }Example (MSSQL):
protected void tokenizeVendorSql() { domssqlsqltexttotokenlist(); }Example (PostgreSQL):
protected void tokenizeVendorSql() { dopostgresqltexttotokenlist(); }- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Description copied from class:AbstractSqlParserSetup vendor-specific parsers for raw statement extraction.Hook Method: Called by
AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long)after initializing sqlcmds but before calling the vendor-specific extraction logic.Subclass Responsibility: Inject sqlcmds into vendor parser(s) and update their token lists. Examples:
- Single parser (MSSQL): Inject into fparser only
- Dual parsers (Oracle): Inject into both fparser and fplsqlparser
Example (MSSQL):
protected void setupVendorParsersForExtraction() { this.fparser.sqlcmds = this.sqlcmds; this.fparser.sourcetokenlist = this.sourcetokenlist; }Example (Oracle with dual parsers):
protected void setupVendorParsersForExtraction() { this.fparser.sqlcmds = this.sqlcmds; this.fplsqlparser.sqlcmds = this.sqlcmds; this.fparser.sourcetokenlist = this.sourcetokenlist; this.fplsqlparser.sourcetokenlist = this.sourcetokenlist; }- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Description copied from class:AbstractSqlParserCall vendor-specific raw statement extraction logic.Hook Method: Called by
AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long)to execute the vendor-specific logic for identifying statement boundaries.Subclass Responsibility: Call the vendor-specific extraction method (e.g., dooraclegetrawsqlstatements, domssqlgetrawsqlstatements) passing the builder. The extraction method will populate the builder with raw statements.
Example (Oracle):
protected void extractVendorRawStatements(SqlParseResult.Builder builder) { dooraclegetrawsqlstatements(builder); }Example (MSSQL):
protected void extractVendorRawStatements(SqlParseResult.Builder builder) { domssqlgetrawsqlstatements(builder); }- 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) Description copied from class:AbstractSqlParserPerform actual parsing with syntax checking.Subclass Responsibility: Parse SQL using vendor-specific parser and optional secondary parser (e.g., PL/SQL for Oracle).
Important: This method receives raw statements that have already been extracted by
AbstractSqlParser.getrawsqlstatements(ParserContext). Subclasses should NOT re-extract statements - just parse each statement to build the AST.Example:
protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) { // Use the passed-in rawStatements (DO NOT re-extract!) for (int i = 0; i < rawStatements.size(); i++) { TCustomSqlStatement stmt = rawStatements.get(i); stmt.parsestatement(...); // Build AST for each statement } return rawStatements; }- 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
Description copied from class:AbstractSqlParserPerform semantic analysis on parsed statements.Hook Method: Default implementation does nothing. Override to provide vendor-specific semantic analysis.
Typical Implementation:
- Column-to-table resolution (TSQLResolver)
- Dataflow analysis
- Reference resolution
- Scope resolution
- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
performInterpreter
Description copied from class:AbstractSqlParserPerform interpretation/evaluation on parsed statements.Hook Method: Default implementation does nothing. Override to provide AST interpretation/evaluation.
Typical Implementation:
- Execute simple SQL statements
- Evaluate expressions
- Constant folding
- Static analysis
- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
onRawStatementCompleteVendorSpecific
GaussDB-specific statement completion logic.Migrated from TGSqlParser.doongetrawsqlstatementevent() (lines 5129-5141).
For CREATE PROCEDURE/FUNCTION statements, marks Oracle-style routines by setting special token codes to distinguish them from PostgreSQL-style routines.
- Overrides:
onRawStatementCompleteVendorSpecificin classAbstractSqlParser- Parameters:
statement- the completed statement
-
getVendor
Description copied from interface:SqlParserGet the database vendor this parser handles.- Specified by:
getVendorin interfaceSqlParser- Overrides:
getVendorin classAbstractSqlParser- Returns:
- the database vendor (e.g., dbvoracle, dbvmysql)
-
toString
- Overrides:
toStringin classAbstractSqlParser
-