Class HiveSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles Hive-specific SQL syntax including:
- Hive DDL statements (CREATE TABLE/DATABASE with Hive-specific options)
- Hive DML statements (INSERT OVERWRITE, LOAD DATA, etc.)
- HiveQL functions and extensions
- Backtick-quoted identifiers including qualified names (`schema.table`)
- Hive-specific keywords and data types
Design Notes:
- Extends
AbstractSqlParserusing the template method pattern - Uses
TLexerHivefor tokenization - Uses
TParserHivefor parsing - Delimiter character: ';' for SQL statements
- Splits backtick-quoted qualified names (`schema.table`) into individual tokens
Usage Example:
// Get Hive parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvhive);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvhive)
.sqlText("SELECT * FROM `default.employee` WHERE dept = 'IT'")
.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 voidCall Hive-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the Hive lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the Hive SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Hive 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 raw SQL statements.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform semantic analysis on parsed statements.protected voidSetup Hive parser for raw statement extraction.protected voidCall Hive-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 Hive lexer used for tokenization
-
-
Constructor Details
-
HiveSqlParser
public HiveSqlParser()Construct Hive SQL parser.Configures the parser for Hive 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 Hive lexer instance.- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- the parser context- Returns:
- configured lexer instance (never null)
-
getParser
Return the Hive 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
Hive 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 Hive-specific tokenization logic.Delegates to dohivetexttotokenlist which handles Hive's specific keyword recognition, backtick-quoted identifiers, and qualified name splitting.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup Hive parser for raw statement extraction.Hive uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call Hive-specific raw statement extraction logic.Delegates to dohivegetrawsqlstatements which handles Hive's statement delimiters (semicolons).
Note: parserContext is already set by AbstractSqlParser before this is called
- 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 raw SQL statements.This method performs full syntax analysis of each statement:
- Initializes global context and SQL environment
- Parses each statement using TParserHive
- Handles errors with optional error recovery
- Collects syntax errors for reporting
Migrated from TGSqlParser.performParsing()
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- the parser contextparser- the main parser (TParserHive)secondaryParser- the secondary parser (null for Hive)tokens- the source token listrawStatements- raw statements already extracted (never null)- Returns:
- the parsed statement list
-
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 for compile-time constant expression evaluation. Hive does not require interpretation currently.
- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements (mutable)
-
toString
- Overrides:
toStringin classAbstractSqlParser
-