public class BigQuerySqlParser extends AbstractSqlParser
This parser handles BigQuery-specific SQL syntax including:
Design Notes:
AbstractSqlParser using the template method patternTLexerBigquery for tokenizationTParserBigquery for parsingUsage Example:
// Get BigQuery parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvbigquery);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvbigquery)
.sqlText("SELECT * FROM `project.dataset.table` WHERE region = 'US'")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
SqlParser,
AbstractSqlParser,
TLexerBigquery,
TParserBigqueryAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerBigquery |
flexer
The BigQuery lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
BigQuerySqlParser()
Construct BigQuery SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Post-process statement after parsing (hook method).
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call BigQuery-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the BigQuery lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the BigQuery SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
BigQuery does not use a secondary parser (unlike Oracle with PL/SQL).
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform interpretation/evaluation on statements.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Parse all SQL statements after tokenization and raw extraction.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform semantic analysis on parsed statements.
|
protected void |
setupVendorParsersForExtraction()
Setup BigQuery parser for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call BigQuery-specific tokenization logic.
|
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 TLexerBigquery flexer
public BigQuerySqlParser()
Configures the parser for BigQuery 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 dobigquerysqltexttotokenlist which handles BigQuery's specific keyword recognition, backtick-quoted identifiers, and qualified name splitting.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
BigQuery uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to dobigquerygetrawsqlstatements which handles BigQuery's statement delimiters and scripting language boundaries (BEGIN...END blocks, IF/WHILE/FOR/LOOP statements).
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method iterates through all statements, calls parsestatement on each, and handles error recovery for CREATE TABLE statements if enabled.
Inherited performParsing pattern from AbstractSqlParser, specialized for BigQuery.
performParsing in class AbstractSqlParsercontext - the parser contextparser - 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)
BigQuery does not require special post-processing, so this is a no-op. Override if BigQuery-specific validation is needed in the future.
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsedprotected void performSemanticAnalysis(ParserContext context, TStatementList statements)
Runs TSQLResolver to build relationships between tables and columns, resolve references, and perform type checking.
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)protected void performInterpreter(ParserContext context, TStatementList statements)
Runs TASTEvaluator to execute constant expressions and compile-time evaluations.
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)public String toString()
toString in class AbstractSqlParser