public class FlinkSqlParser extends AbstractSqlParser
This parser handles Flink SQL-specific syntax including:
Implementation Status: NEW
SqlParser,
AbstractSqlParser,
TLexerFlink,
TParserFlinkAbstractSqlParser.PreparedSqlReaderdefaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
FlinkSqlParser()
Construct Flink SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Hook for vendor-specific post-processing after statement is parsed.
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Hook method for vendor-specific raw statement extraction.
|
protected TCustomLexer |
getLexer(ParserContext context)
Get the lexer for this vendor.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Get the main parser for this vendor.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Get secondary parser (e.g., PL/SQL for Oracle).
|
EDbVendor |
getVendor()
Get the database vendor this parser handles.
|
protected void |
handleCreateTableErrorRecovery(TCustomSqlStatement stmt)
Handle error recovery for CREATE TABLE statements.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform interpretation/evaluation on parsed statements.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser mainParser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Perform actual parsing with syntax checking.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform semantic analysis on parsed statements.
|
protected void |
setupVendorParsersForExtraction()
Hook method to setup parsers before raw statement extraction.
|
protected void |
tokenizeVendorSql()
Hook method for vendor-specific tokenization.
|
String |
toString() |
attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic FlinkSqlParser()
Configures the parser for Flink SQL with default delimiter (;).
public EDbVendor getVendor()
SqlParsergetVendor in interface SqlParsergetVendor in class AbstractSqlParserprotected TCustomLexer getLexer(ParserContext context)
AbstractSqlParserSubclass 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;
}
getLexer in class AbstractSqlParsercontext - the parser contextprotected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
AbstractSqlParserSubclass 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;
}
getParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens)
AbstractSqlParserHook 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;
}
getSecondaryParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected void tokenizeVendorSql()
Delegates to doflinktexttotokenlist() which implements Flink SQL-specific token processing logic.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser mainParser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
AbstractSqlParserSubclass 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;
}
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 afterStatementParsed(TCustomSqlStatement stmt)
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsedprotected void handleCreateTableErrorRecovery(TCustomSqlStatement stmt)
protected void performSemanticAnalysis(ParserContext context, TStatementList statements)
AbstractSqlParserHook Method: Default implementation does nothing. Override to provide vendor-specific semantic analysis.
Typical Implementation:
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)protected void performInterpreter(ParserContext context, TStatementList statements)
AbstractSqlParserHook Method: Default implementation does nothing. Override to provide AST interpretation/evaluation.
Typical Implementation:
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)public String toString()
toString in class AbstractSqlParser