Package gudusoft.gsqlparser.parser
Class SnowflakeSqlParser
Object
gudusoft.gsqlparser.parser.AbstractSqlParser
gudusoft.gsqlparser.parser.SnowflakeSqlParser
- All Implemented Interfaces:
SqlParser
Snowflake database SQL parser implementation.
This parser handles Snowflake-specific SQL syntax including:
- Snowflake stored procedures (SQL and JavaScript)
- Snowflake-specific functions (FLATTEN, PIVOT, UNPIVOT, etc.)
- Snowflake tasks and streams
- Snowflake semi-structured data handling (VARIANT, ARRAY, OBJECT)
- Special token handling (AT, LEFT/RIGHT joins, DATE/TIME functions)
- Transaction control (BEGIN TRANSACTION, COMMIT, ROLLBACK)
Design Notes:
- Extends
AbstractSqlParserusing the template method pattern - Uses
TLexerSnowflakefor tokenization - Uses
TParserSnowflakefor parsing - Delimiter character: ';' for SQL statements
Usage Example:
// Get Snowflake parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvsnowflake);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvsnowflake)
.sqlText("SELECT * FROM customers 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
FieldsModifier and TypeFieldDescriptionThe Snowflake lexer used for tokenizationFields 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 Snowflake-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the Snowflake lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the Snowflake SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Snowflake does not use a secondary parser (unlike Oracle with PL/SQL).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 full parsing of statements with syntax checking.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform Snowflake-specific semantic analysis using TSQLResolver.protected voidSetup Snowflake parser for raw statement extraction.protected voidCall Snowflake-specific tokenization logic.toString()Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
afterStatementParsed, 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 Snowflake lexer used for tokenization
-
-
Constructor Details
-
SnowflakeSqlParser
public SnowflakeSqlParser()Construct Snowflake SQL parser.Configures the parser for Snowflake 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 Snowflake lexer instance.- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Return the Snowflake 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
Snowflake 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 Snowflake-specific tokenization logic.Delegates to dosnowflakesqltexttotokenlist which handles Snowflake's specific keyword recognition and token generation.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup Snowflake parser for raw statement extraction.Snowflake uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call Snowflake-specific raw statement extraction logic.Delegates to dosnowflakegetrawsqlstatements which handles Snowflake's statement delimiters and stored procedure boundaries.
- 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) Perform full parsing of statements with syntax checking.This method orchestrates the parsing of all statements.
- 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
Perform Snowflake-specific semantic analysis using TSQLResolver.- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
performInterpreter
Perform interpretation/evaluation on parsed statements.- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
toString
- Overrides:
toStringin classAbstractSqlParser
-