Object
org.apache.spark.sql.connector.catalog.View
All Implemented Interfaces:
Relation

@Evolving public class View extends Object implements Relation
A view in a catalog -- the typed payload returned by ViewCatalog.loadView(org.apache.spark.sql.connector.catalog.Identifier) and accepted by ViewCatalog.createView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View) / ViewCatalog.replaceView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View). A View carries the view-specific fields that cannot be represented as string table properties: the query text, captured creation-time resolution context, captured SQL configs, schema-binding mode, and query output column names. Columns and user TBLPROPERTIES are set via the typed builder.

Unlike a Table, a View is itself a Relation rather than something Spark realizes into a Table: Spark expands the view's query text at read time and never builds a view object. A RelationCatalog returns a View directly from RelationCatalog.loadRelation(org.apache.spark.sql.connector.catalog.Identifier) for a view identifier, so it never has to smuggle a view through the Table surface.

Since:
4.2.0
  • Method Details

    • columns

      public Column[] columns()
      Description copied from interface: Relation
      The columns of this relation.
      Specified by:
      columns in interface Relation
    • schema

      public StructType schema()
    • properties

      public Map<String,String> properties()
      Description copied from interface: Relation
      The string map of properties of this relation.
      Specified by:
      properties in interface Relation
    • queryText

      public String queryText()
      The SQL text of the view.
    • currentCatalog

      public String currentCatalog()
      The current catalog at the time the view was created, used to resolve unqualified identifiers in queryText() at read time. May be null if the view was created with no captured resolution context.
    • currentNamespace

      public String[] currentNamespace()
      The current namespace at the time the view was created, used alongside currentCatalog() to resolve unqualified identifiers in queryText() at read time. Never null; empty when no namespace was captured.
    • sqlConfigs

      public Map<String,String> sqlConfigs()
      The SQL configs captured at view creation time, applied when parsing and analyzing the view body. Keys are unprefixed SQL config names (e.g. spark.sql.ansi.enabled).
    • schemaMode

      public String schemaMode()
      The view's schema binding mode. Allowed values match the toString form of org.apache.spark.sql.catalyst.analysis.ViewSchemaMode: BINDING, COMPENSATION, TYPE EVOLUTION, EVOLUTION. May be null when schema binding is not configured.
    • queryColumnNames

      public String[] queryColumnNames()
      Output column names of the query that created the view, used to map the query output to the view's declared columns during view resolution. Empty for views in EVOLUTION mode, which always use the view's current schema.
    • viewDependencies

      public DependencyList viewDependencies()
      Returns the structured list of objects this view depends on (source tables and functions), or null if no dependency list was supplied. Unlike other view metadata which is encoded into properties(), dependency lists are a first-class field because their nested structure does not round-trip cleanly through flat string properties.