Class UnnestNamespace

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

public class UnnestNamespace extends AbstractNamespace
Namespace representing an UNNEST table expression in BigQuery. UNNEST flattens an array into rows. For example: - UNNEST(['a', 'b', 'c']) creates a virtual table with rows 'a', 'b', 'c' - SELECT value FROM UNNEST(array_column) - 'value' is an implicit column name The UNNEST namespace provides: 1. An implicit column for the unnested elements (named by alias or 'value') 2. Support for WITH OFFSET which adds an 'offset' column 3. Support for STRUCT arrays which expose struct field names
  • Constructor Details

  • Method Details

    • 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
    • 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
    • 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
    • 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
    • resolveQualifiedStructField

      Resolve a qualified struct field reference (e.g., "alias.field"). This method infers struct fields when no metadata is available.

      Use this method when resolving qualified column references like "x.field" where "x" is the UNNEST alias. This is appropriate for UNNEST of STRUCT arrays where the struct fields are accessed via the alias.

      For unqualified column references, use resolveColumn(String) which does NOT infer columns and returns null for unknown columns.

      Parameters:
      columnName - the column/field name (without the table qualifier)
      Returns:
      ColumnSource for the inferred struct field
    • getArrayExpression

      Get the array expression being unnested. This is used to track the source of the unnested data.
    • getImplicitColumnName

      Get the implicit column name for the unnested elements.
    • getOffsetColumnName

      Get the offset column name if WITH OFFSET is present.
    • getUnnestTable

    • getSourceTable

      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 For UnnestNamespace, returns the TTable representing the UNNEST expression. This is the immediate source table for columns resolved through this UNNEST.
      Returns:
      The source TTable, or null if not applicable
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNamespace