Class TSQLResolver2ResultFormatter

Object
gudusoft.gsqlparser.resolver2.TSQLResolver2ResultFormatter

Formats the resolution results from TSQLResolver2 into structured output for testing assertions and debugging.

This class provides a consistent way to extract and format Tables / Fields / CTE information from TSQLResolver2 results, handling special scenarios such as UNNEST, CTE, JOIN...USING, SELECT * EXCEPT, etc.

Separation of Concerns Principle

Key Principle: TSQLResolver2ResultFormatter is only responsible for formatting output, NOT for name resolution.

Violating this principle will cause:

  • Users directly using the TSQLResolver2 API will not get correct resolution results
  • Data consistency issues in resolution results

This means the formatter should only read data that has already been resolved by the resolver components. It should never attempt to perform resolution logic such as guessing table names for unresolved columns or modifying the AST nodes.

Configuration Options

The formatter supports various configuration options to control output:

Usage Example


 TSQLResolver2 resolver = new TSQLResolver2(env, statements, config);
 resolver.resolve();

 TSQLResolver2ResultFormatter formatter = new TSQLResolver2ResultFormatter(resolver);
 formatter.setShowCTE(true);
 formatter.setShowDatatype(true);

 String result = formatter.format();
 
See Also:
  • Constructor Details

  • Method Details

    • setShowCTE

      public TSQLResolver2ResultFormatter setShowCTE(boolean showCTE)
    • setShowDatatype

      public TSQLResolver2ResultFormatter setShowDatatype(boolean showDatatype)
    • setShowColumnsOfCTE

      public TSQLResolver2ResultFormatter setShowColumnsOfCTE(boolean showColumnsOfCTE)
    • setListStarColumn

      public TSQLResolver2ResultFormatter setListStarColumn(boolean listStarColumn)
    • getDisplayNameMode

      Get the current display name mode.
      Returns:
      the current DisplayNameMode
    • setDisplayNameMode

      Set the display name mode for identifier formatting.

      This controls how identifiers (table names, column names) are formatted in output:

      This method can be called after instantiation to change the mode for each SQL text being processed.

      Parameters:
      mode - the DisplayNameMode to use
      Returns:
      this formatter for chaining
    • setShowTableEffect

      public TSQLResolver2ResultFormatter setShowTableEffect(boolean showTableEffect)
      Set whether to include table effect type in output. When true, tables will be displayed as tableName(effectType) where effectType indicates how the table is used (e.g., effectInsert, effectUpdate, effectSelect).
      Parameters:
      showTableEffect - true to include table effect
      Returns:
      this formatter for chaining
    • setShowColumnLocation

      public TSQLResolver2ResultFormatter setShowColumnLocation(boolean showColumnLocation)
      Set whether to include column location/clause in output. When true, columns will be displayed as columnName(location) where location indicates the SQL clause where the column appears (e.g., selectList, where, groupBy).
      Parameters:
      showColumnLocation - true to include column location
      Returns:
      this formatter for chaining
    • setOnlyPhysicalTables

      public TSQLResolver2ResultFormatter setOnlyPhysicalTables(boolean onlyPhysicalTables)
      Set whether to only include physical/base tables in output. When true, excludes PL/SQL record variables, cursor variables, and other non-table sources. This makes output compatible with the old TGetTableColumn format.
      Parameters:
      onlyPhysicalTables - true to filter to physical tables only
      Returns:
      this formatter for chaining
    • setShowUnnest

      public TSQLResolver2ResultFormatter setShowUnnest(boolean showUnnest)
      Set whether to include UNNEST tables in output when onlyPhysicalTables=true. Default is true (UNNEST tables are always included).
      Parameters:
      showUnnest - true to include UNNEST tables
      Returns:
      this formatter for chaining
    • setShowPivotTable

      public TSQLResolver2ResultFormatter setShowPivotTable(boolean showPivotTable)
      Set whether to include PIVOT tables in output when onlyPhysicalTables=true. Default is true (PIVOT tables are always included).
      Parameters:
      showPivotTable - true to include PIVOT tables
      Returns:
      this formatter for chaining
    • setShowLateralView

      public TSQLResolver2ResultFormatter setShowLateralView(boolean showLateralView)
      Set whether to include LATERAL VIEW tables in output when onlyPhysicalTables=true. Default is true (LATERAL VIEW tables are always included).
      Parameters:
      showLateralView - true to include LATERAL VIEW tables
      Returns:
      this formatter for chaining
    • setLinkOrphanColumnToFirstTable

      public TSQLResolver2ResultFormatter setLinkOrphanColumnToFirstTable(boolean linkOrphanColumnToFirstTable)
      Set whether orphan columns should be linked to the first candidate table. When true (default), orphan columns (columns that cannot be definitively linked to a single table) will be linked to the first candidate table. When false, orphan columns will use "missed" as their table prefix.
      Parameters:
      linkOrphanColumnToFirstTable - true to use first candidate, false to use "missed"
      Returns:
      this formatter for chaining
    • isShowCTE

      public boolean isShowCTE()
    • isShowDatatype

      public boolean isShowDatatype()
    • isShowColumnsOfCTE

      public boolean isShowColumnsOfCTE()
    • isOnlyPhysicalTables

      public boolean isOnlyPhysicalTables()
    • isShowUnnest

      public boolean isShowUnnest()
    • isShowPivotTable

      public boolean isShowPivotTable()
    • isShowLateralView

      public boolean isShowLateralView()
    • isListStarColumn

      public boolean isListStarColumn()
    • isLinkOrphanColumnToFirstTable

    • isShowTableEffect

      public boolean isShowTableEffect()
    • isShowColumnLocation

      public boolean isShowColumnLocation()
    • getResolutionResult

      Get the resolution result interface for statement-centric access. This provides a clean API for programmatically accessing resolution results.

      Usage example:

       IResolutionResult result = formatter.getResolutionResult();
       for (TCustomSqlStatement stmt : parser.sqlstatements) {
           for (TTable table : result.getTables(stmt)) {
               System.out.println("Table: " + table.getFullName());
               for (TObjectName col : result.getColumnsForTable(stmt, table)) {
                   System.out.println("  Column: " + col.getColumnNameOnly());
               }
           }
       }
       
      Returns:
      The resolution result interface, or null if resolver has not been called
    • format

      public String format()
      Format the resolver results into a structured string.
      Returns:
      Formatted string with Tables, Fields, and optionally Ctes sections
    • getTables

      public Set<String> getTables()
      Get the list of tables found in the statements.
      Returns:
      Set of table names in sorted order
    • getFields

      public Set<String> getFields()
      Get the list of fields (table.column) found in the statements.
      Returns:
      Set of field names in sorted order
    • create

      Create a formatter with default settings.
    • createWithCTE

      Create a formatter configured to show CTE tables and columns.
    • createWithDatatype

      Create a formatter configured to show datatypes.
    • createWithCTEColumns

      Create a formatter configured to show CTE column definitions.
    • getDesiredTablesColumns

      public static String getDesiredTablesColumns(String filePath)
      Read the expected output from a file. Utility method for tests to load expected results.