Class AbstractNamespace

Object
gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
All Implemented Interfaces:
INamespace
Direct Known Subclasses:
CTENamespace, DynamicStarSource, PivotNamespace, SubqueryNamespace, TableNamespace, UnionNamespace, UnnestNamespace, ValuesNamespace

public abstract class AbstractNamespace extends Object implements INamespace
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 Details

    • node

      protected final Object node
      Associated AST node
    • validated

      protected boolean 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

      protected boolean referenceTraceabilityEnabled
      Whether reference traceability is enabled
    • nameMatcher

      protected final INameMatcher nameMatcher
      Name matcher for column name comparisons
    • guessColumnStrategy

      protected int 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

  • Method Details

    • setGuessColumnStrategy

      public void setGuessColumnStrategy(int strategy)
      Set the strategy for handling ambiguous columns.
      Parameters:
      strategy - One of TBaseType.GUESS_COLUMN_STRATEGY_* constants, or -1 to use global default
    • getGuessColumnStrategy

      public int 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

      public Object getNode()
      Description copied from interface: INamespace
      Get the associated AST node (TTable, TSelectSqlStatement, etc.)
      Specified by:
      getNode in interface INamespace
      Returns:
      AST node, or null if not applicable
    • isValidated

      public boolean isValidated()
      Description copied from interface: INamespace
      Check if this namespace is validated/resolved. Some namespaces require resolution before they can provide column info.
      Specified by:
      isValidated in interface INamespace
      Returns:
      true if validated
    • validate

      public void validate()
      Description copied from interface: INamespace
      Validate/resolve this namespace. For subqueries: resolve the SELECT list For tables: load metadata if needed
      Specified by:
      validate in interface INamespace
    • doValidate

      protected abstract void 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

      protected void addColumnSource(String columnName, ColumnSource source, TObjectName objectName)
      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 source
      objectName - the original AST node for traceability (may be null)
    • addColumnSource

      protected void addColumnSource(String columnName, ColumnSource source)
      Add a column source (backward compatible - no traceability).
      Parameters:
      columnName - original column name
      source - the column source
    • hasColumn

      public ColumnLevel hasColumn(String columnName)
      Description copied from interface: INamespace
      Check if a column exists in this namespace. Returns a three-level answer: EXISTS, MAYBE, NOT_EXISTS
      Specified by:
      hasColumn in interface INamespace
      Parameters:
      columnName - Column name to check
      Returns:
      Column existence level
    • resolveColumn

      public ColumnSource resolveColumn(String columnName)
      Description copied from interface: INamespace
      Resolve a column name to its source.
      Specified by:
      resolveColumn in interface INamespace
      Parameters:
      columnName - Column name to resolve
      Returns:
      ColumnSource if found, null otherwise
    • getAllColumnSources

      Description copied from interface: INamespace
      Get all column sources exposed by this namespace. Used for SELECT * expansion and smart completion.
      Specified by:
      getAllColumnSources in interface INamespace
      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: INamespace
      Get 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:
      getAllFinalTables in interface INamespace
      Returns:
      List of all physical tables
    • ensureValidated

      protected void ensureValidated()
      Ensure this namespace is validated before accessing column info
    • getNameMatcher

      Get the name matcher used by this namespace.
      Returns:
      the name matcher
    • toString

      public String toString()
      Overrides:
      toString in class Object