Interface ViewCatalog
- All Superinterfaces:
CatalogPlugin
- All Known Subinterfaces:
RelationCatalog
Connectors that expose only views implement this interface. Connectors that expose
both tables and views must implement RelationCatalog (which extends both this
interface and 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.
The presence of ViewCatalog on the catalog plugin is the signal that it
supports views; there is no capability flag to declare.
- Since:
- 4.2.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault ViewcreateOrReplaceView(Identifier ident, View info) Create a view if one does not exist atident, or atomically replace it if one does.createView(Identifier ident, View info) Create a view.booleandropView(Identifier ident) Drop a view.default voidinvalidateView(Identifier ident) Invalidate cached metadata for a view.List the views in a namespace from the catalog.loadView(Identifier ident) Load view metadata by identifier.voidrenameView(Identifier oldIdent, Identifier newIdent) Rename a view.replaceView(Identifier ident, View info) Atomically replace an existing view's metadata.default booleanviewExists(Identifier ident) Test whether a view exists.Methods inherited from interface org.apache.spark.sql.connector.catalog.CatalogPlugin
defaultNamespace, initialize, name
-
Method Details
-
listViews
Identifier[] listViews(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException List the views in a namespace from the catalog.- Parameters:
namespace- a multi-part namespace- Returns:
- an array of identifiers for views
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException- if the namespace does not exist (optional)
-
loadView
Load view metadata by identifier.- Parameters:
ident- a view identifier- Returns:
- the view metadata
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchViewException- if the view does not exist
-
viewExists
Test whether a view exists.The default implementation calls
loadView(org.apache.spark.sql.connector.catalog.Identifier)and catchesNoSuchViewException. Catalogs that can answer existence cheaply should override.- Parameters:
ident- a view identifier- Returns:
- true if a view exists at
ident, false otherwise
-
invalidateView
Invalidate cached metadata for a view.If the view is currently cached, drop the cached entry; otherwise do nothing. This must not issue remote calls.
- Parameters:
ident- a view identifier
-
createView
View createView(Identifier ident, View info) throws org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Create a view.- Parameters:
ident- the view identifierinfo- the view metadata- Returns:
- the metadata of the newly created view; may equal
info - Throws:
org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException- if a view already exists atidentorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException- if the identifier's namespace does not exist (optional)
-
replaceView
View replaceView(Identifier ident, View info) throws org.apache.spark.sql.catalyst.analysis.NoSuchViewException Atomically replace an existing view's metadata.Used by
ALTER VIEW ... AS. Implementations should commit the new metadata atomically; views carry no data, so a single transactional metastore call (or equivalent) is sufficient -- there is no separate staging API.- Parameters:
ident- the view identifierinfo- the new view metadata- Returns:
- the metadata of the replaced view; may equal
info - Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchViewException- if no view exists atident
-
createOrReplaceView
default View createOrReplaceView(Identifier ident, View info) throws org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Create a view if one does not exist atident, or atomically replace it if one does.Used by
CREATE OR REPLACE VIEW. The default implementation callsreplaceView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View), falling back tocreateView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View)onNoSuchViewException. The fallback is non-atomic across the two calls (a concurrent drop or create can race), so catalogs that can answer the upsert in a single transactional call should override this method to collapse to one RPC and to make the swap atomic.- Parameters:
ident- the view identifierinfo- the view metadata- Returns:
- the metadata of the created or replaced view; may equal
info - Throws:
org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException- ifidentcannot host this view -- either a concurrentCREATE VIEWwon the race in the default impl's gap betweenreplaceView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View)and the fallbackcreateView(org.apache.spark.sql.connector.catalog.Identifier, org.apache.spark.sql.connector.catalog.View), or, in aRelationCatalog, a table sits atidentorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException- if the identifier's namespace does not exist (optional)
-
dropView
Drop a view.- Parameters:
ident- a view identifier- Returns:
- true if a view was dropped, false otherwise
-
renameView
void renameView(Identifier oldIdent, Identifier newIdent) throws org.apache.spark.sql.catalyst.analysis.NoSuchViewException, org.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException Rename a view.If the catalog supports tables and contains a table at the new identifier, this must throw
ViewAlreadyExistsException. If the source identifier resolves to a table rather than a view, this must throwNoSuchViewException. The cross-type contract for catalogs that expose both tables and views lives onRelationCatalog.- Parameters:
oldIdent- the view identifier of the existing view to renamenewIdent- the new view identifier- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchViewException- if no view exists atoldIdentorg.apache.spark.sql.catalyst.analysis.ViewAlreadyExistsException- if a view (or, in aRelationCatalog, a table) already exists atnewIdent
-