You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2026/06/23 03:48:33 UTC
(spark) branch branch-4.x updated: [SPARK-52729][SQL][FOLLOWUP] Model table and view as a common Relation
This is an automated email from the ASF dual-hosted git repository.
cloud-fan pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 4f7aa0283344 [SPARK-52729][SQL][FOLLOWUP] Model table and view as a common Relation
4f7aa0283344 is described below
commit 4f7aa0283344c9a7f373c8969c2d1d68b68aa39d
Author: Wenchen Fan <we...@databricks.com>
AuthorDate: Mon Jun 22 20:48:07 2026 -0700
[SPARK-52729][SQL][FOLLOWUP] Model table and view as a common Relation
### What changes were proposed in this pull request?
This is a follow-up of #52729 (which introduced `ViewInfo extends TableInfo`).
`ViewInfo IS-A TableInfo` was never a true relationship -- a view is not a table -- and it
forced table-only state (`partitions()`/`constraints()`, `withPartitions`/`withConstraints`/
`withProvider`/`withLocation`) onto the view surface. It also led `MetadataTable` to do double
duty: a delegating table *and* a carrier that smuggled a view through the `Table` interface.
This PR models a table and a view as the two kinds of a new `Relation` type, mirroring Postgres
`pg_class` + `relkind`:
```
interface Relation // columns(), properties()
Table (existing, now `extends Relation`) -- an object Spark reads from / writes to
View (renamed from ViewInfo) -- metadata; Spark expands its query text
```
The two kinds are deliberately asymmetric, matching how Spark treats them:
- A view has no object form (Spark never builds one), so its info *is* the relation:
`ViewInfo` is renamed to `View` and `implements Relation`. `V1ViewInfo` -> `V1View`.
- A table is realized from metadata: `TableInfo` stays metadata-only and is adapted into a
`Table` by `DelegatingTable` (renamed from `MetadataTable`, now table-only -- it never carries
a view). A catalog with its own `Table` object returns that instead.
- `RelationInfo` is dropped; the shared builder logic lives in a package-private
`RelationBuilder` base.
Catalog API:
- `TableViewCatalog` -> `RelationCatalog`, and `loadTableOrView` -> `loadRelation(Identifier):
Relation`. The default `loadTable` / `loadView` / `tableExists` / `viewExists` discriminate via
`instanceof Table` / `instanceof View`. `listTableAndViewSummaries` -> `listRelationSummaries`.
- `ViewCatalog.loadView` / `createView` / `replaceView` / `createOrReplaceView` now speak `View`.
- The resolver (`Analyzer`, `RelationResolution`) carries `Relation`, so a pure `ViewCatalog`
returns its `View` directly instead of wrapping it in a `MetadataTable`. A view is never
represented as a `Table`.
A combined catalog stays easy to implement: from `loadRelation`, return your own `Table` (or a
`DelegatingTable` over a `TableInfo`) for a table, and a `View` for a view.
`Relation` is left un-sealed: `Table` is independently an open interface (so a closed hierarchy
adds little), and a sealed Java interface trips Scala's pattern-match analysis.
### Why are the changes needed?
Modeling `Relation = Table | View` removes the `ViewInfo IS-A TableInfo` lie and the
view-as-Table smuggling, keeps `DelegatingTable` single-purpose, and keeps each builder scoped to
exactly what its kind needs -- while preserving the single-RPC `loadRelation` perf path.
### Does this PR introduce _any_ user-facing change?
No. The affected APIs (`Relation`, `Table`, `View`, `TableInfo`, `DelegatingTable`,
`RelationCatalog`, `ViewCatalog`) are `Evolving` and unreleased (`since 4.2.0`).
### How was this patch tested?
Existing tests, updated for the new types. Ran `DataSourceV2MetadataViewSuite`,
`DataSourceV2MetadataTableSuite`, `MetricViewV2CatalogSuite`, the v2 view DDL suites,
`SimpleSQLViewSuite`, `PersistedViewTestSuite`, and the temp-view suites -- all passing.
`catalyst` and `sql/core` compile (main + test).
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
Closes #56606 from cloud-fan/view-info-relation-info-refactor.
Authored-by: Wenchen Fan <we...@databricks.com>
Signed-off-by: Wenchen Fan <we...@databricks.com>
(cherry picked from commit 1c997dc6ed7d7ac46a0eb95cc9aa16153b9976a8)
Signed-off-by: Wenchen Fan <we...@databricks.com>
---
.../{MetadataTable.java => DelegatingTable.java} | 29 ++---
.../spark/sql/connector/catalog/Relation.java | 53 +++++++++
.../sql/connector/catalog/RelationBuilder.java | 85 ++++++++++++++
...{TableViewCatalog.java => RelationCatalog.java} | 79 ++++++-------
.../apache/spark/sql/connector/catalog/Table.java | 4 +-
.../spark/sql/connector/catalog/TableCatalog.java | 2 +-
.../spark/sql/connector/catalog/TableInfo.java | 97 ++++------------
.../connector/catalog/{ViewInfo.java => View.java} | 56 ++++++----
.../spark/sql/connector/catalog/ViewCatalog.java | 16 +--
.../spark/sql/catalyst/analysis/Analyzer.scala | 31 +++---
.../sql/catalyst/analysis/RelationResolution.scala | 47 ++++----
.../sql/catalyst/analysis/v2ResolutionPlans.scala | 10 +-
.../sql/catalyst/catalog/SessionCatalog.scala | 2 +-
.../spark/sql/catalyst/catalog/interface.scala | 2 +-
.../sql/connector/catalog/CatalogV2Util.scala | 6 +-
.../spark/sql/connector/catalog/Catalogs.scala | 12 +-
.../spark/sql/connector/catalog/V1Table.scala | 12 +-
.../catalog/{V1ViewInfo.scala => V1View.scala} | 30 ++---
.../sql/metricview/serde/MetricViewCanonical.scala | 2 +-
...Catalog.scala => InMemoryRelationCatalog.scala} | 50 ++++-----
.../catalyst/analysis/ResolveSessionCatalog.scala | 2 +-
.../command/DescribeRelationJsonCommand.scala | 6 +-
.../execution/command/ShowTablesJsonCommand.scala | 6 +-
.../spark/sql/execution/command/tables.scala | 6 +-
.../execution/datasources/v2/AlterV2ViewExec.scala | 18 +--
.../datasources/v2/CreateV2ViewExec.scala | 10 +-
.../datasources/v2/DataSourceV2Strategy.scala | 14 +--
.../execution/datasources/v2/ShowTablesExec.scala | 10 +-
.../datasources/v2/V2ViewInspectionExecs.scala | 26 ++---
.../connector/DataSourceV2MetadataTableSuite.scala | 12 +-
.../connector/DataSourceV2MetadataViewSuite.scala | 124 ++++++++++-----------
.../sql/execution/MetricViewV2CatalogSuite.scala | 80 ++++++-------
.../AlterViewSetTblPropertiesSuiteBase.scala | 2 +-
.../execution/command/CreateViewSuiteBase.scala | 2 +-
.../sql/execution/command/DropViewSuiteBase.scala | 2 +-
.../execution/command/PlanResolutionSuite.scala | 2 +-
.../command/v2/AlterViewSchemaBindingSuite.scala | 2 +-
.../v2/AlterViewSetTblPropertiesSuite.scala | 2 +-
.../v2/AlterViewUnsetTblPropertiesSuite.scala | 2 +-
.../sql/execution/command/v2/CreateViewSuite.scala | 8 +-
.../command/v2/ViewCommandSuiteBase.scala | 12 +-
41 files changed, 533 insertions(+), 440 deletions(-)
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/MetadataTable.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/DelegatingTable.java
similarity index 67%
rename from sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/MetadataTable.java
rename to sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/DelegatingTable.java
index 1d1acfde80f9..2e8d63eb16d9 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/MetadataTable.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/DelegatingTable.java
@@ -27,40 +27,35 @@ import org.apache.spark.sql.connector.catalog.constraints.Constraint;
import org.apache.spark.sql.connector.expressions.Transform;
/**
- * A concrete {@code Table} implementation that contains only table metadata, deferring
- * read/write to Spark. It represents a general Spark data source table or a Spark view;
- * Spark resolves the table provider into a data source (for tables) or expands the view text
- * (for views) at read time.
+ * A concrete {@link Table} that adapts a {@link TableInfo} -- it contains only table metadata and
+ * defers read/write to Spark, which resolves the table provider into a data source at read time.
* <p>
- * Catalogs build the metadata via {@link TableInfo.Builder} (for data-source tables) or
- * {@link ViewInfo.Builder} (for views). A {@code MetadataTable} wrapping a
- * {@link TableInfo} can be returned from {@link TableCatalog#loadTable(Identifier)} for a
- * data-source table; a {@code MetadataTable} wrapping a {@link ViewInfo} can be returned
- * from {@link TableViewCatalog#loadTableOrView(Identifier)} as the single-RPC perf opt-in
- * for a view.
- * Downstream consumers distinguish the two by checking
- * {@code getTableInfo() instanceof ViewInfo}.
+ * Catalogs build the metadata via {@link TableInfo.Builder} and return a {@code DelegatingTable}
+ * from {@link TableCatalog#loadTable(Identifier)} (or {@link RelationCatalog#loadRelation} for a
+ * data-source table) when they want Spark to handle the underlying source. A catalog that has its
+ * own {@link Table} object returns that instead. Views are never represented as a
+ * {@code DelegatingTable}: a view is a {@link View}, which is itself a {@link Relation}.
*
* @since 4.2.0
*/
@Evolving
-public class MetadataTable implements Table {
+public class DelegatingTable implements Table {
private final TableInfo info;
private final String name;
/**
- * @param info metadata for the table or view. Pass a {@link ViewInfo} for a view.
+ * @param info the table metadata to delegate to.
* @param name human-readable name for this table, returned by {@link #name()} and surfaced
* in places that read it (e.g. {@code BatchScan} plan-tree labels and
* partition-management error messages). {@code DESCRIBE TABLE EXTENDED} does
* not read this field; it emits the resolved identifier as structured
* {@code Catalog} / {@code Namespace} / {@code Table} rows. Catalogs returning
- * a {@code MetadataTable} from {@link TableCatalog#loadTable} or
- * {@link TableViewCatalog#loadTableOrView} should typically pass
+ * a {@code DelegatingTable} from {@link TableCatalog#loadTable} or
+ * {@link RelationCatalog#loadRelation} should typically pass
* {@code ident.toString()}, matching the quoted multi-part form used elsewhere
* for v2 identifiers.
*/
- public MetadataTable(TableInfo info, String name) {
+ public DelegatingTable(TableInfo info, String name) {
this.info = Objects.requireNonNull(info, "info should not be null");
this.name = Objects.requireNonNull(name, "name should not be null");
}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Relation.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Relation.java
new file mode 100644
index 000000000000..747a22c489c8
--- /dev/null
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Relation.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.connector.catalog;
+
+import java.util.Map;
+
+import org.apache.spark.annotation.Evolving;
+
+/**
+ * A relation in a catalog: either a {@link Table} or a {@link View}. This is the common type
+ * returned by {@link RelationCatalog#loadRelation} so a catalog that exposes both kinds can
+ * answer a single read in one round trip; callers discriminate with {@code instanceof Table} /
+ * {@code instanceof View}.
+ * <p>
+ * The two kinds are deliberately asymmetric, mirroring how Spark treats them: a {@link Table} is
+ * an object Spark reads from and writes to, while a {@link View} carries only metadata (Spark
+ * expands its query text at read time and never builds a view object). Modeling both as siblings
+ * of {@code Relation} -- rather than smuggling a view through the {@code Table} surface -- keeps
+ * table-only concepts (partitioning, constraints, scans, writes) off the view side.
+ * <p>
+ * In practice the only two kinds are {@link Table} and {@link View}. {@code Relation} is left
+ * un-sealed because {@link Table} is itself an open interface (so a closed hierarchy would add
+ * little) and because a sealed Java interface trips Scala's pattern-match analysis.
+ *
+ * @since 4.2.0
+ */
+@Evolving
+public interface Relation {
+
+ /**
+ * The columns of this relation.
+ */
+ Column[] columns();
+
+ /**
+ * The string map of properties of this relation.
+ */
+ Map<String, String> properties();
+}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationBuilder.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationBuilder.java
new file mode 100644
index 000000000000..12e225b8bfdd
--- /dev/null
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationBuilder.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.connector.catalog;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.spark.sql.types.StructType;
+
+/**
+ * Shared builder state for {@link TableInfo.Builder} and {@link View.Builder} -- the fields and
+ * convenience setters common to building a table's metadata and a view: the columns and the
+ * string properties bag, plus the reserved-property setters that apply to both. Setters return
+ * {@code B} so subclass builders chain through their own type without a covariant override on each
+ * inherited setter.
+ * <p>
+ * This is an internal implementation detail: tables and views do not share a value type (a
+ * {@link TableInfo} describes a table Spark will realize as a {@link Table}, while a {@link View}
+ * is itself a {@link Relation}), only this builder logic.
+ */
+abstract class RelationBuilder<B extends RelationBuilder<B>> {
+ protected Column[] columns = new Column[0];
+ protected Map<String, String> properties = new HashMap<>();
+
+ protected abstract B self();
+
+ public B withColumns(Column[] columns) {
+ this.columns = columns;
+ return self();
+ }
+
+ public B withSchema(StructType schema) {
+ this.columns = CatalogV2Util.structTypeToV2Columns(schema);
+ return self();
+ }
+
+ /**
+ * Replaces the current properties map with a defensive copy of the given map. Any reserved
+ * keys set earlier via convenience setters (e.g. {@link #withComment}) are discarded --
+ * call those setters <i>after</i> this method, not before.
+ */
+ public B withProperties(Map<String, String> properties) {
+ this.properties = new HashMap<>(properties);
+ return self();
+ }
+
+ // Convenience setters below write reserved keys into the current `properties` map. Pair
+ // each with a preceding `withProperties(...)` call if you want to start from a user map;
+ // calling `withProperties` after a convenience setter discards the value the convenience
+ // setter wrote.
+
+ public B withComment(String comment) {
+ properties.put(TableCatalog.PROP_COMMENT, comment);
+ return self();
+ }
+
+ public B withCollation(String collation) {
+ properties.put(TableCatalog.PROP_COLLATION, collation);
+ return self();
+ }
+
+ public B withOwner(String owner) {
+ properties.put(TableCatalog.PROP_OWNER, owner);
+ return self();
+ }
+
+ public B withTableType(String tableType) {
+ properties.put(TableCatalog.PROP_TABLE_TYPE, tableType);
+ return self();
+ }
+}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableViewCatalog.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationCatalog.java
similarity index 73%
rename from sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableViewCatalog.java
rename to sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationCatalog.java
index 45ec41d680d8..e088e5d3a82c 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableViewCatalog.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/RelationCatalog.java
@@ -27,15 +27,15 @@ import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
* Catalog API for connectors that expose both tables and views in a single shared identifier
* namespace.
* <p>
- * Connectors that expose <i>both</i> tables and views must implement {@code TableViewCatalog};
+ * Connectors that expose <i>both</i> tables and views must implement {@code RelationCatalog};
* implementing {@link TableCatalog} and {@link ViewCatalog} directly without
- * {@code TableViewCatalog} is rejected at catalog initialization. Connectors that expose only
+ * {@code RelationCatalog} is rejected at catalog initialization. Connectors that expose only
* tables implement just {@link TableCatalog}; connectors that expose only views implement just
* {@link ViewCatalog}; this interface is not relevant to them.
*
* <h2>Two principles</h2>
*
- * A {@code TableViewCatalog} follows two rules that, taken together, define every cross-cutting
+ * A {@code RelationCatalog} follows two rules that, taken together, define every cross-cutting
* subtlety:
* <ol>
* <li><b>Orthogonal interfaces.</b> Every {@link TableCatalog} method behaves as if views did
@@ -102,14 +102,14 @@ import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
* <h2>Single-RPC perf entry points</h2>
*
* The orthogonal {@link TableCatalog} and {@link ViewCatalog} answer two cross-cutting
- * questions in two round trips each. {@code TableViewCatalog} adds dedicated methods so a
+ * questions in two round trips each. {@code RelationCatalog} adds dedicated methods so a
* catalog can answer both in one round trip:
* <ul>
- * <li>{@link #loadTableOrView(Identifier)} -- the resolver's per-identifier read path. Returns
- * a regular {@link Table} for a table, or a {@link MetadataTable} wrapping a
- * {@link ViewInfo} for a view. Saves the {@code loadTable} -> {@code loadView} fallback
- * on a cold cache.</li>
- * <li>{@link #listTableAndViewSummaries(String[])} -- a unified listing of tables and views
+ * <li>{@link #loadRelation(Identifier)} -- the resolver's per-identifier read path. Returns a
+ * {@link Table} for a table or a {@link View} for a view; callers discriminate via
+ * {@code instanceof}. Saves the {@code loadTable} -> {@code loadView} fallback on a cold
+ * cache.</li>
+ * <li>{@link #listRelationSummaries(String[])} -- a unified listing of tables and views
* with the kind preserved on each {@link TableSummary}. Default impl performs both
* {@link TableCatalog#listTableSummaries} and {@link ViewCatalog#listViews}; override to
* fetch in one round trip.</li>
@@ -118,22 +118,21 @@ import org.apache.spark.sql.catalyst.analysis.NoSuchViewException;
* @since 4.2.0
*/
@Evolving
-public interface TableViewCatalog extends TableCatalog, ViewCatalog {
+public interface RelationCatalog extends TableCatalog, ViewCatalog {
/**
- * Load metadata for an identifier that may resolve to either a table or a view.
+ * Load the relation for an identifier that may resolve to either a table or a view.
* <p>
- * For a table, returns the table's {@link Table}. For a view, returns a
- * {@link MetadataTable} wrapping a {@link ViewInfo}; callers discriminate via
- * {@code getTableInfo() instanceof ViewInfo}. This lets the resolver answer in a single RPC
- * instead of falling back from {@link TableCatalog#loadTable} to {@link ViewCatalog#loadView}.
+ * Returns a {@link Table} for a table or a {@link View} for a view; callers discriminate via
+ * {@code instanceof Table} / {@code instanceof View}. This lets the resolver answer in a single
+ * RPC instead of falling back from {@link TableCatalog#loadTable} to
+ * {@link ViewCatalog#loadView}.
*
* @param ident the identifier
- * @return a {@link Table} for tables, or a {@link MetadataTable} wrapping a
- * {@link ViewInfo} for views
+ * @return a {@link Table} for tables, or a {@link View} for views
* @throws NoSuchTableException if neither a table nor a view exists at {@code ident}
*/
- Table loadTableOrView(Identifier ident) throws NoSuchTableException;
+ Relation loadRelation(Identifier ident) throws NoSuchTableException;
/**
* List the tables and views in a namespace, returned as {@link TableSummary} entries with
@@ -149,7 +148,7 @@ public interface TableViewCatalog extends TableCatalog, ViewCatalog {
* @throws NoSuchTableException if a table listed by the underlying enumeration disappears
* before its summary can be assembled (default impl only)
*/
- default TableSummary[] listTableAndViewSummaries(String[] namespace)
+ default TableSummary[] listRelationSummaries(String[] namespace)
throws NoSuchNamespaceException, NoSuchTableException {
TableSummary[] tableSummaries = listTableSummaries(namespace);
Identifier[] viewIdentifiers = listViews(namespace);
@@ -167,52 +166,47 @@ public interface TableViewCatalog extends TableCatalog, ViewCatalog {
/**
* {@inheritDoc}
* <p>
- * The default implementation derives from {@link #loadTableOrView}: a {@link MetadataTable}
- * wrapping a {@link ViewInfo} is rejected as not-a-table; anything else is returned. Override
- * only if a tables-only path is materially cheaper than the unified one.
+ * The default implementation derives from {@link #loadRelation}: a {@link View} is rejected as
+ * not-a-table; a {@link Table} is returned. Override only if a tables-only path is materially
+ * cheaper than the unified one.
*/
@Override
default Table loadTable(Identifier ident) throws NoSuchTableException {
- Table t = loadTableOrView(ident);
- if (t instanceof MetadataTable mot && mot.getTableInfo() instanceof ViewInfo) {
- throw new NoSuchTableException(ident);
+ if (loadRelation(ident) instanceof Table t) {
+ return t;
}
- return t;
+ throw new NoSuchTableException(ident);
}
/**
* {@inheritDoc}
* <p>
- * The default implementation derives from {@link #loadTableOrView}: a {@link MetadataTable}
- * wrapping a {@link ViewInfo} is unwrapped and returned; anything else (table or absent) is
- * surfaced as {@link NoSuchViewException}. Override only if a views-only path is materially
- * cheaper than the unified one.
+ * The default implementation derives from {@link #loadRelation}: a {@link View} is returned;
+ * anything else (table or absent) is surfaced as {@link NoSuchViewException}. Override only if a
+ * views-only path is materially cheaper than the unified one.
*/
@Override
- default ViewInfo loadView(Identifier ident) throws NoSuchViewException {
- Table t;
+ default View loadView(Identifier ident) throws NoSuchViewException {
try {
- t = loadTableOrView(ident);
+ if (loadRelation(ident) instanceof View v) {
+ return v;
+ }
} catch (NoSuchTableException e) {
throw new NoSuchViewException(ident);
}
- if (t instanceof MetadataTable mot && mot.getTableInfo() instanceof ViewInfo vi) {
- return vi;
- }
throw new NoSuchViewException(ident);
}
/**
* {@inheritDoc}
* <p>
- * The default implementation derives from {@link #loadTableOrView}: returns {@code true} only if
- * the entry exists and is not a view. Override only if a cheaper existence-check path exists.
+ * The default implementation derives from {@link #loadRelation}: returns {@code true} only if
+ * the entry exists and is a table. Override only if a cheaper existence-check path exists.
*/
@Override
default boolean tableExists(Identifier ident) {
try {
- Table t = loadTableOrView(ident);
- return !(t instanceof MetadataTable mot && mot.getTableInfo() instanceof ViewInfo);
+ return loadRelation(ident) instanceof Table;
} catch (NoSuchTableException e) {
return false;
}
@@ -221,14 +215,13 @@ public interface TableViewCatalog extends TableCatalog, ViewCatalog {
/**
* {@inheritDoc}
* <p>
- * The default implementation derives from {@link #loadTableOrView}: returns {@code true} only if
+ * The default implementation derives from {@link #loadRelation}: returns {@code true} only if
* the entry exists and is a view. Override only if a cheaper existence-check path exists.
*/
@Override
default boolean viewExists(Identifier ident) {
try {
- Table t = loadTableOrView(ident);
- return t instanceof MetadataTable mot && mot.getTableInfo() instanceof ViewInfo;
+ return loadRelation(ident) instanceof View;
} catch (NoSuchTableException e) {
return false;
}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Table.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Table.java
index a298520760bc..2735f40770ab 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Table.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/Table.java
@@ -38,11 +38,13 @@ import java.util.Set;
* The default implementation of {@link #partitioning()} returns an empty array of partitions, and
* the default implementation of {@link #properties()} returns an empty map. These should be
* overridden by implementations that support partitioning and table properties.
+ * <p>
+ * A {@code Table} is one kind of {@link Relation}; the other is {@link View}.
*
* @since 3.0.0
*/
@Evolving
-public interface Table {
+public interface Table extends Relation {
/**
* A name to identify this table. Implementations should provide a meaningful name, like the
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java
index f64c34ee0e07..23e9499932c1 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java
@@ -35,7 +35,7 @@ import java.util.Set;
* Catalog API for connectors that expose tables.
* <p>
* Connectors that expose <i>only</i> tables implement this interface. Connectors that expose
- * both tables and views must implement {@link TableViewCatalog} (which extends both this
+ * both tables and views must implement {@link RelationCatalog} (which extends both this
* interface and {@link ViewCatalog} and adds the cross-cutting contract for the combined
* case); the methods on this interface remain table-only -- they do not interact with views.
* <p>
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableInfo.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableInfo.java
index 89709c9f1c2f..1a3261e3085a 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableInfo.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableInfo.java
@@ -16,7 +16,6 @@
*/
package org.apache.spark.sql.connector.catalog;
-import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -24,6 +23,13 @@ import org.apache.spark.sql.connector.catalog.constraints.Constraint;
import org.apache.spark.sql.connector.expressions.Transform;
import org.apache.spark.sql.types.StructType;
+/**
+ * Metadata describing a data-source table: its columns, properties, partitioning and constraints.
+ * Spark realizes a {@code TableInfo} into a {@link Table} via {@link DelegatingTable}; a catalog
+ * that has its own {@link Table} object returns that instead. Views are described by the sibling
+ * {@link View}, which -- unlike a table -- is itself a {@link Relation} because Spark never builds
+ * a view object.
+ */
public class TableInfo {
private final Column[] columns;
@@ -34,7 +40,7 @@ public class TableInfo {
/**
* Constructor for TableInfo used by the builder.
*/
- protected TableInfo(BaseBuilder<?> builder) {
+ protected TableInfo(Builder builder) {
this.columns = builder.columns;
this.properties = builder.properties;
this.partitions = builder.partitions;
@@ -59,96 +65,37 @@ public class TableInfo {
public Constraint[] constraints() { return constraints; }
- public static class Builder extends BaseBuilder<Builder> {
- @Override
- protected Builder self() { return this; }
-
- @Override
- public TableInfo build() {
- Objects.requireNonNull(columns, "columns should not be null");
- return new TableInfo(this);
- }
- }
-
- /**
- * Shared builder state for {@link TableInfo} and its subclasses. Setters return {@code B} so
- * subclass builders (e.g. {@link ViewInfo.Builder}) chain through their own type without
- * a covariant override on each inherited setter.
- */
- protected abstract static class BaseBuilder<B extends BaseBuilder<B>> {
- protected Column[] columns = new Column[0];
- protected Map<String, String> properties = new HashMap<>();
+ public static class Builder extends RelationBuilder<Builder> {
protected Transform[] partitions = new Transform[0];
protected Constraint[] constraints = new Constraint[0];
- protected abstract B self();
-
- public B withColumns(Column[] columns) {
- this.columns = columns;
- return self();
- }
-
- public B withSchema(StructType schema) {
- this.columns = CatalogV2Util.structTypeToV2Columns(schema);
- return self();
- }
-
- /**
- * Replaces the current properties map with a defensive copy of the given map. Any reserved
- * keys set earlier via convenience setters (e.g. {@link #withProvider}) are discarded --
- * call those setters <i>after</i> this method, not before.
- */
- public B withProperties(Map<String, String> properties) {
- this.properties = new HashMap<>(properties);
- return self();
- }
+ @Override
+ protected Builder self() { return this; }
- public B withPartitions(Transform[] partitions) {
+ public Builder withPartitions(Transform[] partitions) {
this.partitions = partitions;
- return self();
+ return this;
}
- public B withConstraints(Constraint[] constraints) {
+ public Builder withConstraints(Constraint[] constraints) {
this.constraints = constraints;
- return self();
+ return this;
}
- // Convenience setters below write reserved keys into the current `properties` map. Pair
- // each with a preceding `withProperties(...)` call if you want to start from a user map;
- // calling `withProperties` after a convenience setter discards the value the convenience
- // setter wrote.
-
/** Writes {@link TableCatalog#PROP_PROVIDER} into the current properties map. */
- public B withProvider(String provider) {
+ public Builder withProvider(String provider) {
properties.put(TableCatalog.PROP_PROVIDER, provider);
- return self();
+ return this;
}
- public B withLocation(String location) {
+ public Builder withLocation(String location) {
properties.put(TableCatalog.PROP_LOCATION, location);
- return self();
- }
-
- public B withComment(String comment) {
- properties.put(TableCatalog.PROP_COMMENT, comment);
- return self();
+ return this;
}
- public B withCollation(String collation) {
- properties.put(TableCatalog.PROP_COLLATION, collation);
- return self();
- }
-
- public B withOwner(String owner) {
- properties.put(TableCatalog.PROP_OWNER, owner);
- return self();
- }
-
- public B withTableType(String tableType) {
- properties.put(TableCatalog.PROP_TABLE_TYPE, tableType);
- return self();
+ public TableInfo build() {
+ Objects.requireNonNull(columns, "columns should not be null");
+ return new TableInfo(this);
}
-
- public abstract TableInfo build();
}
}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewInfo.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java
similarity index 79%
rename from sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewInfo.java
rename to sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java
index 0f46e915a9be..d4adef9a98c8 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewInfo.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/View.java
@@ -22,26 +22,28 @@ import java.util.Map;
import java.util.Objects;
import org.apache.spark.annotation.Evolving;
+import org.apache.spark.sql.types.StructType;
/**
- * View metadata DTO -- the typed payload returned by {@link ViewCatalog#loadView} and accepted
- * by {@link ViewCatalog#createView} / {@link ViewCatalog#replaceView}. Carries the
+ * A view in a catalog -- the typed payload returned by {@link ViewCatalog#loadView} and accepted
+ * by {@link ViewCatalog#createView} / {@link ViewCatalog#replaceView}. A {@code 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. Schema and user TBLPROPERTIES are inherited from {@link TableInfo}
- * via the typed builder.
+ * query output column names. Columns and user TBLPROPERTIES are set via the typed builder.
* <p>
- * {@code ViewInfo} extends {@link TableInfo} so that a {@link TableViewCatalog} can opt into the
- * single-RPC perf path by returning a {@link MetadataTable} wrapping a {@code ViewInfo}
- * from {@link TableViewCatalog#loadTableOrView} for a view identifier. Pure {@link ViewCatalog}
- * implementations never see {@code TableInfo}; the typed setters on {@link Builder} cover
- * everything they need to construct a {@code ViewInfo}.
+ * Unlike a {@link Table}, a {@code View} is itself a {@link Relation} rather than something Spark
+ * realizes into a {@code Table}: Spark expands the view's query text at read time and never builds
+ * a view object. A {@link RelationCatalog} returns a {@code View} directly from
+ * {@link RelationCatalog#loadRelation} for a view identifier, so it never has to smuggle a view
+ * through the {@code Table} surface.
*
* @since 4.2.0
*/
@Evolving
-public class ViewInfo extends TableInfo {
+public class View implements Relation {
+ private final Column[] columns;
+ private final Map<String, String> properties;
private final String queryText;
private final String currentCatalog;
private final String[] currentNamespace;
@@ -50,8 +52,9 @@ public class ViewInfo extends TableInfo {
private final String[] queryColumnNames;
private final DependencyList viewDependencies;
- protected ViewInfo(Builder builder) {
- super(builder);
+ protected View(Builder builder) {
+ this.columns = builder.columns;
+ this.properties = builder.properties;
this.queryText = Objects.requireNonNull(builder.queryText, "queryText should not be null");
this.currentCatalog = builder.currentCatalog;
this.currentNamespace = builder.currentNamespace;
@@ -59,10 +62,24 @@ public class ViewInfo extends TableInfo {
this.schemaMode = builder.schemaMode;
this.queryColumnNames = builder.queryColumnNames;
this.viewDependencies = builder.viewDependencies;
- // Default PROP_TABLE_TYPE = VIEW so `properties()` reflects the typed ViewInfo
- // classification. Callers can refine to a more specific view kind (for example,
- // METRIC_VIEW) by calling BaseBuilder.withTableType(...) on the builder before build().
- properties().putIfAbsent(TableCatalog.PROP_TABLE_TYPE, TableSummary.VIEW_TABLE_TYPE);
+ // Default PROP_TABLE_TYPE = VIEW so `properties()` reflects the typed View classification.
+ // Callers can refine to a more specific view kind (for example, METRIC_VIEW) by calling
+ // RelationBuilder.withTableType(...) on the builder before build().
+ properties.putIfAbsent(TableCatalog.PROP_TABLE_TYPE, TableSummary.VIEW_TABLE_TYPE);
+ }
+
+ @Override
+ public Column[] columns() {
+ return columns;
+ }
+
+ public StructType schema() {
+ return CatalogV2Util.v2ColumnsToStructType(columns);
+ }
+
+ @Override
+ public Map<String, String> properties() {
+ return properties;
}
/** The SQL text of the view. */
@@ -111,7 +128,7 @@ public class ViewInfo extends TableInfo {
*/
public DependencyList viewDependencies() { return viewDependencies; }
- public static class Builder extends BaseBuilder<Builder> {
+ public static class Builder extends RelationBuilder<Builder> {
private String queryText;
private String currentCatalog;
private String[] currentNamespace = new String[0];
@@ -163,10 +180,9 @@ public class ViewInfo extends TableInfo {
return this;
}
- @Override
- public ViewInfo build() {
+ public View build() {
Objects.requireNonNull(columns, "columns should not be null");
- return new ViewInfo(this);
+ return new View(this);
}
}
}
diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java
index 0e74b22079bf..12782ad7f131 100644
--- a/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java
+++ b/sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/ViewCatalog.java
@@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException;
* Catalog API for connectors that expose views.
* <p>
* Connectors that expose <i>only</i> views implement this interface. Connectors that expose
- * both tables and views must implement {@link TableViewCatalog} (which extends both this
+ * both tables and views must implement {@link RelationCatalog} (which extends both this
* interface and {@link TableCatalog} and adds the cross-cutting contract for the combined
* case); the methods on this interface remain view-only -- they do not interact with tables.
* <p>
@@ -53,7 +53,7 @@ public interface ViewCatalog extends CatalogPlugin {
* @return the view metadata
* @throws NoSuchViewException if the view does not exist
*/
- ViewInfo loadView(Identifier ident) throws NoSuchViewException;
+ View loadView(Identifier ident) throws NoSuchViewException;
/**
* Test whether a view exists.
@@ -93,7 +93,7 @@ public interface ViewCatalog extends CatalogPlugin {
* @throws ViewAlreadyExistsException if a view already exists at {@code ident}
* @throws NoSuchNamespaceException if the identifier's namespace does not exist (optional)
*/
- ViewInfo createView(Identifier ident, ViewInfo info)
+ View createView(Identifier ident, View info)
throws ViewAlreadyExistsException, NoSuchNamespaceException;
/**
@@ -108,7 +108,7 @@ public interface ViewCatalog extends CatalogPlugin {
* @return the metadata of the replaced view; may equal {@code info}
* @throws NoSuchViewException if no view exists at {@code ident}
*/
- ViewInfo replaceView(Identifier ident, ViewInfo info) throws NoSuchViewException;
+ View replaceView(Identifier ident, View info) throws NoSuchViewException;
/**
* Create a view if one does not exist at {@code ident}, or atomically replace it if one does.
@@ -126,10 +126,10 @@ public interface ViewCatalog extends CatalogPlugin {
* concurrent {@code CREATE VIEW} won the race in the
* default impl's gap between {@link #replaceView} and
* the fallback {@link #createView}, or, in a
- * {@link TableViewCatalog}, a table sits at {@code ident}
+ * {@link RelationCatalog}, a table sits at {@code ident}
* @throws NoSuchNamespaceException if the identifier's namespace does not exist (optional)
*/
- default ViewInfo createOrReplaceView(Identifier ident, ViewInfo info)
+ default View createOrReplaceView(Identifier ident, View info)
throws ViewAlreadyExistsException, NoSuchNamespaceException {
try {
return replaceView(ident, info);
@@ -152,12 +152,12 @@ public interface ViewCatalog extends CatalogPlugin {
* If the catalog supports tables and contains a table at the new identifier, this must throw
* {@link ViewAlreadyExistsException}. If the source identifier resolves to a table rather than
* a view, this must throw {@link NoSuchViewException}. The cross-type contract for catalogs
- * that expose both tables and views lives on {@link TableViewCatalog}.
+ * that expose both tables and views lives on {@link RelationCatalog}.
*
* @param oldIdent the view identifier of the existing view to rename
* @param newIdent the new view identifier
* @throws NoSuchViewException if no view exists at {@code oldIdent}
- * @throws ViewAlreadyExistsException if a view (or, in a {@link TableViewCatalog}, a table)
+ * @throws ViewAlreadyExistsException if a view (or, in a {@link RelationCatalog}, a table)
* already exists at {@code newIdent}
*/
void renameView(Identifier oldIdent, Identifier newIdent)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
index 98b973abeb8a..c03accfa3312 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
@@ -51,7 +51,9 @@ import org.apache.spark.sql.catalyst.trees.TreePattern._
import org.apache.spark.sql.catalyst.types.DataTypeUtils
import org.apache.spark.sql.catalyst.util.{toPrettySQL, trimTempResolvedColumn, CharVarcharUtils}
import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns._
-import org.apache.spark.sql.connector.catalog._
+// `View` is aliased to `V2View` to avoid clashing with the logical-plan `View` imported via
+// `org.apache.spark.sql.catalyst.plans.logical._`.
+import org.apache.spark.sql.connector.catalog.{View => V2View, _}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
import org.apache.spark.sql.connector.catalog.TableChange.{After, ColumnPosition}
import org.apache.spark.sql.connector.catalog.functions.UnboundFunction
@@ -1189,9 +1191,9 @@ class Analyzer(
* so surfacing a downstream "view not found" would hide the real reason.
*
* Lookup order against a non-session catalog:
- * 1. If the catalog is a [[TableViewCatalog]], [[TableViewCatalog.loadTableOrView]] is called
- * once. A returned [[MetadataTable]] wrapping a [[ViewInfo]] is interpreted as a
- * view; other results are tables.
+ * 1. If the catalog is a [[RelationCatalog]], [[RelationCatalog.loadRelation]] is called
+ * once. A returned [[org.apache.spark.sql.connector.catalog.View]] is interpreted as a
+ * view; a [[Table]] is a table.
* 2. Otherwise, [[TableCatalog.loadTable]] is tried (when implemented), then
* [[ViewCatalog.loadView]] as the fallback view-resolution path (when implemented).
*/
@@ -1208,17 +1210,18 @@ class Analyzer(
throw QueryCompilationErrors.missingCatalogViewsAbilityError(catalog)
}
catalog match {
- case mc: TableViewCatalog =>
- // Single-RPC perf path: loadTableOrView returns a Table for a table or a
- // MetadataTable wrapping a ViewInfo for a view. NoSuchTable means
- // neither exists.
+ case mc: RelationCatalog =>
+ // Single-RPC perf path: loadRelation returns a Table for a table or a View
+ // for a view. NoSuchTable means neither exists.
try {
- Some(mc.loadTableOrView(ident) match {
- case t: MetadataTable if t.getTableInfo.isInstanceOf[ViewInfo] =>
- ResolvedPersistentView(
- catalog, ident, t.getTableInfo.asInstanceOf[ViewInfo])
- case table =>
+ Some(mc.loadRelation(ident) match {
+ case v: V2View =>
+ ResolvedPersistentView(catalog, ident, v)
+ case table: Table =>
ResolvedTable.create(catalog.asTableCatalog, ident, table)
+ case other => throw SparkException.internalError(
+ s"Catalog ${catalog.name} returned an unexpected relation type for " +
+ s"$ident: ${other.getClass.getName}. Expected a Table or a View.")
})
} catch {
case _: NoSuchTableException => None
@@ -1237,7 +1240,7 @@ class Analyzer(
val v1Ident = v1Table.catalogTable.identifier
val v2Ident = Identifier.of(v1Ident.database.toArray, v1Ident.identifier)
ResolvedPersistentView(
- catalog, v2Ident, new V1ViewInfo(v1Table.catalogTable))
+ catalog, v2Ident, new V1View(v1Table.catalogTable))
case table =>
ResolvedTable.create(catalog.asTableCatalog, ident, table)
}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala
index 55a7ad10790e..22bed3fbe769 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/RelationResolution.scala
@@ -34,16 +34,17 @@ import org.apache.spark.sql.connector.catalog.{
CatalogPlugin,
CatalogV2Util,
ChangelogContext,
+ DelegatingTable,
Identifier,
LookupCatalog,
- MetadataTable,
+ Relation,
+ RelationCatalog,
Table,
TableCatalog,
- TableViewCatalog,
V1Table,
V2TableWithV1Fallback,
- ViewCatalog,
- ViewInfo
+ View,
+ ViewCatalog
}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
import org.apache.spark.sql.errors.{DataTypeErrorsBase, QueryCompilationErrors}
@@ -243,8 +244,8 @@ class RelationResolution(
.orElse {
val writePrivileges = u.options.get(UnresolvedRelation.REQUIRED_WRITE_PRIVILEGES)
val finalOptions = u.clearWritePrivileges.options
- // For a `TableViewCatalog` with no time-travel / write privileges, the single-RPC
- // `loadTableOrView` answers both "is there a table?" and "is there a view?" in one
+ // For a `RelationCatalog` with no time-travel / write privileges, the single-RPC
+ // `loadRelation` answers both "is there a table?" and "is there a view?" in one
// call. Time-travel and write privileges apply to tables only, so for those the
// lookup falls through to the table-only `loadTable` path below; views are not
// reachable via the v2 fallback in those cases.
@@ -252,10 +253,10 @@ class RelationResolution(
// Skip the table-side lookup entirely for view-only catalogs (no `TableCatalog`
// mixin): `CatalogV2Util.loadTable` would call `asTableCatalog` and throw
// MISSING_CATALOG_ABILITY.TABLES, masking the legitimate view-resolution path.
- val tableOrView: Option[Table] = catalog match {
- case mc: TableViewCatalog if finalTimeTravelSpec.isEmpty && writePrivileges == null =>
+ val relation: Option[Relation] = catalog match {
+ case mc: RelationCatalog if finalTimeTravelSpec.isEmpty && writePrivileges == null =>
try {
- Some(mc.loadTableOrView(ident))
+ Some(mc.loadRelation(ident))
} catch {
case _: NoSuchTableException => None
}
@@ -280,7 +281,7 @@ class RelationResolution(
catalog match {
case vc: ViewCatalog =>
try {
- Some(new MetadataTable(vc.loadView(ident), ident.toString))
+ Some(vc.loadView(ident))
} catch {
case _: NoSuchViewException => None
}
@@ -291,12 +292,9 @@ class RelationResolution(
}
}
}
- // `table` is `tableOrView` filtered to tables only -- used for cache lookup since
+ // `table` is `relation` filtered to tables only -- used for cache lookup since
// we don't share-cache views.
- val table: Option[Table] = tableOrView.filter {
- case t: MetadataTable if t.getTableInfo.isInstanceOf[ViewInfo] => false
- case _ => true
- }
+ val table: Option[Table] = relation.collect { case t: Table => t }
val sharedRelationCacheMatch = for {
t <- table
@@ -314,7 +312,7 @@ class RelationResolution(
val loaded = createRelation(
catalog,
ident,
- tableOrView,
+ relation,
finalOptions,
u.isStreaming,
finalTimeTravelSpec)
@@ -373,7 +371,7 @@ class RelationResolution(
private def createRelation(
catalog: CatalogPlugin,
ident: Identifier,
- table: Option[Table],
+ relation: Option[Relation],
options: CaseInsensitiveStringMap,
isStreaming: Boolean,
timeTravelSpec: Option[TimeTravelSpec]): Option[LogicalPlan] = {
@@ -393,7 +391,12 @@ class RelationResolution(
}
}
- table.map {
+ relation.map {
+ // A view is interpreted via v1: project it to a `CatalogTable` and run the v1 scan path,
+ // which expands the view text.
+ case v: View =>
+ createDataSourceV1Scan(V1Table.toCatalogTable(catalog, ident, v))
+
// To utilize this code path to execute V1 commands, e.g. INSERT,
// either it must be session catalog, or tracksPartitionsInCatalog
// must be false so it does not require use catalog to manage partitions.
@@ -405,13 +408,13 @@ class RelationResolution(
|| !v1Table.catalogTable.tracksPartitionsInCatalog =>
createDataSourceV1Scan(v1Table.v1Table)
- // MetadataTable is a sentinel meaning "interpret via v1", so unlike the V1Table
+ // DelegatingTable is a sentinel meaning "interpret via v1", so unlike the V1Table
// case above we apply no session-catalog / tracksPartitionsInCatalog guard -- any catalog
- // returning MetadataTable has opted into v1 read semantics.
- case t: MetadataTable =>
+ // returning DelegatingTable has opted into v1 read semantics.
+ case t: DelegatingTable =>
createDataSourceV1Scan(V1Table.toCatalogTable(catalog, ident, t))
- case table =>
+ case table: Table =>
if (isStreaming) {
assert(timeTravelSpec.isEmpty, "time travel is not allowed in streaming")
val v1Fallback = table match {
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala
index a8f5f0688890..43370748e2b3 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/v2ResolutionPlans.scala
@@ -229,19 +229,19 @@ case class ResolvedProcedure(
/**
* A plan containing a resolved persistent view.
*
- * `info` is the typed v2 [[org.apache.spark.sql.connector.catalog.ViewInfo]] payload for the
+ * `info` is the typed v2 [[org.apache.spark.sql.connector.catalog.View]] payload for the
* view. Session-catalog (v1) views are surfaced through the same channel via
- * [[org.apache.spark.sql.connector.catalog.V1ViewInfo]], which extends `ViewInfo` and wraps
+ * [[org.apache.spark.sql.connector.catalog.V1View]], which extends `View` and wraps
* the original [[CatalogTable]] -- mirroring the way
* [[org.apache.spark.sql.connector.catalog.V1Table]] exposes a v1 `CatalogTable` through the
* v2 [[org.apache.spark.sql.connector.catalog.Table]] surface for `ResolvedTable`. v1-only
* paths (e.g. `DescribeTableCommand`, `ShowCreateTableCommand`) recover the original
- * `CatalogTable` by pattern-matching `info` against `V1ViewInfo`.
+ * `CatalogTable` by pattern-matching `info` against `V1View`.
*/
case class ResolvedPersistentView(
catalog: CatalogPlugin,
identifier: Identifier,
- info: org.apache.spark.sql.connector.catalog.ViewInfo)
+ info: org.apache.spark.sql.connector.catalog.View)
extends LeafNodeWithoutStats {
// Surface the view's schema as `output` so `ResolveReferences` can resolve column references
// against it (e.g. `DescribeColumn(ResolvedPersistentView, UnresolvedAttribute, ...)`). The
@@ -252,7 +252,7 @@ case class ResolvedPersistentView(
toAttributes(CharVarcharUtils.replaceCharVarcharWithStringInSchema(info.schema))
// Render `info` in plan-tree output as the qualified view name. The default case-class
- // `toString` would format `info` via `Object.toString`, which produces `V1ViewInfo@<hash>`
+ // `toString` would format `info` via `Object.toString`, which produces `V1View@<hash>`
// for the v1 leg and a similarly opaque hash for the v2 leg -- non-deterministic and useless
// in EXPLAIN / golden file output. Replace it with the multi-part `catalog.namespace.name`
// form so EXPLAIN, plan-tree dumps, and `SQLQueryTestSuite` golden files remain stable.
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
index fd700f1ee013..d8461300f927 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
@@ -1123,7 +1123,7 @@ class SessionCatalog(
// so the SubqueryAlias qualifier reflects the real catalog + multi-part namespace.
// Fall back to the historical 3-part form for v1 session-catalog tables -- we intentionally
// always include `SESSION_CATALOG_NAME` here and ignore
- // `LEGACY_NON_IDENTIFIER_OUTPUT_CATALOG_NAME` to preserve pre-v2-MetadataTable behavior.
+ // `LEGACY_NON_IDENTIFIER_OUTPUT_CATALOG_NAME` to preserve pre-v2-DelegatingTable behavior.
val multiParts = metadata.multipartIdentifier.getOrElse {
val qualifiedIdent = qualifyIdentifier(metadata.identifier)
Seq(CatalogManager.SESSION_CATALOG_NAME, qualifiedIdent.database.get, qualifiedIdent.table)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala
index 6dda153985e5..247d4124dae4 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala
@@ -447,7 +447,7 @@ case class CatalogTable(
ignoredProperties: Map[String, String] = Map.empty,
viewOriginalText: Option[String] = None,
// Multi-part identifier [catalog, namespace..., name] for tables synthesized from a v2
- // `MetadataTable` whose namespace has more than one part -- the v1 `identifier:
+ // `DelegatingTable` whose namespace has more than one part -- the v1 `identifier:
// TableIdentifier` (single-string database) cannot carry that losslessly. `None` for
// v1-native tables; callers should use `fullIdent` which falls back to `identifier.nameParts`.
multipartIdentifier: Option[Seq[String]] = None)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala
index e34a21eeec76..cbebe5b4934d 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Util.scala
@@ -534,14 +534,14 @@ private[sql] object CatalogV2Util {
}
/**
- * Construct a [[ViewInfo.Builder]] seeded from an existing view's metadata. Used by ALTER
+ * Construct a [[View.Builder]] seeded from an existing view's metadata. Used by ALTER
* VIEW execs (SET / UNSET TBLPROPERTIES, ALTER VIEW ... WITH SCHEMA BINDING) -- override
* the one field that changes, then `build` to produce the replacement payload for
* [[ViewCatalog#replaceView]]. Every other field flows through unchanged so a metadata-only
* mutation does not perturb the view body.
*/
- def viewInfoBuilderFrom(existing: ViewInfo): ViewInfo.Builder = {
- val builder = new ViewInfo.Builder()
+ def viewInfoBuilderFrom(existing: View): View.Builder = {
+ val builder = new View.Builder()
builder
.withSchema(existing.schema)
.withProperties(existing.properties)
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/Catalogs.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/Catalogs.scala
index c40d5ab67919..03addeb17069 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/Catalogs.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/Catalogs.scala
@@ -64,7 +64,7 @@ private[sql] object Catalogs {
}
val plugin = pluginClass.getDeclaredConstructor().newInstance().asInstanceOf[CatalogPlugin]
plugin.initialize(name, catalogOptions(name, conf))
- validateTableViewCatalog(name, plugin)
+ validateRelationCatalog(name, plugin)
plugin
} catch {
case e: ClassNotFoundException =>
@@ -110,17 +110,17 @@ private[sql] object Catalogs {
/**
* Reject catalogs that implement both [[TableCatalog]] and [[ViewCatalog]] without
- * extending [[TableViewCatalog]]. The combined case has cross-cutting rules (single namespace,
- * cross-type collision rejection, perf opt-ins) that live on [[TableViewCatalog]]; implementing
+ * extending [[RelationCatalog]]. The combined case has cross-cutting rules (single namespace,
+ * cross-type collision rejection, perf opt-ins) that live on [[RelationCatalog]]; implementing
* the two interfaces directly would skip that contract.
*/
- private def validateTableViewCatalog(name: String, plugin: CatalogPlugin): Unit = {
+ private def validateRelationCatalog(name: String, plugin: CatalogPlugin): Unit = {
if (plugin.isInstanceOf[TableCatalog] && plugin.isInstanceOf[ViewCatalog] &&
- !plugin.isInstanceOf[TableViewCatalog]) {
+ !plugin.isInstanceOf[RelationCatalog]) {
throw new IllegalArgumentException(
s"Catalog '$name' (${plugin.getClass.getName}) implements both TableCatalog and " +
s"ViewCatalog directly. Catalogs that expose both tables and views must implement " +
- s"TableViewCatalog instead, which centralizes the cross-cutting rules (shared " +
+ s"RelationCatalog instead, which centralizes the cross-cutting rules (shared " +
s"identifier namespace, cross-type collision rejection, single-RPC perf entry " +
s"points).")
}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1Table.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1Table.scala
index 8a47cac8e796..f4b629e372cd 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1Table.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1Table.scala
@@ -113,10 +113,8 @@ private[sql] object V1Table {
def toCatalogTable(
catalog: CatalogPlugin,
ident: Identifier,
- t: MetadataTable): CatalogTable = t.getTableInfo match {
- case viewInfo: ViewInfo => toCatalogTable(catalog, ident, viewInfo)
- case tableInfo => toCatalogTable(catalog, ident, tableInfo)
- }
+ t: DelegatingTable): CatalogTable =
+ toCatalogTable(catalog, ident, t.getTableInfo)
private def toCatalogTable(
catalog: CatalogPlugin,
@@ -127,7 +125,7 @@ private[sql] object V1Table {
// v1 mapping (e.g. TableSummary.FOREIGN_TABLE_TYPE). v1 only has EXTERNAL/MANAGED, so
// anything other than the explicit MANAGED mapping falls back to EXTERNAL for the v1
// representation -- the same default v1 uses when the value is missing. VIEW is reached
- // only through the ViewInfo branch above.
+ // only through the View branch above.
val tableType = props.get(TableCatalog.PROP_TABLE_TYPE) match {
case Some(TableSummary.MANAGED_TABLE_TYPE) => CatalogTableType.MANAGED
case _ => CatalogTableType.EXTERNAL
@@ -169,7 +167,7 @@ private[sql] object V1Table {
def toCatalogTable(
catalog: CatalogPlugin,
ident: Identifier,
- info: ViewInfo): CatalogTable = {
+ info: View): CatalogTable = {
val props = info.properties.asScala.toMap
val userProps = props -- CatalogV2Util.TABLE_RESERVED_PROPERTIES
// Serde/OPTION properties only apply to data-source tables; views' user properties are a
@@ -196,7 +194,7 @@ private[sql] object V1Table {
val schemaModeProps = Option(info.schemaMode)
.map(m => Map(CatalogTable.VIEW_SCHEMA_MODE -> m))
.getOrElse(Map.empty)
- // ViewInfo always represents a view-like table, but PROP_TABLE_TYPE may further refine the
+ // View always represents a view-like table, but PROP_TABLE_TYPE may further refine the
// kind (e.g. METRIC_VIEW). Default to plain VIEW when no refinement is supplied.
val tableType = props.get(TableCatalog.PROP_TABLE_TYPE) match {
case Some(TableSummary.METRIC_VIEW_TABLE_TYPE) => CatalogTableType.METRIC_VIEW
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1ViewInfo.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1View.scala
similarity index 72%
rename from sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1ViewInfo.scala
rename to sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1View.scala
index e18fe52385a1..7a19d04dd4e4 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1ViewInfo.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/V1View.scala
@@ -22,42 +22,42 @@ import org.apache.spark.sql.catalyst.catalog.CatalogTable
/**
* A v1 [[CatalogTable]] (representing a session-catalog view) exposed through the v2
- * [[ViewInfo]] surface, mirroring the way [[V1Table]] exposes a v1 table CatalogTable through
+ * [[View]] surface, mirroring the way [[V1Table]] exposes a v1 table CatalogTable through
* the v2 [[Table]] surface. Holds the original [[CatalogTable]] in [[v1Table]] for v1-only
* paths that need the full v1 metadata representation (e.g. `DescribeTableCommand`,
* `ShowCreateTableCommand`, anything that calls `CatalogTable#toLinkedHashMap`).
*
- * Note on `properties()`: the inherited [[ViewInfo#properties]] bag is built from the entire
+ * Note on `properties()`: the inherited [[View#properties]] bag is built from the entire
* `v1Table.properties` map, which intermixes user TBLPROPERTIES with v1-internal storage keys
* (`view.sqlConfig.*`, `view.catalogAndNamespace.*`, `view.query.out.*`, `view.schemaMode`).
* v2 view inspection / SET execs (`ShowV2ViewPropertiesExec`, `AlterV2ViewSetPropertiesExec`,
- * etc.) never see a `V1ViewInfo` -- `ResolveSessionCatalog` rewrites session-catalog views to
+ * etc.) never see a `V1View` -- `ResolveSessionCatalog` rewrites session-catalog views to
* v1 commands first -- so the bag stays internal to v1-only paths. Consumers that do receive
- * a `V1ViewInfo` should prefer the typed accessors ([[ViewInfo#sqlConfigs]],
- * [[ViewInfo#currentNamespace]], [[ViewInfo#currentCatalog]], [[ViewInfo#queryColumnNames]],
- * [[ViewInfo#schemaMode]]) for the v1-internal fields rather than scraping `properties()` for
+ * a `V1View` should prefer the typed accessors ([[View#sqlConfigs]],
+ * [[View#currentNamespace]], [[View#currentCatalog]], [[View#queryColumnNames]],
+ * [[View#schemaMode]]) for the v1-internal fields rather than scraping `properties()` for
* them.
*/
-private[sql] class V1ViewInfo(val v1Table: CatalogTable)
- extends ViewInfo(V1ViewInfo.builderFrom(v1Table))
+private[sql] class V1View(val v1Table: CatalogTable)
+ extends View(V1View.builderFrom(v1Table))
-private[sql] object V1ViewInfo {
+private[sql] object V1View {
/**
- * Convert a v1 [[CatalogTable]] view into a [[ViewInfo.Builder]] with the same fields.
- * Used as the {@code super(builder)} argument when constructing a [[V1ViewInfo]].
+ * Convert a v1 [[CatalogTable]] view into a [[View.Builder]] with the same fields.
+ * Used as the {@code super(builder)} argument when constructing a [[V1View]].
*/
- private def builderFrom(v1Table: CatalogTable): ViewInfo.Builder = {
- val builder = new ViewInfo.Builder()
+ private def builderFrom(v1Table: CatalogTable): View.Builder = {
+ val builder = new View.Builder()
builder.withSchema(v1Table.schema)
builder.withProperties(v1Table.properties.asJava)
// v1 stores collation / comment in typed `CatalogTable` fields rather than in `properties`,
- // but consumers reading off [[ViewInfo]] (`ApplyDefaultCollation.fetchDefaultCollation`,
+ // but consumers reading off [[View]] (`ApplyDefaultCollation.fetchDefaultCollation`,
// `ShowCreateV2ViewExec`, etc.) expect them under `PROP_COLLATION` / `PROP_COMMENT`. Bridge
// them through the typed setters so the v2 surface sees the same view metadata regardless
// of which catalog produced it.
v1Table.collation.foreach(builder.withCollation)
v1Table.comment.foreach(builder.withComment)
- // ViewInfo requires a non-null queryText; v1 views always have one, but defend against
+ // View requires a non-null queryText; v1 views always have one, but defend against
// an old/corrupt CatalogTable with `viewText = None` by falling back to an empty string.
builder.withQueryText(v1Table.viewText.getOrElse(""))
val cn = v1Table.viewCatalogAndNamespace
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewCanonical.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewCanonical.scala
index 1b4718ebd385..3fa7ea539597 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewCanonical.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/metricview/serde/MetricViewCanonical.scala
@@ -179,7 +179,7 @@ private[sql] case class MetricView(
* [[Constants.MAXIMUM_PROPERTY_SIZE]] characters, so these are descriptive values
* for catalog browsers / lineage tooling -- not round-trippable representations
* of the source. Consumers that need the full SQL or filter expression for
- * re-execution should read [[ViewInfo#queryText]] (the YAML body) and re-parse it
+ * re-execution should read [[View#queryText]] (the YAML body) and re-parse it
* rather than reconstruct the query from these properties; for any source whose
* SQL exceeds the size limit, this property would silently return a truncated
* string.
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryTableViewCatalog.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryRelationCatalog.scala
similarity index 83%
rename from sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryTableViewCatalog.scala
rename to sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryRelationCatalog.scala
index a3506938dea7..d6f526b30ce0 100644
--- a/sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryTableViewCatalog.scala
+++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryRelationCatalog.scala
@@ -26,46 +26,46 @@ import org.apache.spark.sql.catalyst.analysis.{NamespaceAlreadyExistsException,
import org.apache.spark.sql.util.CaseInsensitiveStringMap
/**
- * An in-memory [[TableViewCatalog]] for tests. Tables and views share a single keyspace per
- * the [[TableViewCatalog]] contract; the stored value's runtime type ([[TableInfo]] vs
- * [[ViewInfo]]) is the kind discriminator. Also implements [[SupportsNamespaces]] with a
+ * An in-memory [[RelationCatalog]] for tests. Tables and views share a single keyspace per
+ * the [[RelationCatalog]] contract; the stored [[Relation]]'s runtime type ([[Table]] vs
+ * [[View]]) is the kind discriminator. Tables are stored as a [[DelegatingTable]] wrapping the
+ * [[TableInfo]] passed to `createTable`. Also implements [[SupportsNamespaces]] with a
* minimal namespace store, so analyzer rules that read namespace metadata (e.g.
* `ApplyDefaultCollation` consulting `loadNamespaceMetadata` for `PROP_COLLATION`) work
* uniformly with the v1 session catalog. Suitable for any test suite that wants to exercise
* v2 view DDL or inspection commands against a non-session catalog.
*/
-class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces {
+class InMemoryRelationCatalog extends RelationCatalog with SupportsNamespaces {
private val store =
- new ConcurrentHashMap[(Seq[String], String), TableInfo]()
+ new ConcurrentHashMap[(Seq[String], String), Relation]()
private val namespaces =
new ConcurrentHashMap[Seq[String], util.Map[String, String]]()
- override def loadTableOrView(ident: Identifier): Table = {
+ override def loadRelation(ident: Identifier): Relation = {
val key = (ident.namespace().toSeq, ident.name())
- Option(store.get(key))
- .map(new MetadataTable(_, ident.toString))
- .getOrElse(throw new NoSuchTableException(ident))
+ Option(store.get(key)).getOrElse(throw new NoSuchTableException(ident))
}
// ----- TableCatalog -----------------------------------------------------------------
override def createTable(ident: Identifier, info: TableInfo): Table = {
val key = (ident.namespace().toSeq, ident.name())
- if (store.putIfAbsent(key, info) != null) {
+ val table = new DelegatingTable(info, ident.toString)
+ if (store.putIfAbsent(key, table) != null) {
throw new TableAlreadyExistsException(ident)
}
- new MetadataTable(info, ident.toString)
+ table
}
override def alterTable(ident: Identifier, changes: TableChange*): Table = {
- throw new UnsupportedOperationException("alterTable not supported on InMemoryTableViewCatalog")
+ throw new UnsupportedOperationException("alterTable not supported on InMemoryRelationCatalog")
}
override def dropTable(ident: Identifier): Boolean = {
val key = (ident.namespace().toSeq, ident.name())
val existing = store.get(key)
- if (existing == null || existing.isInstanceOf[ViewInfo]) return false
+ if (existing == null || existing.isInstanceOf[View]) return false
store.remove(key) != null
}
@@ -73,7 +73,7 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
val oldKey = (oldIdent.namespace().toSeq, oldIdent.name())
val newKey = (newIdent.namespace().toSeq, newIdent.name())
val existing = store.get(oldKey)
- if (existing == null || existing.isInstanceOf[ViewInfo]) {
+ if (existing == null || existing.isInstanceOf[View]) {
throw new NoSuchTableException(oldIdent)
}
if (store.putIfAbsent(newKey, existing) != null) {
@@ -86,7 +86,7 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
val target = namespace.toSeq
val ids = new java.util.ArrayList[Identifier]()
store.forEach { (key, info) =>
- if (key._1 == target && !info.isInstanceOf[ViewInfo]) {
+ if (key._1 == target && !info.isInstanceOf[View]) {
ids.add(Identifier.of(key._1.toArray, key._2))
}
}
@@ -99,14 +99,14 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
val target = namespace.toSeq
val ids = new java.util.ArrayList[Identifier]()
store.forEach { (key, info) =>
- if (key._1 == target && info.isInstanceOf[ViewInfo]) {
+ if (key._1 == target && info.isInstanceOf[View]) {
ids.add(Identifier.of(key._1.toArray, key._2))
}
}
ids.toArray(new Array[Identifier](0))
}
- override def createView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def createView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
if (store.putIfAbsent(key, info) != null) {
throw new ViewAlreadyExistsException(ident)
@@ -114,10 +114,10 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
info
}
- override def replaceView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def replaceView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
val existing = store.get(key)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) {
+ if (existing == null || !existing.isInstanceOf[View]) {
throw new NoSuchViewException(ident)
}
store.put(key, info)
@@ -127,7 +127,7 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
override def dropView(ident: Identifier): Boolean = {
val key = (ident.namespace().toSeq, ident.name())
val existing = store.get(key)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) return false
+ if (existing == null || !existing.isInstanceOf[View]) return false
store.remove(key) != null
}
@@ -135,7 +135,7 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
val oldKey = (oldIdent.namespace().toSeq, oldIdent.name())
val newKey = (newIdent.namespace().toSeq, newIdent.name())
val existing = store.get(oldKey)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) {
+ if (existing == null || !existing.isInstanceOf[View]) {
throw new NoSuchViewException(oldIdent)
}
if (store.putIfAbsent(newKey, existing) != null) {
@@ -219,16 +219,16 @@ class InMemoryTableViewCatalog extends TableViewCatalog with SupportsNamespaces
// Test-only accessors --------------------------------------------------------------
/** Returns the stored entry (table or view) for the identifier, or throws if missing. */
- def getStoredInfo(namespace: Array[String], name: String): TableInfo = {
+ def getStoredInfo(namespace: Array[String], name: String): Relation = {
Option(store.get((namespace.toSeq, name))).getOrElse {
throw new NoSuchTableException(Identifier.of(namespace, name))
}
}
- /** Returns the stored ViewInfo, or throws if the entry is missing or is not a view. */
- def getStoredView(namespace: Array[String], name: String): ViewInfo = {
+ /** Returns the stored View, or throws if the entry is missing or is not a view. */
+ def getStoredView(namespace: Array[String], name: String): View = {
getStoredInfo(namespace, name) match {
- case v: ViewInfo => v
+ case v: View => v
case _ => throw new IllegalStateException(
s"stored entry at ${namespace.mkString(".")}.$name is not a view")
}
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala
index b7fa1f422364..969adc073186 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveSessionCatalog.scala
@@ -816,7 +816,7 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager)
object ResolvedViewIdentifier {
// Only matches session-catalog persistent views. Non-session-catalog persistent views
- // (produced for `MetadataTable`) fall through and are picked up by dedicated v2 strategy
+ // (produced for `DelegatingTable`) fall through and are picked up by dedicated v2 strategy
// cases in `DataSourceV2Strategy` -- AlterViewAs, SET/UNSET TBLPROPERTIES, ALTER VIEW ...
// WITH SCHEMA, RENAME TO, SHOW CREATE TABLE, SHOW TBLPROPERTIES, SHOW COLUMNS, DESCRIBE
// [COLUMN] all dispatch to v2 view execs that consume `ResolvedPersistentView.info`
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/DescribeRelationJsonCommand.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/DescribeRelationJsonCommand.scala
index 64317a04547a..8746fdbc9249 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/DescribeRelationJsonCommand.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/DescribeRelationJsonCommand.scala
@@ -33,7 +33,7 @@ import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.util.{quoteIfNeeded, DateTimeUtils, TimestampFormatter}
import org.apache.spark.sql.classic.ClassicConversions.castToImpl
-import org.apache.spark.sql.connector.catalog.{V1Table, V1ViewInfo}
+import org.apache.spark.sql.connector.catalog.{V1Table, V1View}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.types._
@@ -73,11 +73,11 @@ case class DescribeRelationJsonCommand(
}
// Resolve `v.info` to a `CatalogTable` so the JSON renderer below can read v1-shaped
// fields uniformly. Session-catalog views carry the original `CatalogTable` inside
- // `V1ViewInfo`; non-session v2 views carry a plain `ViewInfo` and are projected to a
+ // `V1View`; non-session v2 views carry a plain `View` and are projected to a
// `CatalogTable` via `V1Table.toCatalogTable`, the same conversion the
// `CreateTableLike` strategy case in `DataSourceV2Strategy` uses.
val metadata = v.info match {
- case v1Info: V1ViewInfo => v1Info.v1Table
+ case v1Info: V1View => v1Info.v1Table
case info => V1Table.toCatalogTable(v.catalog, v.identifier, info)
}
describeIdentifier(v.identifier.toQualifiedNameParts(v.catalog), jsonMap)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowTablesJsonCommand.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowTablesJsonCommand.scala
index 7c3ed1564e44..0dfc31705ae6 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowTablesJsonCommand.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowTablesJsonCommand.scala
@@ -28,7 +28,7 @@ import org.apache.spark.sql.catalyst.analysis.ResolvedNamespace
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.util.StringUtils
-import org.apache.spark.sql.connector.catalog.{CatalogV2Util, TableCatalog, TableViewCatalog}
+import org.apache.spark.sql.connector.catalog.{CatalogV2Util, RelationCatalog, TableCatalog}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
import org.apache.spark.sql.types.{MetadataBuilder, StringType}
@@ -109,8 +109,8 @@ case class ShowTablesJsonCommand(
ns: Seq[String]): JObject = {
val identifiers = if (!isExtended) {
catalog match {
- case mc: TableViewCatalog =>
- mc.listTableAndViewSummaries(ns.toArray).map(_.identifier())
+ case mc: RelationCatalog =>
+ mc.listRelationSummaries(ns.toArray).map(_.identifier())
case _ => catalog.listTables(ns.toArray)
}
} else {
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
index e0a4922efe9e..df050742ec66 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala
@@ -39,7 +39,7 @@ import org.apache.spark.sql.catalyst.types.DataTypeUtils
import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIfNeeded, CaseInsensitiveMap, CharVarcharUtils, DateTimeUtils, ResolveDefaultColumns}
import org.apache.spark.sql.catalyst.util.ResolveDefaultColumns.CURRENT_DEFAULT_COLUMN_METADATA_KEY
import org.apache.spark.sql.classic.ClassicConversions.castToImpl
-import org.apache.spark.sql.connector.catalog.{TableCatalog, V1Table, V1ViewInfo}
+import org.apache.spark.sql.connector.catalog.{TableCatalog, V1Table, V1View}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.TableIdentifierHelper
import org.apache.spark.sql.errors.{QueryCompilationErrors, QueryExecutionErrors}
import org.apache.spark.sql.execution.CommandExecutionMode
@@ -590,9 +590,9 @@ object ResolvedChildHelper {
val catalog = sparkSession.sessionState.catalog
child match {
case ResolvedTempView(_, metadata) => metadata
- // v1 inspection commands always see a v1 (`V1ViewInfo`) view here -- the v2 strategy
+ // v1 inspection commands always see a v1 (`V1View`) view here -- the v2 strategy
// handles non-session views before this method is reached.
- case ResolvedPersistentView(_, _, info: V1ViewInfo) => info.v1Table
+ case ResolvedPersistentView(_, _, info: V1View) => info.v1Table
case ResolvedTable(_, _, t: V1Table, _) => t.v1Table
case _ if (catalog.isTempView(table)) =>
catalog.getTempViewOrPermanentTableMetadata(table)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewExec.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewExec.scala
index 2309cb31b5eb..3afed35d894b 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewExec.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/AlterV2ViewExec.scala
@@ -23,12 +23,12 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{ResolvedIdentifier, SchemaEvolution, ViewSchemaMode}
import org.apache.spark.sql.catalyst.catalog.CatalogTable
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
-import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, TableCatalog, ViewCatalog, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, TableCatalog, View, ViewCatalog}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.{IdentifierHelper, MultipartIdentifierHelper}
import org.apache.spark.sql.execution.command.CommandUtils
/**
- * Shared bits for the v2 ALTER VIEW ... AS exec. The replacement [[ViewInfo]] is constructed by
+ * Shared bits for the v2 ALTER VIEW ... AS exec. The replacement [[View]] is constructed by
* [[V2ViewPreparation.buildViewInfo]]; the existing view's payload is provided at analysis time
* via the `existingView` field so we can preserve user-set TBLPROPERTIES, comment, collation,
* owner, and schema binding mode without re-loading at runtime.
@@ -40,7 +40,7 @@ import org.apache.spark.sql.execution.command.CommandUtils
* propagates.
*/
private[v2] trait V2AlterViewPreparation extends V2ViewPreparation {
- protected def existingView: ViewInfo
+ protected def existingView: View
protected lazy val existingProps: Map[String, String] =
existingView.properties.asScala.toMap
@@ -53,13 +53,13 @@ private[v2] trait V2AlterViewPreparation extends V2ViewPreparation {
override def collation: Option[String] = existingProp(TableCatalog.PROP_COLLATION)
// Preserve the existing view's owner (v1-parity with AlterViewAsCommand's viewMeta.copy,
// which leaves `owner` untouched). If the existing view has no PROP_OWNER, pass it through
- // as None so the replacement ViewInfo also has no owner.
+ // as None so the replacement View also has no owner.
override def owner: Option[String] = existingProp(TableCatalog.PROP_OWNER)
override def userProperties: Map[String, String] = existingProps
// Preserve the existing view's schema binding mode. Reuse `viewSchemaModeFromProperties`
// for a v1-identical decode -- it honors `viewSchemaBindingEnabled` and defaults missing
- // values to SchemaBinding. We feed the typed `ViewInfo.schemaMode` String in via a
+ // values to SchemaBinding. We feed the typed `View.schemaMode` String in via a
// single-key map so the decode logic stays in one place.
override def viewSchemaMode: ViewSchemaMode =
CatalogTable.viewSchemaModeFromProperties(
@@ -75,7 +75,7 @@ private[v2] trait V2AlterViewPreparation extends V2ViewPreparation {
case class AlterV2ViewExec(
catalog: ViewCatalog,
identifier: Identifier,
- existingView: ViewInfo,
+ existingView: View,
originalText: String,
query: LogicalPlan) extends V2AlterViewPreparation {
@@ -96,7 +96,7 @@ case class AlterV2ViewExec(
case class AlterV2ViewSetPropertiesExec(
catalog: ViewCatalog,
identifier: Identifier,
- existingView: ViewInfo,
+ existingView: View,
properties: Map[String, String]) extends LeafV2CommandExec {
override def output: Seq[org.apache.spark.sql.catalyst.expressions.Attribute] = Seq.empty
@@ -124,7 +124,7 @@ case class AlterV2ViewSetPropertiesExec(
case class AlterV2ViewUnsetPropertiesExec(
catalog: ViewCatalog,
identifier: Identifier,
- existingView: ViewInfo,
+ existingView: View,
propertyKeys: Seq[String]) extends LeafV2CommandExec {
override def output: Seq[org.apache.spark.sql.catalyst.expressions.Attribute] = Seq.empty
@@ -152,7 +152,7 @@ case class AlterV2ViewUnsetPropertiesExec(
case class AlterV2ViewSchemaBindingExec(
catalog: ViewCatalog,
identifier: Identifier,
- existingView: ViewInfo,
+ existingView: View,
viewSchemaMode: ViewSchemaMode) extends LeafV2CommandExec {
override def output: Seq[org.apache.spark.sql.catalyst.expressions.Attribute] = Seq.empty
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateV2ViewExec.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateV2ViewExec.scala
index 4e10c7d3ab28..2781ca4528c5 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateV2ViewExec.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/CreateV2ViewExec.scala
@@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.analysis.{ResolvedIdentifier, SchemaEvoluti
import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.util.CharVarcharUtils
-import org.apache.spark.sql.connector.catalog.{DependencyList, Identifier, TableCatalog, ViewCatalog, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{DependencyList, Identifier, TableCatalog, View, ViewCatalog}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.IdentifierHelper
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.execution.command.{CommandUtils, ViewHelper}
@@ -33,7 +33,7 @@ import org.apache.spark.sql.util.SchemaUtils
import org.apache.spark.util.ArrayImplicits._
/**
- * Shared validation + ViewInfo construction for v2 CREATE VIEW / ALTER VIEW execs.
+ * Shared validation + View construction for v2 CREATE VIEW / ALTER VIEW execs.
*
* Mirrors the persistent-view portion of v1 [[ViewHelper.prepareTable]] + the execution-time
* checks in [[org.apache.spark.sql.execution.command.CreateViewCommand.run]]. Post-analysis
@@ -57,7 +57,7 @@ private[v2] trait V2ViewPreparation extends LeafV2CommandExec {
protected lazy val fullNameParts: Seq[String] =
(catalog.name() +: identifier.asMultipartIdentifier).toSeq
- /** Optional structured dependency list to stamp on the built `ViewInfo`. */
+ /** Optional structured dependency list to stamp on the built `View`. */
protected def viewDependencies: Option[DependencyList] = None
/** Optional view sub-kind to stamp on `PROP_TABLE_TYPE`; defaults to `VIEW` when `None`. */
@@ -74,7 +74,7 @@ private[v2] trait V2ViewPreparation extends LeafV2CommandExec {
override def output: Seq[Attribute] = Seq.empty
- protected def buildViewInfo(): ViewInfo = {
+ protected def buildViewInfo(): View = {
import ViewHelper._
if (userSpecifiedColumns.nonEmpty) {
@@ -107,7 +107,7 @@ private[v2] trait V2ViewPreparation extends LeafV2CommandExec {
query.output.map(_.name).toArray
}
- val builder = new ViewInfo.Builder()
+ val builder = new View.Builder()
.withSchema(aliasedSchema)
.withProperties(userProperties.asJava)
.withQueryText(originalText)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
index c6661488cae5..9c745461b170 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DataSourceV2Strategy.scala
@@ -34,7 +34,7 @@ import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.trees.TreePattern.SCALAR_SUBQUERY
import org.apache.spark.sql.catalyst.util.{quoteIfNeeded, toPrettySQL, GeneratedColumn, IdentityColumn, ResolveDefaultColumns, ResolveTableConstraints, V2ExpressionBuilder}
import org.apache.spark.sql.classic.SparkSession
-import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Dependency, DependencyList, Identifier, StagingTableCatalog, SupportsDeleteV2, SupportsNamespaces, SupportsPartitionManagement, SupportsWrite, TableCapability, TableCatalog, TableSummary, TruncatableTable, V1Table, V1ViewInfo, ViewCatalog}
+import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Dependency, DependencyList, Identifier, StagingTableCatalog, SupportsDeleteV2, SupportsNamespaces, SupportsPartitionManagement, SupportsWrite, TableCapability, TableCatalog, TableSummary, TruncatableTable, V1Table, V1View, ViewCatalog}
import org.apache.spark.sql.connector.catalog.TableChange
import org.apache.spark.sql.connector.catalog.index.SupportsIndex
import org.apache.spark.sql.connector.expressions.{FieldReference, LiteralValue}
@@ -105,10 +105,10 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
}
// Strategy cases that target v2 views read `ResolvedPersistentView.info` directly. For
- // session-catalog (v1) views the payload is a `V1ViewInfo` wrapping the original
- // `CatalogTable`; v2 catalogs supply a regular `ViewInfo` from the catalog.
+ // session-catalog (v1) views the payload is a `V1View` wrapping the original
+ // `CatalogTable`; v2 catalogs supply a regular `View` from the catalog.
// `ResolveSessionCatalog` rewrites session-catalog views to v1 commands before this strategy
- // fires, so v2 cases that don't expect a `V1ViewInfo` won't see one.
+ // fires, so v2 cases that don't expect a `V1View` won't see one.
private def qualifyLocInTableSpec(tableSpec: TableSpec): TableSpec = {
val newLoc = tableSpec.location.map { loc =>
@@ -268,13 +268,13 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
// Views are wrapped in V1Table so the exec can extract schema and provider uniformly --
// session-catalog (v1) views unwrap to their original `CatalogTable`; non-session v2
// views go through `V1Table.toCatalogTable` to synthesize an equivalent `CatalogTable`
- // from the resolved `ViewInfo`.
+ // from the resolved `View`.
case CreateTableLike(
ResolvedIdentifier(catalog, ident), source,
locationStr, provider, serdeInfo, properties, ifNotExists) =>
val table = source match {
case ResolvedTable(_, _, t, _) => t
- case ResolvedPersistentView(_, _, info: V1ViewInfo) => V1Table(info.v1Table)
+ case ResolvedPersistentView(_, _, info: V1View) => V1Table(info.v1Table)
case rpv @ ResolvedPersistentView(viewCatalog, viewIdent, _) =>
V1Table(V1Table.toCatalogTable(viewCatalog, viewIdent, rpv.info))
case ResolvedTempView(_, meta) => V1Table(meta)
@@ -364,7 +364,7 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
// View DDL / inspection on a non-session v2 catalog that the v1 rewrite in
// `ResolveSessionCatalog` can't handle (its `ResolvedViewIdentifier` matcher is gated on
- // `isSessionCatalog`). Routed to dedicated v2 execs that read the typed `ViewInfo`
+ // `isSessionCatalog`). Routed to dedicated v2 execs that read the typed `View`
// resolved at analysis time directly from `ResolvedPersistentView.info` -- no re-loading
// at exec time.
case SetViewProperties(rpv @ ResolvedPersistentView(catalog, ident, _), props) =>
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowTablesExec.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowTablesExec.scala
index 8680785e0815..cb21e7056921 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowTablesExec.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowTablesExec.scala
@@ -22,15 +22,15 @@ import scala.collection.mutable.ArrayBuffer
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.catalyst.util.StringUtils
-import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, TableCatalog, TableViewCatalog}
+import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, RelationCatalog, TableCatalog}
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits.NamespaceHelper
import org.apache.spark.sql.execution.LeafExecNode
/**
* Physical plan node for showing tables.
*
- * For a [[TableViewCatalog]] (one that exposes both tables and views in a shared identifier
- * namespace), this routes through [[TableViewCatalog#listTableAndViewSummaries]] so that views are
+ * For a [[RelationCatalog]] (one that exposes both tables and views in a shared identifier
+ * namespace), this routes through [[RelationCatalog#listRelationSummaries]] so that views are
* included in the listing -- matching the v1 `SHOW TABLES` semantics where views appear
* alongside tables. Pure [[TableCatalog]] catalogs continue to use `listTables` and return
* tables only.
@@ -44,8 +44,8 @@ case class ShowTablesExec(
val rows = new ArrayBuffer[InternalRow]()
val identifiers: Array[Identifier] = catalog match {
- case mc: TableViewCatalog =>
- mc.listTableAndViewSummaries(namespace.toArray).map(_.identifier())
+ case mc: RelationCatalog =>
+ mc.listRelationSummaries(namespace.toArray).map(_.identifier())
case _ => catalog.listTables(namespace.toArray)
}
identifiers.foreach { ident =>
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ViewInspectionExecs.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ViewInspectionExecs.scala
index d1ceeba833ea..2bf4664bc474 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ViewInspectionExecs.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ViewInspectionExecs.scala
@@ -24,11 +24,11 @@ import org.apache.spark.sql.catalyst.{InternalRow, SQLConfHelper}
import org.apache.spark.sql.catalyst.expressions.Attribute
import org.apache.spark.sql.catalyst.util.{escapeSingleQuotedString, quoteIfNeeded, ResolveDefaultColumns}
import org.apache.spark.sql.catalyst.util.ResolveDefaultColumnsUtils.CURRENT_DEFAULT_COLUMN_METADATA_KEY
-import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, TableCatalog, TableSummary, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{CatalogV2Util, Identifier, TableCatalog, TableSummary, View}
import org.apache.spark.sql.errors.QueryCompilationErrors
/**
- * Read-side v2 view execs. Each receives the typed [[ViewInfo]] resolved at analysis time
+ * Read-side v2 view execs. Each receives the typed [[View]] resolved at analysis time
* (carried on `ResolvedPersistentView.info`) and formats output rows directly from it --
* matching the way v2 table inspection execs (e.g. `ShowCreateTableExec`, `DescribeTableExec`)
* consume the [[org.apache.spark.sql.connector.catalog.Table]] attached to `ResolvedTable`.
@@ -40,15 +40,15 @@ import org.apache.spark.sql.errors.QueryCompilationErrors
/**
* Physical plan node for SHOW CREATE TABLE on a v2 view. Reconstructs the {@code CREATE VIEW}
- * statement directly from the typed [[ViewInfo]] -- the column list comes from
- * [[ViewInfo#schema]], the body from [[ViewInfo#queryText]], the binding mode from
- * [[ViewInfo#schemaMode]], and the user TBLPROPERTIES from [[ViewInfo#properties]] (with the
+ * statement directly from the typed [[View]] -- the column list comes from
+ * [[View#schema]], the body from [[View#queryText]], the binding mode from
+ * [[View#schemaMode]], and the user TBLPROPERTIES from [[View#properties]] (with the
* reserved-keys filter applied so internal entries don't leak into the rendered DDL).
*/
case class ShowCreateV2ViewExec(
output: Seq[Attribute],
quotedName: String,
- viewInfo: ViewInfo) extends LeafV2CommandExec with SQLConfHelper {
+ viewInfo: View) extends LeafV2CommandExec with SQLConfHelper {
override protected def run(): Seq[InternalRow] = {
val builder = new StringBuilder
@@ -99,7 +99,7 @@ case class ShowCreateV2ViewExec(
/**
* Physical plan node for SHOW TBLPROPERTIES on a v2 view. Returns the user-facing properties
- * from [[ViewInfo#properties]] -- reserved first-class keys (PROP_COMMENT, PROP_COLLATION,
+ * from [[View#properties]] -- reserved first-class keys (PROP_COMMENT, PROP_COLLATION,
* PROP_OWNER, PROP_TABLE_TYPE, ...) are filtered out so users see only what they (or the
* catalog) explicitly set, matching v1 `SHOW TBLPROPERTIES` on a session-catalog view (which
* hides these because v1 stores them in typed `CatalogTable` fields rather than `properties`).
@@ -108,7 +108,7 @@ case class ShowCreateV2ViewExec(
case class ShowV2ViewPropertiesExec(
output: Seq[Attribute],
quotedName: String,
- viewInfo: ViewInfo,
+ viewInfo: View,
propertyKey: Option[String]) extends LeafV2CommandExec with SQLConfHelper {
override protected def run(): Seq[InternalRow] = {
@@ -133,11 +133,11 @@ case class ShowV2ViewPropertiesExec(
/**
* Physical plan node for SHOW COLUMNS on a v2 view. Returns one row per top-level field in
- * [[ViewInfo#schema]].
+ * [[View#schema]].
*/
case class ShowV2ViewColumnsExec(
output: Seq[Attribute],
- viewInfo: ViewInfo) extends LeafV2CommandExec {
+ viewInfo: View) extends LeafV2CommandExec {
override protected def run(): Seq[InternalRow] = {
viewInfo.schema.map(c => toCatalystRow(c.name)).toSeq
@@ -157,7 +157,7 @@ case class DescribeV2ViewExec(
output: Seq[Attribute],
catalogName: String,
identifier: Identifier,
- viewInfo: ViewInfo,
+ viewInfo: View,
isExtended: Boolean) extends DescribeIdentifierRows with SQLConfHelper {
override protected def run(): Seq[InternalRow] = {
@@ -170,7 +170,7 @@ case class DescribeV2ViewExec(
result += toCatalystRow("# Detailed View Information", "", "")
addIdentifierRows(result, catalogName, identifier, entityLabel = "View")
// Surface the view sub-kind so users see whether they're looking at a plain VIEW
- // or a sub-kind like METRIC_VIEW. `ViewInfo`'s constructor unconditionally stamps
+ // or a sub-kind like METRIC_VIEW. `View`'s constructor unconditionally stamps
// `PROP_TABLE_TYPE` (defaulting to `VIEW`), so this row is always present and
// matches v1 `CatalogTable.toJsonLinkedHashMap`'s `Type` row for parity.
result += toCatalystRow(
@@ -235,7 +235,7 @@ case class DescribeV2ViewExec(
*/
case class DescribeV2ViewColumnExec(
output: Seq[Attribute],
- viewInfo: ViewInfo,
+ viewInfo: View,
colNameParts: Seq[String],
isExtended: Boolean) extends LeafV2CommandExec with SQLConfHelper {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataTableSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataTableSuite.scala
index 42fa148106df..3a7e5322d620 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataTableSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataTableSuite.scala
@@ -20,14 +20,14 @@ package org.apache.spark.sql.connector
import org.apache.spark.SparkConf
import org.apache.spark.sql.Row
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
-import org.apache.spark.sql.connector.catalog.{Identifier, MetadataTable, Table, TableCatalog, TableChange, TableInfo, TableSummary}
+import org.apache.spark.sql.connector.catalog.{DelegatingTable, Identifier, Table, TableCatalog, TableChange, TableInfo, TableSummary}
import org.apache.spark.sql.connector.expressions.LogicalExpressions
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.util.CaseInsensitiveStringMap
/**
- * Tests for the data-source-table side of [[MetadataTable]]: a v2 catalog returns
+ * Tests for the data-source-table side of [[DelegatingTable]]: a v2 catalog returns
* metadata-only tables and Spark reads / writes them via the V1 data-source path.
* View-related paths live in [[DataSourceV2MetadataViewSuite]].
*/
@@ -111,7 +111,7 @@ class DataSourceV2MetadataTableSuite extends SharedSparkSession {
}
/**
- * A read-only [[TableCatalog]] that returns [[MetadataTable]] for a small set of canned
+ * A read-only [[TableCatalog]] that returns [[DelegatingTable]] for a small set of canned
* table fixtures. Used to drive the data-source-table read path (file source + v2 provider)
* through Spark's V1 data-source machinery.
*/
@@ -124,7 +124,7 @@ class TestingDataSourceTableCatalog extends TableCatalog {
.withLocation(ident.namespace().head)
.withTableType(TableSummary.EXTERNAL_TABLE_TYPE)
.build()
- new MetadataTable(info, ident.toString)
+ new DelegatingTable(info, ident.toString)
case "test_partitioned_json" =>
val partitioning = LogicalExpressions.identity(LogicalExpressions.reference(Seq("c2")))
val info = new TableInfo.Builder()
@@ -134,13 +134,13 @@ class TestingDataSourceTableCatalog extends TableCatalog {
.withTableType(TableSummary.EXTERNAL_TABLE_TYPE)
.withPartitions(Array(partitioning))
.build()
- new MetadataTable(info, ident.toString)
+ new DelegatingTable(info, ident.toString)
case "test_v2" =>
val info = new TableInfo.Builder()
.withSchema(FakeV2Provider.schema)
.withProvider(classOf[FakeV2Provider].getName)
.build()
- new MetadataTable(info, ident.toString)
+ new DelegatingTable(info, ident.toString)
case _ => throw new NoSuchTableException(ident)
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataViewSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataViewSuite.scala
index 969ebb540ae6..a80b2e0c21d7 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataViewSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataViewSuite.scala
@@ -20,21 +20,21 @@ package org.apache.spark.sql.connector
import org.apache.spark.SparkConf
import org.apache.spark.sql.{AnalysisException, Row}
import org.apache.spark.sql.catalyst.analysis.{NoSuchTableException, NoSuchViewException, TableAlreadyExistsException, ViewAlreadyExistsException}
-import org.apache.spark.sql.connector.catalog.{Identifier, MetadataTable, Table, TableCatalog, TableChange, TableInfo, TableSummary, TableViewCatalog, V1Table, ViewCatalog, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{DelegatingTable, Identifier, Relation, RelationCatalog, Table, TableCatalog, TableChange, TableInfo, TableSummary, V1Table, View, ViewCatalog}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.util.CaseInsensitiveStringMap
/**
- * Tests for the view side of [[MetadataTable]]: view-text expansion on read, and
+ * Tests for the view side of [[DelegatingTable]]: view-text expansion on read, and
* CREATE VIEW / ALTER VIEW ... AS going through the v2 write path
* (`CreateV2ViewExec` / `AlterV2ViewExec`). View writes route through
* [[ViewCatalog#createView]] / [[ViewCatalog#replaceView]].
* Data-source-table read paths live in
* [[org.apache.spark.sql.connector.DataSourceV2MetadataTableSuite]].
*
- * TODO: register a `MetadataTable`-backed `DelegatingCatalogExtension` as
+ * TODO: register a `DelegatingTable`-backed `DelegatingCatalogExtension` as
* `spark.sql.catalog.spark_catalog` and run the shared
* [[org.apache.spark.sql.execution.PersistedViewTestSuite]] body against the v2 path for full
* parity with the v1 persisted-view coverage.
@@ -43,7 +43,7 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
import testImplicits._
override def sparkConf: SparkConf = super.sparkConf
- .set("spark.sql.catalog.view_catalog", classOf[TestingTableViewCatalog].getName)
+ .set("spark.sql.catalog.view_catalog", classOf[TestingRelationCatalog].getName)
// --- View read path -----------------------------------------------------
@@ -71,54 +71,52 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
// End-to-end coverage of the v2 encoder -> parser round-trip: test_unqualified_multi is a
// view whose captured catalog+namespace is view_catalog.ns1.ns2 (two-part namespace) and
// whose body references `t` unqualified. At read time the unqualified `t` must expand to
- // view_catalog.ns1.ns2.t via the captured context -- which TestingTableViewCatalog resolves to
+ // view_catalog.ns1.ns2.t via the captured context -- which TestingRelationCatalog resolves to
// its own `t` fixture at that namespace.
checkAnswer(
spark.table("view_catalog.outer_ns.test_unqualified_multi"),
Row("multi"))
}
- // --- ViewInfo unit tests -----------------------------------------------
+ // --- View unit tests -----------------------------------------------
test("multi-part captured namespace round-trips through V1Table.toCatalogTable") {
- // (a) ViewInfo.Builder stores (cat, Array(db1, db2)) as typed fields.
+ // (a) View.Builder stores (cat, Array(db1, db2)) as typed fields.
// (b) V1Table.toCatalogTable reads them directly and emits v1's numbered
// view.catalogAndNamespace.* keys so (c) the resulting CatalogTable's
// `viewCatalogAndNamespace` exposes the full (cat, db1, db2), which is what the v1
// view-resolution path consumes to expand unqualified references in the view body.
- val info = new ViewInfo.Builder()
+ val info = new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT col FROM t")
.withCurrentCatalog("my_cat")
.withCurrentNamespace(Array("db1", "db2"))
.build()
- val motTable = new MetadataTable(info, "v")
// Any CatalogPlugin works here; toCatalogTable only reads `catalog.name()`.
val catalog = spark.sessionState.catalogManager.catalog("view_catalog")
val ct = V1Table.toCatalogTable(
- catalog, Identifier.of(Array("ns"), "v"), motTable)
+ catalog, Identifier.of(Array("ns"), "v"), info)
assert(ct.viewCatalogAndNamespace == Seq("my_cat", "db1", "db2"))
// Namespace parts containing dots flow through structurally (no string encoding).
- val infoWeird = new ViewInfo.Builder()
+ val infoWeird = new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT col FROM t")
.withCurrentCatalog("my_cat")
.withCurrentNamespace(Array("weird.db", "normal"))
.build()
val ctWeird = V1Table.toCatalogTable(
- catalog, Identifier.of(Array("ns"), "v"), new MetadataTable(infoWeird, "v"))
+ catalog, Identifier.of(Array("ns"), "v"), infoWeird)
assert(ctWeird.viewCatalogAndNamespace == Seq("my_cat", "weird.db", "normal"))
}
test("view with no captured catalog omits viewCatalogAndNamespace") {
- val info = new ViewInfo.Builder()
+ val info = new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT * FROM spark_catalog.default.t")
.build()
- val motTable = new MetadataTable(info, "v")
val catalog = spark.sessionState.catalogManager.catalog("view_catalog")
- val ct = V1Table.toCatalogTable(catalog, Identifier.of(Array("ns"), "v"), motTable)
+ val ct = V1Table.toCatalogTable(catalog, Identifier.of(Array("ns"), "v"), info)
assert(ct.viewCatalogAndNamespace.isEmpty)
}
@@ -209,7 +207,7 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
// `unsupportedCreateOrReplaceViewOnTableError`. Pre-seed a non-view entry at a
// multi-level-namespace identifier to exercise the rendering.
val catalog = spark.sessionState.catalogManager.catalog("view_catalog")
- .asInstanceOf[TestingTableViewCatalog]
+ .asInstanceOf[TestingRelationCatalog]
val tblIdent = Identifier.of(Array("ns1", "inner"), "t_err")
catalog.createTable(
tblIdent,
@@ -347,7 +345,7 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
test("DESCRIBE TABLE EXTENDED ... AS JSON on a v2 view succeeds") {
// `DescribeRelationJsonCommand` is a v1 runnable command that reads v1-shaped fields off
// a `CatalogTable`. For non-session v2 views the resolved `ResolvedPersistentView.info`
- // is a plain `ViewInfo`; the command projects it to a `CatalogTable` via
+ // is a plain `View`; the command projects it to a `CatalogTable` via
// `V1Table.toCatalogTable` so DESC ... AS JSON works uniformly across session and
// non-session view catalogs.
seedV2View("v_desc_json")
@@ -366,7 +364,7 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
private def seedV2Table(name: String): Unit = {
val catalog = spark.sessionState.catalogManager.catalog("view_catalog")
- .asInstanceOf[TestingTableViewCatalog]
+ .asInstanceOf[TestingRelationCatalog]
catalog.createTable(
Identifier.of(Array("default"), name),
new TableInfo.Builder()
@@ -375,9 +373,9 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
.build())
}
- test("SHOW TABLES on a TableViewCatalog returns both tables and views (v1-parity)") {
- // For a `TableViewCatalog` (a catalog exposing both tables and views in a shared
- // identifier namespace), SHOW TABLES routes through `listTableAndViewSummaries` so views
+ test("SHOW TABLES on a RelationCatalog returns both tables and views (v1-parity)") {
+ // For a `RelationCatalog` (a catalog exposing both tables and views in a shared
+ // identifier namespace), SHOW TABLES routes through `listRelationSummaries` so views
// appear alongside tables -- matching the v1 SHOW TABLES output. Pure `TableCatalog`
// catalogs (no view mixin) continue to use `listTables` and return tables only.
seedV2View("v_in_show_tables")
@@ -394,29 +392,29 @@ class DataSourceV2MetadataViewSuite extends SharedSparkSession {
}
/**
- * A [[TableViewCatalog]]: round-trips [[MetadataTable]] for created views and tables and
+ * A [[RelationCatalog]]: round-trips [[DelegatingTable]] for created views and tables and
* exposes a few canned read-only view fixtures (`test_view`, `test_unqualified_view`,
* `test_unqualified_multi`, plus an unqualified-target view at `ns1.ns2.t`) used by the
* view-read tests. Entries created via `createTable` / `createView` are distinguished by the
- * stored value's runtime type (ViewInfo vs TableInfo). The single-RPC perf entry point
- * [[loadTableOrView]] returns either kind; [[loadTable]] is tables-only per the
+ * stored [[Relation]]'s runtime type (View vs Table). The single-RPC perf entry point
+ * [[loadRelation]] returns either kind; [[loadTable]] is tables-only per the
* [[TableCatalog#loadTable]] contract.
*/
-class TestingTableViewCatalog extends TableViewCatalog {
+class TestingRelationCatalog extends RelationCatalog {
// Holds entries (views and tables) created via createTable / createView within the session.
- // Keyed by (namespace, name); the stored value's runtime type (ViewInfo vs TableInfo)
- // distinguishes views from tables. Mixed-catalog: shared identifier namespace per the
- // TableViewCatalog contract.
+ // Keyed by (namespace, name); the stored [[Relation]]'s runtime type (View vs Table)
+ // distinguishes views from tables. Tables are stored as a DelegatingTable wrapping the
+ // TableInfo. Mixed-catalog: shared identifier namespace per the RelationCatalog contract.
private val createdViews =
- new java.util.concurrent.ConcurrentHashMap[(Seq[String], String), TableInfo]()
+ new java.util.concurrent.ConcurrentHashMap[(Seq[String], String), Relation]()
- // Canned read-only view fixtures, exposed only via the perf path (loadTableOrView). loadView
- // does not need to expose them because the resolver routes TableViewCatalog reads through
- // loadTableOrView.
- private def fixtureView(ident: Identifier): Option[ViewInfo] = ident.name() match {
+ // Canned read-only view fixtures, exposed only via the perf path (loadRelation). loadView
+ // does not need to expose them because the resolver routes RelationCatalog reads through
+ // loadRelation.
+ private def fixtureView(ident: Identifier): Option[View] = ident.name() match {
case "test_view" =>
- Some(new ViewInfo.Builder()
+ Some(new View.Builder()
.withSchema(new StructType().add("col", "string").add("i", "int"))
.withQueryText(
"SELECT col, col::int AS i FROM spark_catalog.default.t WHERE col = 'b'")
@@ -424,7 +422,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
SQLConf.ANSI_ENABLED.key, (ident.namespace().head == "ansi").toString))
.build())
case "test_unqualified_view" =>
- Some(new ViewInfo.Builder()
+ Some(new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT col FROM t WHERE col = 'b'")
.withCurrentCatalog("spark_catalog")
@@ -434,7 +432,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
// View whose captured catalog+namespace is view_catalog.ns1.ns2 (two-part). The
// unqualified `t` in the body must resolve via that captured context to
// view_catalog.ns1.ns2.t, which this catalog also serves (see `t` case below).
- Some(new ViewInfo.Builder()
+ Some(new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT col FROM t")
.withCurrentCatalog("view_catalog")
@@ -443,22 +441,21 @@ class TestingTableViewCatalog extends TableViewCatalog {
case "t" if ident.namespace().toSeq == Seq("ns1", "ns2") =>
// Target of test_unqualified_multi's unqualified reference. Self-contained view so
// the test doesn't need external data.
- Some(new ViewInfo.Builder()
+ Some(new View.Builder()
.withSchema(new StructType().add("col", "string"))
.withQueryText("SELECT 'multi' AS col")
.build())
case _ => None
}
- override def loadTableOrView(ident: Identifier): Table = {
- // Single-RPC perf path: returns tables AND views (as MetadataTable). Stored entries
- // win over fixture views (the fixture namespace is read-only and disjoint from
- // createdViews in practice). loadTable, loadView, tableExists, viewExists all derive
- // from this via the TableViewCatalog default impls.
+ override def loadRelation(ident: Identifier): Relation = {
+ // Single-RPC perf path: returns tables AND views. Stored entries win over fixture views
+ // (the fixture namespace is read-only and disjoint from createdViews in practice).
+ // loadTable, loadView, tableExists, viewExists all derive from this via the
+ // RelationCatalog default impls.
val key = (ident.namespace().toSeq, ident.name())
Option(createdViews.get(key))
.orElse(fixtureView(ident))
- .map(new MetadataTable(_, ident.toString))
.getOrElse(throw new NoSuchTableException(ident))
}
@@ -467,23 +464,24 @@ class TestingTableViewCatalog extends TableViewCatalog {
// TableAlreadyExistsException. The shared `createdViews` keyspace makes `putIfAbsent`
// throw uniformly for both table-at-ident and view-at-ident collisions.
val key = (ident.namespace().toSeq, ident.name())
- if (createdViews.putIfAbsent(key, info) != null) {
+ val table = new DelegatingTable(info, ident.toString)
+ if (createdViews.putIfAbsent(key, table) != null) {
throw new TableAlreadyExistsException(ident)
}
- new MetadataTable(info, ident.toString)
+ table
}
- /** Test-only accessor: returns the stored TableInfo (table or view) for the identifier. */
- def getStoredInfo(namespace: Array[String], name: String): TableInfo = {
+ /** Test-only accessor: returns the stored Relation (table or view) for the identifier. */
+ def getStoredInfo(namespace: Array[String], name: String): Relation = {
Option(createdViews.get((namespace.toSeq, name))).getOrElse {
throw new NoSuchTableException(Identifier.of(namespace, name))
}
}
- /** Test-only accessor: returns the stored ViewInfo; fails if the entry is not a view. */
- def getStoredView(namespace: Array[String], name: String): ViewInfo = getStoredInfo(
+ /** Test-only accessor: returns the stored View; fails if the entry is not a view. */
+ def getStoredView(namespace: Array[String], name: String): View = getStoredInfo(
namespace, name) match {
- case v: ViewInfo => v
+ case v: View => v
case _ => throw new IllegalStateException(
s"stored entry at ${namespace.mkString(".")}.$name is not a view")
}
@@ -494,7 +492,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
override def dropTable(ident: Identifier): Boolean = {
val key = (ident.namespace().toSeq, ident.name())
val existing = createdViews.get(key)
- if (existing == null || existing.isInstanceOf[ViewInfo]) return false
+ if (existing == null || existing.isInstanceOf[View]) return false
createdViews.remove(key) != null
}
override def renameTable(oldIdent: Identifier, newIdent: Identifier): Unit = {
@@ -505,7 +503,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
val targetNs = namespace.toSeq
val ids = new java.util.ArrayList[Identifier]()
createdViews.forEach { (key, info) =>
- if (key._1 == targetNs && !info.isInstanceOf[ViewInfo]) {
+ if (key._1 == targetNs && !info.isInstanceOf[View]) {
ids.add(Identifier.of(key._1.toArray, key._2))
}
}
@@ -518,14 +516,14 @@ class TestingTableViewCatalog extends TableViewCatalog {
val targetNs = namespace.toSeq
val ids = new java.util.ArrayList[Identifier]()
createdViews.forEach { (key, info) =>
- if (key._1 == targetNs && info.isInstanceOf[ViewInfo]) {
+ if (key._1 == targetNs && info.isInstanceOf[View]) {
ids.add(Identifier.of(key._1.toArray, key._2))
}
}
ids.toArray(new Array[Identifier](0))
}
- override def createView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def createView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
if (createdViews.putIfAbsent(key, info) != null) {
throw new ViewAlreadyExistsException(ident)
@@ -533,10 +531,10 @@ class TestingTableViewCatalog extends TableViewCatalog {
info
}
- override def replaceView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def replaceView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
val existing = createdViews.get(key)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) {
+ if (existing == null || !existing.isInstanceOf[View]) {
throw new NoSuchViewException(ident)
}
createdViews.put(key, info)
@@ -546,7 +544,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
override def dropView(ident: Identifier): Boolean = {
val key = (ident.namespace().toSeq, ident.name())
val existing = createdViews.get(key)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) return false
+ if (existing == null || !existing.isInstanceOf[View]) return false
createdViews.remove(key) != null
}
@@ -554,7 +552,7 @@ class TestingTableViewCatalog extends TableViewCatalog {
val oldKey = (oldIdent.namespace().toSeq, oldIdent.name())
val newKey = (newIdent.namespace().toSeq, newIdent.name())
val existing = createdViews.get(oldKey)
- if (existing == null || !existing.isInstanceOf[ViewInfo]) {
+ if (existing == null || !existing.isInstanceOf[View]) {
throw new NoSuchViewException(oldIdent)
}
if (createdViews.putIfAbsent(newKey, existing) != null) {
@@ -600,14 +598,14 @@ class TestingTableOnlyCatalog extends TableCatalog {
*/
class TestingViewOnlyCatalog extends ViewCatalog {
private val store =
- new java.util.concurrent.ConcurrentHashMap[(Seq[String], String), ViewInfo]()
+ new java.util.concurrent.ConcurrentHashMap[(Seq[String], String), View]()
// Seeded on first `initialize`. Filters `spark_catalog.default.t` so the read test can
// assert deterministic output. ALTER VIEW tests overwrite it via `replaceView`.
private def seedDefault(): Unit = {
val key = (Seq("default"), "pure_v")
if (!store.containsKey(key)) {
- val info = new ViewInfo.Builder()
+ val info = new View.Builder()
.withSchema(new StructType().add("x", "int"))
.withQueryText("SELECT x FROM spark_catalog.default.t WHERE x > 1")
.build()
@@ -624,12 +622,12 @@ class TestingViewOnlyCatalog extends ViewCatalog {
ids.toArray(new Array[Identifier](0))
}
- override def loadView(ident: Identifier): ViewInfo = {
+ override def loadView(ident: Identifier): View = {
val key = (ident.namespace().toSeq, ident.name())
Option(store.get(key)).getOrElse(throw new NoSuchViewException(ident))
}
- override def createView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def createView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
if (store.putIfAbsent(key, info) != null) {
throw new ViewAlreadyExistsException(ident)
@@ -637,7 +635,7 @@ class TestingViewOnlyCatalog extends ViewCatalog {
info
}
- override def replaceView(ident: Identifier, info: ViewInfo): ViewInfo = {
+ override def replaceView(ident: Identifier, info: View): View = {
val key = (ident.namespace().toSeq, ident.name())
if (!store.containsKey(key)) throw new NoSuchViewException(ident)
store.put(key, info)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/MetricViewV2CatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/MetricViewV2CatalogSuite.scala
index b1f011c9cdac..9b75e89a1ad8 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/MetricViewV2CatalogSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/MetricViewV2CatalogSuite.scala
@@ -23,7 +23,7 @@ import scala.jdk.CollectionConverters._
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.analysis.{NoSuchViewException, ViewAlreadyExistsException}
-import org.apache.spark.sql.connector.catalog.{Identifier, InMemoryTableCatalog, MetadataTable, Table, TableCatalog, TableDependency, TableSummary, TableViewCatalog, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{Identifier, InMemoryTableCatalog, Relation, RelationCatalog, TableCatalog, TableDependency, TableSummary, View}
import org.apache.spark.sql.metricview.serde.{AssetSource, Column, Constants, DimensionExpression, MeasureExpression, MetricView, MetricViewFactory, SQLSource}
import org.apache.spark.sql.test.SharedSparkSession
import org.apache.spark.sql.types.Metadata
@@ -35,8 +35,8 @@ import org.apache.spark.sql.types.Metadata
* [[org.apache.spark.sql.execution.datasources.v2.CreateV2MetricViewExec]]).
* Metric views are persisted through the same [[ViewCatalog]] interface
* as plain views; the only marker that distinguishes them is `PROP_TABLE_TYPE = METRIC_VIEW`
- * plus the typed `viewDependencies` field on [[ViewInfo]]. The recording catalog used here is a
- * minimal [[TableViewCatalog]] so the same instance can also host the source table referenced by
+ * plus the typed `viewDependencies` field on [[View]]. The recording catalog used here is a
+ * minimal [[RelationCatalog]] so the same instance can also host the source table referenced by
* the metric view's YAML.
*/
class MetricViewV2CatalogSuite extends SharedSparkSession {
@@ -121,11 +121,11 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
yaml
}
- private def capturedViewInfo(): ViewInfo = {
+ private def capturedViewInfo(): View = {
val ident = Identifier.of(Array(testNamespace), metricViewName)
val info = MetricViewRecordingCatalog.capturedViews.get(ident)
assert(info != null,
- s"Expected ViewInfo for $ident to be captured by the V2 catalog")
+ s"Expected View for $ident to be captured by the V2 catalog")
info
}
@@ -134,7 +134,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
// ============================================================
- test("V2 catalog receives METRIC_VIEW table type and view text via ViewInfo") {
+ test("V2 catalog receives METRIC_VIEW table type and view text via View") {
withTestCatalogTables {
val metricView = MetricView(
"0.1",
@@ -144,7 +144,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
val yaml = createMetricView(fullMetricViewName, metricView)
val info = capturedViewInfo()
- // PROP_TABLE_TYPE is overwritten to METRIC_VIEW after `ViewInfo`'s constructor stamps it
+ // PROP_TABLE_TYPE is overwritten to METRIC_VIEW after `View`'s constructor stamps it
// to VIEW; this is the marker `V1Table.toCatalogTable` reads to map the round-tripped row
// back to `CatalogTableType.METRIC_VIEW`.
assert(info.properties().get(TableCatalog.PROP_TABLE_TYPE)
@@ -163,7 +163,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
}
}
- test("V2 catalog path populates metric_view.* + view context + sql configs on ViewInfo") {
+ test("V2 catalog path populates metric_view.* + view context + sql configs on View") {
withTestCatalogTables {
val metricView = MetricView(
"0.1",
@@ -182,7 +182,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
assert(props.get(MetricView.PROP_FROM_SQL) === null)
assert(props.get(MetricView.PROP_WHERE) === "count > 0")
- // SQL configs and current catalog/namespace are first-class typed fields on ViewInfo, no
+ // SQL configs and current catalog/namespace are first-class typed fields on View, no
// longer encoded into properties for V2 catalogs.
assert(info.sqlConfigs().size > 0,
s"Expected at least one captured SQL config; got ${info.sqlConfigs()}")
@@ -336,7 +336,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
// Now CREATE VIEW IF NOT EXISTS with a different YAML body. The catalog should not see
// the second create at all (V2ViewPreparation's `viewExists` short-circuit fires before
- // `buildViewInfo`), so the captured ViewInfo retains the original body.
+ // `buildViewInfo`), so the captured View retains the original body.
val replacement = MetricView(
"0.1",
AssetSource(fullSourceTableName),
@@ -471,7 +471,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
val deepIdent = Identifier.of(deepNamespace, deepMetricViewName)
val info = MetricViewRecordingCatalog.capturedViews.get(deepIdent)
- assert(info != null, s"Expected ViewInfo for $deepIdent to be captured")
+ assert(info != null, s"Expected View for $deepIdent to be captured")
assert(info.properties().get(TableCatalog.PROP_TABLE_TYPE)
=== TableSummary.METRIC_VIEW_TABLE_TYPE)
} finally {
@@ -607,7 +607,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
val multiTable = "events_deep"
val multiFull = s"$testCatalogName.${multiNamespace.mkString(".")}.$multiTable"
withTestCatalogTables {
- // The InMemoryTableCatalog (TableViewCatalog mixin) supports multi-level namespaces.
+ // The InMemoryTableCatalog (RelationCatalog mixin) supports multi-level namespaces.
sql(s"CREATE NAMESPACE IF NOT EXISTS $testCatalogName.${multiNamespace.head}")
sql(s"CREATE NAMESPACE IF NOT EXISTS " +
s"$testCatalogName.${multiNamespace.mkString(".")}")
@@ -650,7 +650,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
createMetricView(fullMetricViewName, mv)
// The fixture's `events` source has rows ("region_1", 1, 5.0), ("region_2", 2, 10.0).
// The metric view aggregates by `region` summing `count`. Resolution flows through
- // loadTableOrView -> MetadataTable(ViewInfo) -> V1Table.toCatalogTable(ViewInfo) ->
+ // loadRelation -> DelegatingTable(View) -> V1Table.toCatalogTable(View) ->
// CatalogTableType.METRIC_VIEW -> ResolveMetricView, which rewrites the view body
// into Aggregate(Seq(region), Seq(sum(count) AS count_sum)) over `events`. The
// `measure(...)` wrapper is required for measure columns -- selecting `count_sum`
@@ -740,7 +740,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
// ============================================================
- test("DESCRIBE TABLE EXTENDED on a v2 metric view round-trips through loadTableOrView") {
+ test("DESCRIBE TABLE EXTENDED on a v2 metric view round-trips through loadRelation") {
withTestCatalogTables {
val mv = MetricView(
"0.1",
@@ -750,10 +750,10 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
val yaml = createMetricView(fullMetricViewName, mv)
// DESCRIBE TABLE EXTENDED resolves the ident through `Analyzer.lookupTableOrView`,
- // which calls `TableViewCatalog.loadTableOrView` once and gets back a
- // `MetadataTable(ViewInfo)`. The analyzer wraps it as a `ResolvedPersistentView` and
+ // which calls `RelationCatalog.loadRelation` once and gets back a
+ // `DelegatingTable(View)`. The analyzer wraps it as a `ResolvedPersistentView` and
// `DataSourceV2Strategy` routes through SPARK-56655's `DescribeV2ViewExec`, which
- // reads the typed `ViewInfo` directly and emits the standard "Type" / "View Text" /
+ // reads the typed `View` directly and emits the standard "Type" / "View Text" /
// "View Current Catalog" / "View Schema Mode" / etc. rows. Pins that `DescribeV2ViewExec`
// emits a "Type" row for parity with v1 `CatalogTable.toJsonLinkedHashMap`, so users
// can distinguish a plain VIEW from a sub-kind like METRIC_VIEW.
@@ -918,7 +918,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
s"Expected TABLE_OR_VIEW_NOT_FOUND for the old ident, got " +
s"${oldEx.getCondition}: ${oldEx.getMessage}")
- // New ident loads through `TableViewCatalog.loadTableOrView` and surfaces the same
+ // New ident loads through `RelationCatalog.loadRelation` and surfaces the same
// metric-view kind on `DESCRIBE TABLE EXTENDED`.
val rows = sql(s"DESCRIBE TABLE EXTENDED $renamedFull").collect()
val rowMap = rows.map(r => r.getString(0) -> r.getString(1)).toMap
@@ -930,7 +930,7 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
}
}
- test("SHOW TABLES on a v2 TableViewCatalog lists both tables and metric views") {
+ test("SHOW TABLES on a v2 RelationCatalog lists both tables and metric views") {
withTestCatalogTables {
val mv = MetricView(
"0.1",
@@ -940,13 +940,13 @@ class MetricViewV2CatalogSuite extends SharedSparkSession {
createMetricView(fullMetricViewName, mv)
val tables = sql(s"SHOW TABLES IN $testCatalogName.$testNamespace")
.collect().map(_.getString(1)).toSet
- // SPARK-56655 routes SHOW TABLES on a `TableViewCatalog` through `listRelationSummaries`
+ // SPARK-56655 routes SHOW TABLES on a `RelationCatalog` through `listRelationSummaries`
// so views appear alongside tables in the output (matching v1 SHOW TABLES on a session
// catalog). Pure `TableCatalog` catalogs continue to return tables only.
assert(tables.contains(sourceTableName),
s"SHOW TABLES should list the source table, got: $tables")
assert(tables.contains(metricViewName),
- s"SHOW TABLES on a TableViewCatalog should also list metric views, got: $tables")
+ s"SHOW TABLES on a RelationCatalog should also list metric views, got: $tables")
}
}
@@ -971,17 +971,17 @@ object MetricViewV2CatalogSuite {
}
/**
- * Minimal [[TableViewCatalog]] used by [[MetricViewV2CatalogSuite]]. Layers `ViewCatalog`
+ * Minimal [[RelationCatalog]] used by [[MetricViewV2CatalogSuite]]. Layers `ViewCatalog`
* methods over [[InMemoryTableCatalog]] (which provides table storage + namespace ops) and
- * captures every [[ViewInfo]] passed to `createView` so tests can inspect the typed payload.
+ * captures every [[View]] passed to `createView` so tests can inspect the typed payload.
*
* The metric-view CREATE path goes via `ViewCatalog.createView`, so the captured map keys are
* the view identifiers; the source table created by the test fixture is stored separately in
* the inherited table catalog.
*/
-class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCatalog {
+class MetricViewRecordingCatalog extends InMemoryTableCatalog with RelationCatalog {
private val views =
- new ConcurrentHashMap[(Seq[String], String), ViewInfo]()
+ new ConcurrentHashMap[(Seq[String], String), View]()
// -- ViewCatalog methods --
@@ -994,11 +994,11 @@ class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCata
out.asScala.toArray
}
- // `loadView`, `tableExists`, and `viewExists` are inherited from `TableViewCatalog`'s
- // defaults, which derive from `loadTableOrView` -- a stored `ViewInfo` is wrapped in
- // `MetadataTable` by `loadTableOrView` and the defaults unwrap it correctly.
+ // `loadView`, `tableExists`, and `viewExists` are inherited from `RelationCatalog`'s
+ // defaults, which derive from `loadRelation` -- a stored `View` is returned directly by
+ // `loadRelation` and the defaults discriminate it by type correctly.
- // Bypasses `TableViewCatalog.tableExists` (whose default delegates to `loadTableOrView`,
+ // Bypasses `RelationCatalog.tableExists` (whose default delegates to `loadRelation`,
// which checks our `views` map first); we want a tables-only check here so the cross-type
// collision branches in `createView` / `replaceView` see only "is there a *table* at this
// ident?".
@@ -1006,8 +1006,8 @@ class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCata
try { super[InMemoryTableCatalog].loadTable(ident); true }
catch { case _: org.apache.spark.sql.catalyst.analysis.NoSuchTableException => false }
- override def createView(ident: Identifier, info: ViewInfo): ViewInfo = {
- // TableViewCatalog active-rejection contract: createView must throw
+ override def createView(ident: Identifier, info: View): View = {
+ // RelationCatalog active-rejection contract: createView must throw
// ViewAlreadyExistsException when *either* a view *or* a table sits at the ident.
if (tableExistsTablesOnly(ident)) {
throw new ViewAlreadyExistsException(ident)
@@ -1020,8 +1020,8 @@ class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCata
info
}
- override def replaceView(ident: Identifier, info: ViewInfo): ViewInfo = {
- // Per the TableViewCatalog contract, replaceView must surface NoSuchViewException
+ override def replaceView(ident: Identifier, info: View): View = {
+ // Per the RelationCatalog contract, replaceView must surface NoSuchViewException
// when a *table* sits at the ident (not silently succeed and shadow the table).
if (tableExistsTablesOnly(ident)) throw new NoSuchViewException(ident)
val key = (ident.namespace().toSeq, ident.name())
@@ -1055,13 +1055,13 @@ class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCata
}
}
- // -- TableViewCatalog single-RPC perf path --
+ // -- RelationCatalog single-RPC perf path --
- override def loadTableOrView(ident: Identifier): Table = {
+ override def loadRelation(ident: Identifier): Relation = {
val key = (ident.namespace().toSeq, ident.name())
Option(views.get(key)) match {
- case Some(info) => new MetadataTable(info, ident.toString)
- // Bypass `TableViewCatalog.loadTable` (whose default delegates back to `loadTableOrView`)
+ case Some(info) => info
+ // Bypass `RelationCatalog.loadTable` (whose default delegates back to `loadRelation`)
// and call `InMemoryTableCatalog.loadTable` directly to avoid infinite recursion.
case None => super[InMemoryTableCatalog].loadTable(ident)
}
@@ -1069,10 +1069,10 @@ class MetricViewRecordingCatalog extends InMemoryTableCatalog with TableViewCata
}
object MetricViewRecordingCatalog {
- // Captures every ViewInfo that flows through createView / replaceView so individual tests
+ // Captures every View that flows through createView / replaceView so individual tests
// can assert on it. Cleared between tests via `reset()`.
- val capturedViews: ConcurrentHashMap[Identifier, ViewInfo] =
- new ConcurrentHashMap[Identifier, ViewInfo]()
+ val capturedViews: ConcurrentHashMap[Identifier, View] =
+ new ConcurrentHashMap[Identifier, View]()
def reset(): Unit = capturedViews.clear()
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterViewSetTblPropertiesSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterViewSetTblPropertiesSuiteBase.scala
index b55ee4563c6e..bf3931d7c1cb 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterViewSetTblPropertiesSuiteBase.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/AlterViewSetTblPropertiesSuiteBase.scala
@@ -100,7 +100,7 @@ trait AlterViewSetTblPropertiesSuiteBase extends QueryTest with DDLCommandTestUt
test("setting `comment` flows through to SHOW CREATE TABLE") {
// v1 `AlterTableSetPropertiesCommand` updates the typed `CatalogTable.comment` field when
// the user passes `'comment'` via SET TBLPROPERTIES, so SHOW CREATE TABLE renders the
- // comment in the COMMENT clause. The v2 path uses `ViewInfo.properties` as the source of
+ // comment in the COMMENT clause. The v2 path uses `View.properties` as the source of
// truth for `PROP_COMMENT` (see `AlterV2ViewSetPropertiesExec` and `ShowCreateV2ViewExec`),
// so the same SET TBLPROPERTIES('comment' = ...) round-trips through SHOW CREATE TABLE.
// Pin the cross-catalog parity here.
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateViewSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateViewSuiteBase.scala
index d046e74b6862..b0e42ed8cbe9 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateViewSuiteBase.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/CreateViewSuiteBase.scala
@@ -40,7 +40,7 @@ trait CreateViewSuiteBase extends QueryTest with DDLCommandTestUtils {
/**
* Seed a non-view table at `qualified` (full `catalog.ns.name`) and run `body`. Same SQL
- * for v1 and v2 -- `InMemoryTableViewCatalog.createTable` accepts the parquet TableInfo
+ * for v1 and v2 -- `InMemoryRelationCatalog.createTable` accepts the parquet TableInfo
* the same way the session catalog does, so both legs share this implementation.
*/
protected final def withSeededTable(qualified: String)(body: => Unit): Unit = {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DropViewSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DropViewSuiteBase.scala
index 92a368e4155a..9266f2dbca9d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DropViewSuiteBase.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DropViewSuiteBase.scala
@@ -37,7 +37,7 @@ trait DropViewSuiteBase extends QueryTest with DDLCommandTestUtils {
/**
* Seed a non-view table at `qualified` (full `catalog.ns.name`) and run `body`. Same SQL
- * for v1 and v2 -- `InMemoryTableViewCatalog.createTable` accepts the parquet TableInfo
+ * for v1 and v2 -- `InMemoryRelationCatalog.createTable` accepts the parquet TableInfo
* the same way the session catalog does, so both legs share this implementation.
*/
protected final def withSeededTable(qualified: String)(body: => Unit): Unit = {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala
index cd917a817f7f..6968a75f5eee 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/PlanResolutionSuite.scala
@@ -153,7 +153,7 @@ class PlanResolutionSuite extends SharedSparkSession with AnalysisTest {
when(t.comment).thenReturn(None)
when(t.collation).thenReturn(None)
if (tableType == CatalogTableType.VIEW) {
- // Stub the view-only fields that resolution reads through `V1ViewInfo.builderFrom`.
+ // Stub the view-only fields that resolution reads through `V1View.builderFrom`.
// Mockito returns `null` for unstubbed Object methods, which would NPE the moment
// builderFrom calls `.getOrElse` / `.asJava` / `.toArray` on a null Option/Seq/Map.
when(t.viewText).thenReturn(None)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSchemaBindingSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSchemaBindingSuite.scala
index 517880047d25..c9f769d9f548 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSchemaBindingSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSchemaBindingSuite.scala
@@ -22,7 +22,7 @@ import org.apache.spark.sql.execution.command
class AlterViewSchemaBindingSuite
extends command.AlterViewSchemaBindingSuiteBase with ViewCommandSuiteBase {
- test("V2: catalog stores the new schema mode on ViewInfo") {
+ test("V2: catalog stores the new schema mode on View") {
val view = s"$catalog.$namespace.v2_schema_mode"
createView(view)
sql(s"ALTER VIEW $view WITH SCHEMA EVOLUTION")
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSetTblPropertiesSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSetTblPropertiesSuite.scala
index 642d8d46b7fa..46499b6b4969 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSetTblPropertiesSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewSetTblPropertiesSuite.scala
@@ -26,7 +26,7 @@ import org.apache.spark.sql.execution.command
class AlterViewSetTblPropertiesSuite
extends command.AlterViewSetTblPropertiesSuiteBase with ViewCommandSuiteBase {
- test("V2: catalog stores the property on ViewInfo") {
+ test("V2: catalog stores the property on View") {
val view = s"$catalog.$namespace.v2_set_view_info"
createView(view)
sql(s"ALTER VIEW $view SET TBLPROPERTIES ('k' = 'v')")
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewUnsetTblPropertiesSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewUnsetTblPropertiesSuite.scala
index 0d7f13007e9f..52871b1a0412 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewUnsetTblPropertiesSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/AlterViewUnsetTblPropertiesSuite.scala
@@ -22,7 +22,7 @@ import org.apache.spark.sql.execution.command
class AlterViewUnsetTblPropertiesSuite
extends command.AlterViewUnsetTblPropertiesSuiteBase with ViewCommandSuiteBase {
- test("V2: unset removes the entry from the stored ViewInfo") {
+ test("V2: unset removes the entry from the stored View") {
val view = s"$catalog.$namespace.v2_unset_view_info"
createViewWithProps(view, "k" -> "v")
sql(s"ALTER VIEW $view UNSET TBLPROPERTIES ('k')")
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/CreateViewSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/CreateViewSuite.scala
index 1750a538b1d4..7ff334454664 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/CreateViewSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/CreateViewSuite.scala
@@ -18,13 +18,13 @@
package org.apache.spark.sql.execution.command.v2
import org.apache.spark.sql.AnalysisException
-import org.apache.spark.sql.connector.catalog.{BasicInMemoryTableCatalog, TableCatalog, ViewInfo}
+import org.apache.spark.sql.connector.catalog.{BasicInMemoryTableCatalog, TableCatalog, View}
import org.apache.spark.sql.execution.command
class CreateViewSuite extends command.CreateViewSuiteBase with ViewCommandSuiteBase {
import testImplicits._
- test("V2: CREATE VIEW propagates DEFAULT COLLATION onto the stored ViewInfo") {
+ test("V2: CREATE VIEW propagates DEFAULT COLLATION onto the stored View") {
val view = s"$catalog.$namespace.v2_create_collation"
withTable("spark_catalog.default.src_coll") {
Seq("a", "b").toDF("col").write.saveAsTable("spark_catalog.default.src_coll")
@@ -56,13 +56,13 @@ class CreateViewSuite extends command.CreateViewSuiteBase with ViewCommandSuiteB
// The Base version of this scenario asserts the SQL behavior (errors / no-op);
// here we additionally pin the v2-only post-condition that the persisted entry under
// the colliding identifier remains a `TableInfo` and is NOT silently swapped for a
- // `ViewInfo` by the IF NOT EXISTS path.
+ // `View` by the IF NOT EXISTS path.
val name = "v2_ifne_keeps_table"
val view = s"$catalog.$namespace.$name"
withSeededTable(view) {
sql(s"CREATE VIEW IF NOT EXISTS $view AS SELECT 1 AS col")
val stored = viewCatalog.getStoredInfo(Array(namespace), name)
- assert(!stored.isInstanceOf[ViewInfo])
+ assert(!stored.isInstanceOf[View])
}
}
}
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ViewCommandSuiteBase.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ViewCommandSuiteBase.scala
index 4dbbbc21afa9..3f67a61bce4a 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ViewCommandSuiteBase.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/v2/ViewCommandSuiteBase.scala
@@ -18,21 +18,21 @@
package org.apache.spark.sql.execution.command.v2
import org.apache.spark.SparkConf
-import org.apache.spark.sql.connector.catalog.InMemoryTableViewCatalog
+import org.apache.spark.sql.connector.catalog.InMemoryRelationCatalog
/**
* Settings for v2 view command test suites. Extends v2 [[CommandSuiteBase]] (so view tests
* inherit `checkLocation` and the standard v2 `test_catalog` configuration), and additionally
- * wires `test_view_catalog` to [[InMemoryTableViewCatalog]] -- the catalog that the unified
+ * wires `test_view_catalog` to [[InMemoryRelationCatalog]] -- the catalog that the unified
* `*SuiteBase` view tests under `command/` target via the `$catalog` placeholder.
*/
trait ViewCommandSuiteBase extends CommandSuiteBase {
override def catalog: String = "test_view_catalog"
override def sparkConf: SparkConf = super.sparkConf
- .set(s"spark.sql.catalog.$catalog", classOf[InMemoryTableViewCatalog].getName)
+ .set(s"spark.sql.catalog.$catalog", classOf[InMemoryRelationCatalog].getName)
- /** Helper: returns the configured `InMemoryTableViewCatalog`. */
- protected def viewCatalog: InMemoryTableViewCatalog =
- spark.sessionState.catalogManager.catalog(catalog).asInstanceOf[InMemoryTableViewCatalog]
+ /** Helper: returns the configured `InMemoryRelationCatalog`. */
+ protected def viewCatalog: InMemoryRelationCatalog =
+ spark.sessionState.catalogManager.catalog(catalog).asInstanceOf[InMemoryRelationCatalog]
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org