Class DynamicStarSource

Object
gudusoft.gsqlparser.resolver2.namespace.AbstractNamespace
gudusoft.gsqlparser.resolver2.namespace.DynamicStarSource
All Implemented Interfaces:
INamespace

Dynamic namespace for handling SELECT * without metadata.

This namespace represents a table or subquery where we have SELECT * but no schema information. It dynamically infers columns based on: - Usage in WHERE clauses - Usage in JOIN conditions - Usage in other parts of the query

Example scenario:

 -- No metadata available for employees table
 SELECT * FROM employees e
 WHERE e.department_id = 10
   AND e.salary > 50000

 DynamicStarSource will infer:
 - "department_id" column (from WHERE clause)
 - "salary" column (from WHERE clause)
 

The inference is done lazily - columns are added as evidence is discovered during resolution. This allows the resolver to handle queries without schema information.

Confidence scoring: - Qualified references (t.col): High confidence (0.95) - JOIN conditions: Very high confidence (0.9) - Unqualified references: Lower confidence (0.5-0.8)

  • Constructor Details

  • Method Details

    • getInferenceEngine

      Get the inference engine for this star source. External code can add evidence to this engine.
      Returns:
      the inference engine
    • addInferredColumn

      public boolean addInferredColumn(String columnName, double confidence, String evidence)
      Add a dynamically inferred column.
      Parameters:
      columnName - the column name
      confidence - the confidence score
      evidence - the evidence description
      Returns:
      true if the column was added, false if it already exists
    • addInferredColumn

      public void addInferredColumn(String columnName, ColumnSource columnSource)
      Add a dynamically inferred column from an existing ColumnSource. This is used for reverse inference (Principle 3: Star Column双向处理).
      Parameters:
      columnName - the column name
      columnSource - the column source with confidence and evidence
    • inferColumnsFromEvidence

      public void inferColumnsFromEvidence()
      Infer columns from the inference engine's evidence. This should be called after all evidence has been collected.
    • doValidate

      protected void doValidate()
      Description copied from class: AbstractNamespace
      Subclasses override this to perform actual validation logic.
      Specified by:
      doValidate in class AbstractNamespace
    • 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
      Overrides:
      hasColumn in class AbstractNamespace
      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
      Overrides:
      resolveColumn in class AbstractNamespace
      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
      Overrides:
      getAllColumnSources in class AbstractNamespace
      Returns:
      Map of column name -> ColumnSource
    • getFinalTable

      Description copied from interface: INamespace
      Get the final physical table this namespace represents. For tables: returns the table itself For subqueries/CTEs: recursively traces back to physical table(s)
      Returns:
      Physical table, or null if not determinable
    • getDisplayName

      Description copied from interface: INamespace
      Get a display name for this namespace (for debugging/error messages)
    • getInferredColumnCount

      public int getInferredColumnCount()
      Get the number of dynamically inferred columns.
      Returns:
      column count
    • hasInferredColumns

      public boolean hasInferredColumns()
      Check if any columns have been inferred.
      Returns:
      true if columns were inferred, false otherwise
    • getStatistics

      Get statistics about this dynamic star source.
      Returns:
      statistics string
    • supportsDynamicInference

      public boolean supportsDynamicInference()
      Description copied from interface: INamespace
      Check if this namespace supports dynamic column inference. DynamicStarSource and similar namespaces return true.
      Returns:
      true if this namespace can have columns added dynamically
    • getInferredColumns

      Description copied from interface: INamespace
      Get all columns that were inferred (not from SELECT list directly). These are columns discovered through star column push-down.
      Returns:
      set of inferred column names, empty if none
    • hasStarColumn

      public boolean hasStarColumn()
      Description copied from interface: INamespace
      Check if this namespace contains a star column (SELECT *). Used to identify namespaces that may need star column inference.
      Returns:
      true if the namespace has SELECT *, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNamespace