public class TSQLResolver2ResultFormatter extends Object
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.
Key Principle: TSQLResolver2ResultFormatter is only responsible for
formatting output, NOT for name resolution.
TSQLResolver2,
ScopeBuilder, and NameResolverTSQLResolver2ResultFormatter)Violating this principle will cause:
TSQLResolver2 API will not get correct resolution resultsThis 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.
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
TSQLResolver2 resolver = new TSQLResolver2(env, statements, config);
resolver.resolve();
TSQLResolver2ResultFormatter formatter = new TSQLResolver2ResultFormatter(resolver);
formatter.setShowCTE(true);
formatter.setShowDatatype(true);
String result = formatter.format();
TSQLResolver2,
ScopeBuilder,
NameResolver,
TGetTableColumn| Constructor and Description |
|---|
TSQLResolver2ResultFormatter(TSQLResolver2 resolver)
Create a formatter for the given resolver.
|
TSQLResolver2ResultFormatter(TSQLResolver2 resolver,
TSQLResolverConfig config)
Create a formatter with a specific configuration.
|
| Modifier and Type | Method and Description |
|---|---|
static TSQLResolver2ResultFormatter |
create(TSQLResolver2 resolver)
Create a formatter with default settings.
|
static TSQLResolver2ResultFormatter |
createWithCTE(TSQLResolver2 resolver)
Create a formatter configured to show CTE tables and columns.
|
static TSQLResolver2ResultFormatter |
createWithCTEColumns(TSQLResolver2 resolver)
Create a formatter configured to show CTE column definitions.
|
static TSQLResolver2ResultFormatter |
createWithDatatype(TSQLResolver2 resolver)
Create a formatter configured to show datatypes.
|
String |
format()
Format the resolver results into a structured string.
|
static String |
getDesiredTablesColumns(String filePath)
Read the expected output from a file.
|
DisplayNameMode |
getDisplayNameMode()
Get the current display name mode.
|
Set<String> |
getFields()
Get the list of fields (table.column) found in the statements.
|
IResolutionResult |
getResolutionResult()
Get the resolution result interface for statement-centric access.
|
Set<String> |
getTables()
Get the list of tables found in the statements.
|
boolean |
isLinkOrphanColumnToFirstTable() |
boolean |
isListStarColumn() |
boolean |
isOnlyPhysicalTables() |
boolean |
isShowColumnLocation() |
boolean |
isShowColumnsOfCTE() |
boolean |
isShowCTE() |
boolean |
isShowDatatype() |
boolean |
isShowLateralView() |
boolean |
isShowPivotTable() |
boolean |
isShowTableEffect() |
boolean |
isShowUnnest() |
TSQLResolver2ResultFormatter |
setDisplayNameMode(DisplayNameMode mode)
Set the display name mode for identifier formatting.
|
TSQLResolver2ResultFormatter |
setLinkOrphanColumnToFirstTable(boolean linkOrphanColumnToFirstTable)
Set whether orphan columns should be linked to the first candidate table.
|
TSQLResolver2ResultFormatter |
setListStarColumn(boolean listStarColumn) |
TSQLResolver2ResultFormatter |
setOnlyPhysicalTables(boolean onlyPhysicalTables)
Set whether to only include physical/base tables in output.
|
TSQLResolver2ResultFormatter |
setShowColumnLocation(boolean showColumnLocation)
Set whether to include column location/clause in output.
|
TSQLResolver2ResultFormatter |
setShowColumnsOfCTE(boolean showColumnsOfCTE) |
TSQLResolver2ResultFormatter |
setShowCTE(boolean showCTE) |
TSQLResolver2ResultFormatter |
setShowDatatype(boolean showDatatype) |
TSQLResolver2ResultFormatter |
setShowLateralView(boolean showLateralView)
Set whether to include LATERAL VIEW tables in output when onlyPhysicalTables=true.
|
TSQLResolver2ResultFormatter |
setShowPivotTable(boolean showPivotTable)
Set whether to include PIVOT tables in output when onlyPhysicalTables=true.
|
TSQLResolver2ResultFormatter |
setShowTableEffect(boolean showTableEffect)
Set whether to include table effect type in output.
|
TSQLResolver2ResultFormatter |
setShowUnnest(boolean showUnnest)
Set whether to include UNNEST tables in output when onlyPhysicalTables=true.
|
public TSQLResolver2ResultFormatter(TSQLResolver2 resolver)
resolver - The TSQLResolver2 instance (must have called resolve())public TSQLResolver2ResultFormatter(TSQLResolver2 resolver, TSQLResolverConfig config)
resolver - The TSQLResolver2 instanceconfig - Configuration to applypublic TSQLResolver2ResultFormatter setShowCTE(boolean showCTE)
public TSQLResolver2ResultFormatter setShowDatatype(boolean showDatatype)
public TSQLResolver2ResultFormatter setShowColumnsOfCTE(boolean showColumnsOfCTE)
public TSQLResolver2ResultFormatter setListStarColumn(boolean listStarColumn)
public DisplayNameMode getDisplayNameMode()
public TSQLResolver2ResultFormatter setDisplayNameMode(DisplayNameMode mode)
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.
mode - the DisplayNameMode to usepublic TSQLResolver2ResultFormatter setShowTableEffect(boolean showTableEffect)
showTableEffect - true to include table effectpublic TSQLResolver2ResultFormatter setShowColumnLocation(boolean showColumnLocation)
showColumnLocation - true to include column locationpublic TSQLResolver2ResultFormatter setOnlyPhysicalTables(boolean onlyPhysicalTables)
onlyPhysicalTables - true to filter to physical tables onlypublic TSQLResolver2ResultFormatter setShowUnnest(boolean showUnnest)
showUnnest - true to include UNNEST tablespublic TSQLResolver2ResultFormatter setShowPivotTable(boolean showPivotTable)
showPivotTable - true to include PIVOT tablespublic TSQLResolver2ResultFormatter setShowLateralView(boolean showLateralView)
showLateralView - true to include LATERAL VIEW tablespublic TSQLResolver2ResultFormatter setLinkOrphanColumnToFirstTable(boolean linkOrphanColumnToFirstTable)
linkOrphanColumnToFirstTable - true to use first candidate, false to use "missed"public boolean isShowCTE()
public boolean isShowDatatype()
public boolean isShowColumnsOfCTE()
public boolean isOnlyPhysicalTables()
public boolean isShowUnnest()
public boolean isShowPivotTable()
public boolean isShowLateralView()
public boolean isListStarColumn()
public boolean isLinkOrphanColumnToFirstTable()
public boolean isShowTableEffect()
public boolean isShowColumnLocation()
public IResolutionResult getResolutionResult()
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());
}
}
}
public String format()
public Set<String> getTables()
public Set<String> getFields()
public static TSQLResolver2ResultFormatter create(TSQLResolver2 resolver)
public static TSQLResolver2ResultFormatter createWithCTE(TSQLResolver2 resolver)
public static TSQLResolver2ResultFormatter createWithDatatype(TSQLResolver2 resolver)
public static TSQLResolver2ResultFormatter createWithCTEColumns(TSQLResolver2 resolver)
public static String getDesiredTablesColumns(String filePath)