public class DatabricksSqlParser extends AbstractSqlParser
This parser handles Databricks-specific SQL syntax including:
Implementation Status: MIGRATED
SqlParser,
AbstractSqlParser,
TLexerDatabricks,
TParserDatabricksAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerDatabricks |
flexer
The Databricks lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
DatabricksSqlParser()
Construct Databricks SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Post-processing hook after each statement is parsed.
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Hook method: Extract raw Databricks SQL statements.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Databricks lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Databricks SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Databricks uses a single parser, no secondary parser needed.
|
protected void |
handleCreateTableErrorRecovery(TCustomSqlStatement stmt)
Handle error recovery for CREATE TABLE statements.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform interpretation (execute SQL in interpreter mode).
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Parse all raw statements to build AST.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform semantic analysis (resolve column-table relationships, etc.).
|
protected void |
setupVendorParsersForExtraction()
Hook method: Setup parsers for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Hook method: Tokenize Databricks SQL by calling vendor-specific tokenization.
|
String |
toString() |
attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic TLexerDatabricks flexer
public DatabricksSqlParser()
Configures the parser for Databricks database with default delimiter: semicolon (;)
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)
The lexer is created once in the constructor and reused for all parsing operations.
getLexer in class AbstractSqlParsercontext - parser context (not used, lexer already created)protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
The parser is created once in the constructor and reused for all parsing operations.
getParser in class AbstractSqlParsercontext - parser context (not used, parser already created)tokens - source token list to parseprotected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens)
getSecondaryParser in class AbstractSqlParsercontext - parser contexttokens - source token listprotected void tokenizeVendorSql()
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populateprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method iterates through all raw statements and calls parsestatement() on each one to build the Abstract Syntax Tree. It handles error recovery for CREATE TABLE statements and collects syntax errors.
performParsing in class AbstractSqlParsercontext - parser context with configurationparser - primary parser instancesecondaryParser - secondary parser (null for Databricks)tokens - source token listrawStatements - raw statements from extraction phaseprotected void afterStatementParsed(TCustomSqlStatement stmt)
Default implementation does nothing. Override if needed for vendor-specific post-processing.
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsedprotected void handleCreateTableErrorRecovery(TCustomSqlStatement stmt)
This method attempts to recover from parse errors in CREATE TABLE statements by marking unparseable table properties (like ROW FORMAT, STORED AS, etc.) as sqlpluscmd and retrying.
Databricks/Hive DDL allows complex table properties after the column definition that may not be fully supported in the grammar. This error recovery allows partial parsing of the main table structure.
Extracted from TGSqlParser.doparse() lines 16916-16971
stmt - the statement with errorsprotected void performSemanticAnalysis(ParserContext context, TStatementList statements)
This method runs the TSQLResolver to build semantic relationships between columns and tables, among other analysis.
performSemanticAnalysis in class AbstractSqlParsercontext - parser contextstatements - statement list to analyzeprotected void performInterpreter(ParserContext context, TStatementList statements)
This method runs the TASTEvaluator to interpret/execute the SQL.
performInterpreter in class AbstractSqlParsercontext - parser contextstatements - statement list to interpretpublic String toString()
toString in class AbstractSqlParser