public class DisplayNameNormalizer extends Object
This class provides display-focused normalization that is separate from the matching/equality normalization used during name resolution. The key principle is:
IdentifierService): applies case folding
and other transformations to create a canonical key for comparison
DisplayNameNormalizer normalizer = new DisplayNameNormalizer(EDbVendor.dbvbigquery);
normalizer.setMode(DisplayNameMode.DISPLAY);
// Strip backticks, preserve case
String display = normalizer.normalizeTableName("`kalyan-DB`.`test-schema`.`t1`");
// Result: "kalyan-DB.test-schema.t1"
DisplayNameMode,
DisplayNamePolicy| Constructor and Description |
|---|
DisplayNameNormalizer()
Create a normalizer with default vendor (ANSI).
|
DisplayNameNormalizer(EDbVendor vendor)
Create a normalizer for the specified database vendor.
|
| Modifier and Type | Method and Description |
|---|---|
DisplayNameMode |
getMode()
Get the current display mode.
|
SqlNameGenerator.QuotePolicy |
getQuotePolicy() |
String |
getTableDisplayName(TTable table)
Get a display name for a table, handling various TTable configurations.
|
boolean |
isStripDelimiters()
Check if delimiters should be stripped.
|
String |
normalizeColumnName(String columnName)
Normalize a column name for display.
|
String |
normalizeIdentifier(String identifier)
Normalize a single identifier (without dots) for display.
|
String |
normalizeIdentifier(String identifier,
ESQLDataObjectType objectType)
Normalize a single identifier (without dots) for display, stating its
syntactic role so delimiter rules come from the vendor profile.
|
String |
normalizeObjectName(TObjectName objectName)
Normalize an object name (table or column) for display.
|
String |
normalizeQualifiedName(String qualifiedName)
Normalize a qualified name (e.g., schema.table.column) for display.
|
String |
normalizeQualifiedName(String qualifiedName,
ESQLDataObjectType objectType)
Normalize a qualified name for display, stating the syntactic role of its
segments so delimiter rules come from the vendor profile.
|
String |
normalizeTableName(TTable table)
Normalize a table name for display.
|
DisplayNameNormalizer |
setMode(DisplayNameMode mode)
Set the display mode.
|
DisplayNameNormalizer |
setQuotePolicy(SqlNameGenerator.QuotePolicy quotePolicy)
Choose the spelling
DisplayNameMode.SQL_RENDER generates. |
DisplayNameNormalizer |
setStripDelimiters(boolean stripDelimiters)
Set whether to strip delimiters.
|
String |
stripAllDelimiters(String identifier) |
String |
stripAllDelimiters(String identifier,
ESQLDataObjectType objectType)
Strip SQL delimiters from an identifier, using the vendor's real quote rules.
|
String |
toString() |
public DisplayNameNormalizer(EDbVendor vendor)
vendor - the database vendor (determines delimiter style)public DisplayNameNormalizer()
public DisplayNameMode getMode()
public DisplayNameNormalizer setMode(DisplayNameMode mode)
mode - the display modepublic SqlNameGenerator.QuotePolicy getQuotePolicy()
public DisplayNameNormalizer setQuotePolicy(SqlNameGenerator.QuotePolicy quotePolicy)
DisplayNameMode.SQL_RENDER generates. "Valid SQL that names
this object" is a constraint, not a value: dbo and [dbo] both satisfy it.
This parameter is what makes the answer unique.
WHEN_NEEDED (default): delimit only where the bare word would be invalid,
would fold to another object, or is a keyword — dbo.SalesOrder,
[Order ID].ALWAYS: delimit every segment — [dbo].[SalesOrder].public boolean isStripDelimiters()
public DisplayNameNormalizer setStripDelimiters(boolean stripDelimiters)
stripDelimiters - true to strip delimiterspublic String normalizeTableName(TTable table)
table - the table objectpublic String normalizeObjectName(TObjectName objectName)
objectName - the object name nodepublic String normalizeColumnName(String columnName)
columnName - the column name (may include table prefix)public String normalizeQualifiedName(String qualifiedName)
This method handles multi-part names by normalizing each segment separately while preserving the dot separators.
qualifiedName - the qualified namepublic String normalizeQualifiedName(String qualifiedName, ESQLDataObjectType objectType)
Every segment is decoded with the same objectType, which is what
this class has always done. Per-segment role typing (catalog / schema / leaf)
is a separate change: it would alter output for vendors whose quote rules
differ by role, so it needs its own measurement.
qualifiedName - the qualified nameobjectType - syntactic role of the identifier segmentspublic String normalizeIdentifier(String identifier)
identifier - the identifierpublic String normalizeIdentifier(String identifier, ESQLDataObjectType objectType)
identifier - the identifierobjectType - syntactic role of the identifierpublic String stripAllDelimiters(String identifier)
public String stripAllDelimiters(String identifier, ESQLDataObjectType objectType)
The decision of what counts as a delimiter belongs to the unified name
service, not to the display layer, so this delegates to
IdentifierCodec.decodeLexical(gudusoft.gsqlparser.sqlenv.IdentifierProfile, gudusoft.gsqlparser.sqlenv.ESQLDataObjectType, java.lang.String). Two display-specific rules are layered
on top of it, and both exist to keep output byte-identical to the behavior
this class had before it delegated:
decodeLexical throws
MalformedIdentifierException for input such as "unclosed.
A display layer must not abort a whole Tables/Fields listing because one
name is malformed, so a throw falls through to the legacy strip.decodeLexical decodes
"", [] and '' to the empty string. Rendering a
column as nothing is worse than rendering its raw spelling, so an empty
decode falls through as well.Known gap, deliberately preserved. The legacy fallback also strips delimiters the vendor does not own (backticks for Oracle, brackets for MySQL, single quotes for everyone). Routing those through the profile instead would be the semantically correct behavior, but it changes output for 14 of 15 vendors measured, so it is a separate decision with its own golden review — not something to slip in under a refactor.
identifier - the identifier (may be quoted)objectType - syntactic role of the identifier (quote rules can depend on it)public String getTableDisplayName(TTable table)
table - the table