Class AbstractNamespace
Object
gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
- All Implemented Interfaces:
INamespace
- Direct Known Subclasses:
CTENamespace,DynamicStarSource,PivotNamespace,SubqueryNamespace,TableNamespace,UnionNamespace,UnnestNamespace,ValuesNamespace
Abstract base class for all namespaces.
Provides common functionality for column resolution and caching.
Enhanced with reference traceability support: multiple syntactically different identifiers that refer to the same semantic column can be tracked and traced back.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map<String,ColumnSource> Cached column sources (populated during validation) - keyed by normalized nameprotected Map<String,ColumnSourceWithReferences> Enhanced column sources with reference traceability (keyed by normalized name).protected intStrategy for handling ambiguous columns.protected final INameMatcherName matcher for column name comparisonsprotected final ObjectAssociated AST nodeprotected booleanWhether reference traceability is enabledprotected booleanWhether this namespace has been validated -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractNamespace(Object node) protectedAbstractNamespace(Object node, INameMatcher nameMatcher) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddColumnSource(String columnName, ColumnSource source) Add a column source (backward compatible - no traceability).protected voidaddColumnSource(String columnName, ColumnSource source, TObjectName objectName) Add a column source with reference traceability support.protected abstract voidSubclasses override this to perform actual validation logic.voidEnable reference traceability for this namespace.protected voidEnsure this namespace is validated before accessing column infoGet all column sources exposed by this namespace.Get all final physical tables this namespace depends on.Get all unique columns with their references.getColumnReferences(String columnName) Get all column references for a specific column.getColumnSourceWithReferences(String columnName) Get enhanced column source with references for a specific column.intGet the strategy for handling ambiguous columns.Get the name matcher used by this namespace.getNode()Get the associated AST node (TTable, TSelectSqlStatement, etc.)Check if a column exists in this namespace.booleanCheck if reference traceability is enabled.booleanCheck if this namespace is validated/resolved.resolveColumn(String columnName) Resolve a column name to its source.voidsetGuessColumnStrategy(int strategy) Set the strategy for handling ambiguous columns.toString()voidvalidate()Validate/resolve this namespace.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface gudusoft.gsqlparser.resolver2.namespace.INamespace
addInferredColumn, getDisplayName, getFinalTable, getInferredColumns, getSelectStatement, getSourceTable, getStarColumn, hasStarColumn, resolveColumnPath, supportsDynamicInference
-
Field Details
-
node
Associated AST node -
validated
Whether this namespace has been validated -
columnSources
Cached column sources (populated during validation) - keyed by normalized name -
columnSourcesWithRefs
Enhanced column sources with reference traceability (keyed by normalized name). When enabled, this map stores ColumnSourceWithReferences that track all original references to each semantic column. -
referenceTraceabilityEnabled
Whether reference traceability is enabled -
nameMatcher
Name matcher for column name comparisons -
guessColumnStrategy
Strategy for handling ambiguous columns. Defaults to -1, which means use global TBaseType.GUESS_COLUMN_STRATEGY. Can be overridden per-namespace instance.
-
-
Constructor Details
-
AbstractNamespace
-
AbstractNamespace
-
-
Method Details
-
setGuessColumnStrategy
Set the strategy for handling ambiguous columns.- Parameters:
strategy- One of TBaseType.GUESS_COLUMN_STRATEGY_* constants, or -1 to use global default
-
getGuessColumnStrategy
Get the strategy for handling ambiguous columns. Returns the instance-level strategy if set, otherwise returns the global default.- Returns:
- The strategy constant
-
getNode
Description copied from interface:INamespaceGet the associated AST node (TTable, TSelectSqlStatement, etc.)- Specified by:
getNodein interfaceINamespace- Returns:
- AST node, or null if not applicable
-
isValidated
Description copied from interface:INamespaceCheck if this namespace is validated/resolved. Some namespaces require resolution before they can provide column info.- Specified by:
isValidatedin interfaceINamespace- Returns:
- true if validated
-
validate
Description copied from interface:INamespaceValidate/resolve this namespace. For subqueries: resolve the SELECT list For tables: load metadata if needed- Specified by:
validatein interfaceINamespace
-
doValidate
Subclasses override this to perform actual validation logic. -
enableReferenceTraceability
Enable reference traceability for this namespace. When enabled, all column additions will track original references. -
isReferenceTraceabilityEnabled
Check if reference traceability is enabled.- Returns:
- true if traceability is enabled
-
addColumnSource
Add a column source with reference traceability support.This method normalizes the column name and either:
- Creates a new entry if this is the first reference
- Adds a reference to an existing entry if the column already exists
- Parameters:
columnName- original column name (may include quotes)source- the column sourceobjectName- the original AST node for traceability (may be null)
-
addColumnSource
Add a column source (backward compatible - no traceability).- Parameters:
columnName- original column namesource- the column source
-
hasColumn
Description copied from interface:INamespaceCheck if a column exists in this namespace. Returns a three-level answer: EXISTS, MAYBE, NOT_EXISTS- Specified by:
hasColumnin interfaceINamespace- Parameters:
columnName- Column name to check- Returns:
- Column existence level
-
resolveColumn
Description copied from interface:INamespaceResolve a column name to its source.- Specified by:
resolveColumnin interfaceINamespace- Parameters:
columnName- Column name to resolve- Returns:
- ColumnSource if found, null otherwise
-
getAllColumnSources
Description copied from interface:INamespaceGet all column sources exposed by this namespace. Used for SELECT * expansion and smart completion.- Specified by:
getAllColumnSourcesin interfaceINamespace- Returns:
- Map of column name -> ColumnSource
-
getColumnReferences
Get all column references for a specific column.Requires reference traceability to be enabled.
- Parameters:
columnName- the column name (normalized or original)- Returns:
- list of all references, empty if not found or traceability not enabled
-
getAllUniqueColumns
Get all unique columns with their references.Requires reference traceability to be enabled.
- Returns:
- collection of enhanced column sources, empty if traceability not enabled
-
getColumnSourceWithReferences
Get enhanced column source with references for a specific column.- Parameters:
columnName- the column name- Returns:
- enhanced column source, or null if not found
-
getAllFinalTables
Description copied from interface:INamespaceGet all final physical tables this namespace depends on. For simple table namespace: returns single table For subquery/CTE: returns all tables in the query tree- Specified by:
getAllFinalTablesin interfaceINamespace- Returns:
- List of all physical tables
-
ensureValidated
Ensure this namespace is validated before accessing column info -
getNameMatcher
Get the name matcher used by this namespace.- Returns:
- the name matcher
-
toString
-