Class SubqueryNamespace

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

Namespace representing a subquery. Provides columns from the subquery's SELECT list. Example: FROM (SELECT id, name FROM users) AS t ^^^^^^^^^^^^^^^^^^^^^^^^ SubqueryNamespace exposes columns: id, name
  • Constructor Details

  • Method Details

    • isFromTableFunction

      public boolean isFromTableFunction()
      Returns true if this namespace was created from a TABLE function's subquery.
    • setSourceTable

      public void setSourceTable(TTable sourceTable)
      Set the TTable that wraps this subquery. Used by ScopeBuilder for legacy sync support.
      Parameters:
      sourceTable - the TTable that contains this subquery
    • getSourceTable

      Description copied from interface: INamespace
      Get the TTable that this namespace is associated with. Used for legacy sync to set TObjectName.sourceTable. For TableNamespace: returns the table itself For SubqueryNamespace: returns the TTable wrapping the subquery For CTENamespace: returns the CTE referencing table For others: returns null
      Returns:
      The source TTable, or null if not applicable
    • setSqlEnv

      public void setSqlEnv(TSQLEnv sqlEnv)
      Set the TSQLEnv for metadata lookup. Used when resolving star columns to find which columns exist in underlying tables.
      Parameters:
      sqlEnv - the SQL environment containing table metadata
    • getSqlEnv

      public TSQLEnv getSqlEnv()
      Get the TSQLEnv used for metadata lookup.
      Returns:
      the SQL environment, or null if not set
    • getDisplayName

      Description copied from interface: INamespace
      Get a display name for this namespace (for debugging/error messages)
    • 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
    • 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
      Overrides:
      getAllFinalTables in class AbstractNamespace
      Returns:
      List of all physical tables
    • 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
    • getSubquery

    • getSelectStatement

      Description copied from interface: INamespace
      Get the underlying SELECT statement for this namespace. For CTENamespace: returns the CTE's subquery For SubqueryNamespace: returns the subquery For TableNamespace: returns null
      Returns:
      the SELECT statement, or null if not applicable
    • 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
    • getStarColumn

      Get the first star column (TResultColumn) from this subquery's SELECT list. Used to track the definition node for columns inferred from the star.
      Returns:
      The star column, or null if no star column exists
    • hasAmbiguousStar

      public boolean hasAmbiguousStar()
      Check if this subquery has an unqualified star with multiple tables. In this case, columns are ambiguous and should NOT be auto-resolved. Example: SELECT * FROM table_a, table_c -- ambiguous, columns could come from either table SELECT ta.* FROM table_a ta, table_c tc -- NOT ambiguous, star is qualified SELECT * FROM table_a JOIN table_c ON ... -- ambiguous, columns from both tables Uses getRelations() and TJoinExpr to properly count tables in JOINs.
    • 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
    • addInferredColumn

      public boolean addInferredColumn(String columnName, double confidence, String evidence)
      Description copied from interface: INamespace
      Add an inferred column to this namespace. Used by star column push-down to add columns discovered from outer queries.
      Parameters:
      columnName - the column name to add
      confidence - the confidence score (0.0 to 1.0)
      evidence - description of why this column was inferred
      Returns:
      true if the column was added, false if already exists
    • 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
    • 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
    • resolveColumnInFromScope

      Resolve a column in the FROM scope (child namespaces). This finds where a column originates from in the FROM clause tables/subqueries.

      Unlike resolveColumn() which returns columns from THIS subquery's SELECT list, this method looks into the FROM clause to find the underlying definition.

      IMPORTANT: For TableNamespace, this only returns columns that exist in actual metadata (from DDL or SQLEnv). It does NOT use inferred columns. This is critical for multi-table star resolution where we need to know which table actually has the column based on metadata, not inference.

      Parameters:
      columnName - The column name to find
      Returns:
      ColumnSource from the FROM clause, or null if not found
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNamespace