Class BigQuerySqlParser
- All Implemented Interfaces:
SqlParser
This parser handles BigQuery-specific SQL syntax including:
- BigQuery scripting language (BEGIN...END blocks, IF/WHILE/FOR/LOOP/REPEAT statements)
- BigQuery UDFs (CREATE FUNCTION with SQL or JavaScript)
- BigQuery procedures (CREATE PROCEDURE with BEGIN...END blocks)
- Special type handling (STRUCT, ARRAY, DATE/TIME/TIMESTAMP literals)
- Backtick-quoted identifiers including qualified names (`schema.table`)
- BigQuery-specific keywords and functions
Design Notes:
- Extends
AbstractSqlParserusing the template method pattern - Uses
TLexerBigqueryfor tokenization - Uses
TParserBigqueryfor parsing - Delimiter character: ';' for SQL statements
- Splits backtick-quoted qualified names (`schema.table`) into individual tokens
Usage 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();
- 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, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidPost-process statement after parsing (hook method).protected voidCall BigQuery-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the BigQuery lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the BigQuery SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) BigQuery does not use a secondary parser (unlike Oracle with PL/SQL).protected voidperformInterpreter(ParserContext context, TStatementList statements) Perform interpretation/evaluation on statements.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Parse all SQL statements after tokenization and raw extraction.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform semantic analysis on parsed statements.protected voidSetup BigQuery parser for raw statement extraction.protected voidCall BigQuery-specific tokenization logic.toString()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, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreak
-
Field Details
-
flexer
The BigQuery lexer used for tokenization
-
-
Constructor Details
-
BigQuerySqlParser
public BigQuerySqlParser()Construct BigQuery SQL parser.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.
-
-
Method Details
-
getLexer
Return the BigQuery lexer instance.- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Return the BigQuery 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
BigQuery does not use a secondary parser (unlike Oracle with PL/SQL).- Overrides:
getSecondaryParserin classAbstractSqlParser- Parameters:
context- the parser contexttokens- the source token list- Returns:
- secondary parser instance, or null if not needed
-
tokenizeVendorSql
Call BigQuery-specific tokenization logic.Delegates to dobigquerysqltexttotokenlist which handles BigQuery's specific keyword recognition, backtick-quoted identifiers, and qualified name splitting.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup BigQuery parser for raw statement extraction.BigQuery uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call BigQuery-specific raw statement extraction logic.Delegates to dobigquerygetrawsqlstatements which handles BigQuery's statement delimiters and scripting language boundaries (BEGIN...END blocks, IF/WHILE/FOR/LOOP statements).
- 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) Parse all SQL statements after tokenization and raw extraction.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.
- 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)
-
afterStatementParsed
Post-process statement after parsing (hook method).BigQuery does not require special post-processing, so this is a no-op. Override if BigQuery-specific validation is needed in the future.
- Overrides:
afterStatementParsedin classAbstractSqlParser- Parameters:
stmt- the statement that was just parsed
-
performSemanticAnalysis
Perform semantic analysis on parsed statements.Runs TSQLResolver to build relationships between tables and columns, resolve references, and perform type checking.
- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
performInterpreter
Perform interpretation/evaluation on statements.Runs TASTEvaluator to execute constant expressions and compile-time evaluations.
- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
toString
- Overrides:
toStringin classAbstractSqlParser
-