Class TSQLResolver2ResultFormatter
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.
- Name resolution logic: Must be implemented in
TSQLResolver2,ScopeBuilder, andNameResolver - Formatting logic: Implemented in this class (
TSQLResolver2ResultFormatter)
Violating this principle will cause:
- Users directly using the
TSQLResolver2API 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:
setShowCTE(boolean)- Include CTE tables in outputsetOnlyPhysicalTables(boolean)- Filter to physical tables onlysetShowUnnest(boolean)- Include UNNEST tables when onlyPhysicalTables=truesetShowPivotTable(boolean)- Include PIVOT tables when onlyPhysicalTables=truesetShowLateralView(boolean)- Include LATERAL VIEW tables when onlyPhysicalTables=truesetShowDatatype(boolean)- Include column datatypessetShowColumnLocation(boolean)- Include SQL clause locationsetShowTableEffect(boolean)- Include table effect type
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 Summary
ConstructorsConstructorDescriptionTSQLResolver2ResultFormatter(TSQLResolver2 resolver) Create a formatter for the given resolver.TSQLResolver2ResultFormatter(TSQLResolver2 resolver, TSQLResolverConfig config) Create a formatter with a specific configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic TSQLResolver2ResultFormattercreate(TSQLResolver2 resolver) Create a formatter with default settings.static TSQLResolver2ResultFormattercreateWithCTE(TSQLResolver2 resolver) Create a formatter configured to show CTE tables and columns.static TSQLResolver2ResultFormattercreateWithCTEColumns(TSQLResolver2 resolver) Create a formatter configured to show CTE column definitions.static TSQLResolver2ResultFormattercreateWithDatatype(TSQLResolver2 resolver) Create a formatter configured to show datatypes.format()Format the resolver results into a structured string.static StringgetDesiredTablesColumns(String filePath) Read the expected output from a file.Get the current display name mode.Get the list of fields (table.column) found in the statements.Get the resolution result interface for statement-centric access.Get the list of tables found in the statements.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanSet the display name mode for identifier formatting.setLinkOrphanColumnToFirstTable(boolean linkOrphanColumnToFirstTable) Set whether orphan columns should be linked to the first candidate table.setListStarColumn(boolean listStarColumn) setOnlyPhysicalTables(boolean onlyPhysicalTables) Set whether to only include physical/base tables in output.setShowColumnLocation(boolean showColumnLocation) Set whether to include column location/clause in output.setShowColumnsOfCTE(boolean showColumnsOfCTE) setShowCTE(boolean showCTE) setShowDatatype(boolean showDatatype) setShowLateralView(boolean showLateralView) Set whether to include LATERAL VIEW tables in output when onlyPhysicalTables=true.setShowPivotTable(boolean showPivotTable) Set whether to include PIVOT tables in output when onlyPhysicalTables=true.setShowTableEffect(boolean showTableEffect) Set whether to include table effect type in output.setShowUnnest(boolean showUnnest) Set whether to include UNNEST tables in output when onlyPhysicalTables=true.
-
Constructor Details
-
TSQLResolver2ResultFormatter
Create a formatter for the given resolver.- Parameters:
resolver- The TSQLResolver2 instance (must have called resolve())
-
TSQLResolver2ResultFormatter
Create a formatter with a specific configuration.- Parameters:
resolver- The TSQLResolver2 instanceconfig- Configuration to apply
-
-
Method Details
-
setShowCTE
-
setShowDatatype
-
setShowColumnsOfCTE
-
setListStarColumn
-
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:
DisplayNameMode.DISPLAY- Strip delimiters, preserve original case (e.g.,[OrderID]→OrderID)DisplayNameMode.SQL_RENDER- Preserve delimiters for valid SQL regeneration (e.g.,[Order ID]→[Order ID])DisplayNameMode.CANONICAL- Apply vendor-specific case folding (e.g., Oracle:MyTable→MYTABLE)
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
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
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
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
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
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
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
-
isShowDatatype
-
isShowColumnsOfCTE
-
isOnlyPhysicalTables
-
isShowUnnest
-
isShowPivotTable
-
isShowLateralView
-
isListStarColumn
-
isLinkOrphanColumnToFirstTable
-
isShowTableEffect
-
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
Format the resolver results into a structured string.- Returns:
- Formatted string with Tables, Fields, and optionally Ctes sections
-
getTables
Get the list of tables found in the statements.- Returns:
- Set of table names in sorted order
-
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
Read the expected output from a file. Utility method for tests to load expected results.
-