Class HanaSqlParser

Object
gudusoft.gsqlparser.parser.AbstractSqlParser
gudusoft.gsqlparser.parser.HanaSqlParser
All Implemented Interfaces:
SqlParser

public class HanaSqlParser extends AbstractSqlParser
SAP HANA SQL parser implementation.

This parser handles HANA-specific SQL syntax including:

  • HANA-specific SQL statements and DDL
  • Stored procedures and functions
  • Special HANA keywords and constructs (WITH STRUCTURED, WITH CACHE, etc.)
  • HANA date/time/timestamp constants
  • HANA-specific operators and expressions

Implementation Status: MIGRATED

  • Completed: Migrated from TGSqlParser to AbstractSqlParser
  • Current: Fully self-contained HANA parser

Design Notes:

  • Extends AbstractSqlParser using template method pattern
  • Uses single parser: TParserHana
  • Primary delimiter: semicolon (;)
  • Handles HANA-specific token transformations during raw extraction
Since:
3.2.0.0
See Also:
  • Field Details

  • Constructor Details

    • HanaSqlParser

      public HanaSqlParser()
      Construct HANA SQL parser.

      Configures the parser for SAP HANA database with semicolon (;) as the default delimiter.

  • Method Details

    • getLexer

      protected TCustomLexer getLexer(ParserContext context)
      Description copied from class: AbstractSqlParser
      Get the lexer for this vendor.

      Subclass Responsibility: Return vendor-specific lexer instance. The lexer may be created fresh or cached/reused for performance.

      Example:

       protected TCustomLexer getLexer(ParserContext context) {
           TLexerOracle lexer = new TLexerOracle();
           lexer.delimiterchar = delimiterChar;
           lexer.defaultDelimiterStr = defaultDelimiterStr;
           return lexer;
       }
       
      Specified by:
      getLexer in class AbstractSqlParser
      Parameters:
      context - the parser context
      Returns:
      configured lexer instance (never null)
    • getParser

      protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
      Description copied from class: AbstractSqlParser
      Get the main parser for this vendor.

      Subclass Responsibility: Return vendor-specific parser instance. The parser may be created fresh or cached/reused for performance. If reusing, the token list should be updated.

      Example:

       protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens) {
           TParserOracleSql parser = new TParserOracleSql(tokens);
           parser.lexer = getLexer(context);
           return parser;
       }
       
      Specified by:
      getParser in class AbstractSqlParser
      Parameters:
      context - the parser context
      tokens - the source token list
      Returns:
      configured parser instance (never null)
    • getSecondaryParser

      Description copied from class: AbstractSqlParser
      Get secondary parser (e.g., PL/SQL for Oracle).

      Hook Method: Default implementation returns null. Override if vendor needs a secondary parser. The parser may be created fresh or cached/reused for performance.

      Example (Oracle):

       protected TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens) {
           TParserOraclePLSql plsqlParser = new TParserOraclePLSql(tokens);
           plsqlParser.lexer = getLexer(context);
           return plsqlParser;
       }
       
      Overrides:
      getSecondaryParser in class AbstractSqlParser
      Parameters:
      context - the parser context
      tokens - the source token list
      Returns:
      secondary parser instance, or null if not needed
    • tokenizeVendorSql

      protected void tokenizeVendorSql()
      Description copied from class: AbstractSqlParser
      Call vendor-specific tokenization logic.

      Hook Method: Called by AbstractSqlParser.performTokenization(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TCustomLexer) to execute vendor-specific SQL-to-token conversion logic.

      Subclass Responsibility: Call the vendor-specific tokenization method (e.g., dooraclesqltexttotokenlist, domssqlsqltexttotokenlist) which reads from lexer and populates sourcetokenlist.

      Example (Oracle):

       protected void tokenizeVendorSql() {
           dooraclesqltexttotokenlist();
       }
       

      Example (MSSQL):

       protected void tokenizeVendorSql() {
           domssqlsqltexttotokenlist();
       }
       

      Example (PostgreSQL):

       protected void tokenizeVendorSql() {
           dopostgresqltexttotokenlist();
       }
       
      Specified by:
      tokenizeVendorSql in class AbstractSqlParser
    • setupVendorParsersForExtraction

      Description copied from class: AbstractSqlParser
      Setup vendor-specific parsers for raw statement extraction.

      Hook Method: Called by AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long) after initializing sqlcmds but before calling the vendor-specific extraction logic.

      Subclass Responsibility: Inject sqlcmds into vendor parser(s) and update their token lists. Examples:

      • Single parser (MSSQL): Inject into fparser only
      • Dual parsers (Oracle): Inject into both fparser and fplsqlparser

      Example (MSSQL):

       protected void setupVendorParsersForExtraction() {
           this.fparser.sqlcmds = this.sqlcmds;
           this.fparser.sourcetokenlist = this.sourcetokenlist;
       }
       

      Example (Oracle with dual parsers):

       protected void setupVendorParsersForExtraction() {
           this.fparser.sqlcmds = this.sqlcmds;
           this.fplsqlparser.sqlcmds = this.sqlcmds;
           this.fparser.sourcetokenlist = this.sourcetokenlist;
           this.fplsqlparser.sourcetokenlist = this.sourcetokenlist;
       }
       
      Specified by:
      setupVendorParsersForExtraction in class AbstractSqlParser
    • extractVendorRawStatements

      Description copied from class: AbstractSqlParser
      Call vendor-specific raw statement extraction logic.

      Hook Method: Called by AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long) to execute the vendor-specific logic for identifying statement boundaries.

      Subclass Responsibility: Call the vendor-specific extraction method (e.g., dooraclegetrawsqlstatements, domssqlgetrawsqlstatements) passing the builder. The extraction method will populate the builder with raw statements.

      Example (Oracle):

       protected void extractVendorRawStatements(SqlParseResult.Builder builder) {
           dooraclegetrawsqlstatements(builder);
       }
       

      Example (MSSQL):

       protected void extractVendorRawStatements(SqlParseResult.Builder builder) {
           domssqlgetrawsqlstatements(builder);
       }
       
      Specified by:
      extractVendorRawStatements in class AbstractSqlParser
      Parameters:
      builder - the result builder to populate with raw statements
    • performParsing

      protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
      Description copied from class: AbstractSqlParser
      Perform actual parsing with syntax checking.

      Subclass Responsibility: Parse SQL using vendor-specific parser and optional secondary parser (e.g., PL/SQL for Oracle).

      Important: This method receives raw statements that have already been extracted by AbstractSqlParser.getrawsqlstatements(ParserContext). Subclasses should NOT re-extract statements - just parse each statement to build the AST.

      Example:

       protected TStatementList performParsing(ParserContext context,
                                               TCustomParser parser,
                                               TCustomParser secondaryParser,
                                               TSourceTokenList tokens,
                                               TStatementList rawStatements) {
           // Use the passed-in rawStatements (DO NOT re-extract!)
           for (int i = 0; i < rawStatements.size(); i++) {
               TCustomSqlStatement stmt = rawStatements.get(i);
               stmt.parsestatement(...);  // Build AST for each statement
           }
           return rawStatements;
       }
       
      Specified by:
      performParsing in class AbstractSqlParser
      Parameters:
      context - the parser context
      parser - the main parser instance
      secondaryParser - secondary parser (may be null)
      tokens - the source token list
      rawStatements - raw statements already extracted (never null)
      Returns:
      statement list with parsed AST (never null)
    • performSemanticAnalysis

      protected void performSemanticAnalysis(ParserContext context, TStatementList statements)
      Description copied from class: AbstractSqlParser
      Perform semantic analysis on parsed statements.

      Hook Method: Default implementation does nothing. Override to provide vendor-specific semantic analysis.

      Typical Implementation:

      • Column-to-table resolution (TSQLResolver)
      • Dataflow analysis
      • Reference resolution
      • Scope resolution
      Overrides:
      performSemanticAnalysis in class AbstractSqlParser
      Parameters:
      context - the parser context
      statements - the parsed statements (mutable)