Class DelegatingCatalogExtension
- All Implemented Interfaces:
CatalogExtension
,CatalogPlugin
,FunctionCatalog
,SupportsNamespaces
,TableCatalog
CatalogExtension
, which implements all the catalog functions
by calling the built-in session catalog directly. This is created for convenience, so that users
only need to override some methods where they want to apply custom logic. For example, they can
override createTable
, do something else before calling super.createTable
.- Since:
- 3.0.0
-
Field Summary
Fields inherited from interface org.apache.spark.sql.connector.catalog.SupportsNamespaces
PROP_COMMENT, PROP_LOCATION, PROP_OWNER
Fields inherited from interface org.apache.spark.sql.connector.catalog.TableCatalog
OPTION_PREFIX, PROP_COMMENT, PROP_EXTERNAL, PROP_IS_MANAGED_LOCATION, PROP_LOCATION, PROP_OWNER, PROP_PROVIDER
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
alterNamespace
(String[] namespace, NamespaceChange... changes) Apply a set of metadata changes to a namespace in the catalog.alterTable
(Identifier ident, TableChange... changes) Apply a set ofchanges
to a table in the catalog.void
createNamespace
(String[] namespace, Map<String, String> metadata) Create a namespace in the catalog.createTable
(Identifier ident, Column[] columns, Transform[] partitions, Map<String, String> properties) Create a table in the catalog.createTable
(Identifier ident, StructType schema, Transform[] partitions, Map<String, String> properties) Create a table in the catalog.String[]
Return a default namespace for the catalog.boolean
dropNamespace
(String[] namespace, boolean cascade) Drop a namespace from the catalog with cascade mode, recursively dropping all objects within the namespace if cascade is true.boolean
dropTable
(Identifier ident) Drop a table in the catalog.boolean
functionExists
(Identifier ident) Returns true if the function exists, false otherwise.final void
initialize
(String name, CaseInsensitiveStringMap options) Called to initialize configuration.void
invalidateTable
(Identifier ident) Invalidate cached table metadata for anidentifier
.listFunctions
(String[] namespace) List the functions in a namespace from the catalog.String[][]
List top-level namespaces from the catalog.String[][]
listNamespaces
(String[] namespace) List namespaces in a namespace.listTables
(String[] namespace) List the tables in a namespace from the catalog.loadFunction
(Identifier ident) Load a function byidentifier
from the catalog.loadNamespaceMetadata
(String[] namespace) Load metadata properties for a namespace.loadTable
(Identifier ident) Load table metadata byidentifier
from the catalog.loadTable
(Identifier ident, long timestamp) Load table metadata at a specific time byidentifier
from the catalog.loadTable
(Identifier ident, String version) Load table metadata of a specific version byidentifier
from the catalog.name()
Called to get this catalog's name.boolean
namespaceExists
(String[] namespace) Test whether a namespace exists.boolean
purgeTable
(Identifier ident) Drop a table in the catalog and completely remove its data by skipping a trash even if it is supported.void
renameTable
(Identifier oldIdent, Identifier newIdent) Renames a table in the catalog.final void
setDelegateCatalog
(CatalogPlugin delegate) This will be called only once by Spark to pass in the Spark built-in session catalog, afterCatalogPlugin.initialize(String, CaseInsensitiveStringMap)
is called.boolean
tableExists
(Identifier ident) Test whether a table exists using anidentifier
from the catalog.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.spark.sql.connector.catalog.TableCatalog
useNullableQuerySchema
-
Constructor Details
-
DelegatingCatalogExtension
public DelegatingCatalogExtension()
-
-
Method Details
-
setDelegateCatalog
Description copied from interface:CatalogExtension
This will be called only once by Spark to pass in the Spark built-in session catalog, afterCatalogPlugin.initialize(String, CaseInsensitiveStringMap)
is called.- Specified by:
setDelegateCatalog
in interfaceCatalogExtension
-
name
Description copied from interface:CatalogPlugin
Called to get this catalog's name.This method is only called after
CatalogPlugin.initialize(String, CaseInsensitiveStringMap)
is called to pass the catalog's name.- Specified by:
name
in interfaceCatalogPlugin
-
initialize
Description copied from interface:CatalogPlugin
Called to initialize configuration.This method is called once, just after the provider is instantiated.
- Specified by:
initialize
in interfaceCatalogPlugin
- Parameters:
name
- the name used to identify and load this catalogoptions
- a case-insensitive string map of configuration
-
capabilities
- Specified by:
capabilities
in interfaceTableCatalog
- Returns:
- the set of capabilities for this TableCatalog
-
defaultNamespace
Description copied from interface:CatalogPlugin
Return a default namespace for the catalog.When this catalog is set as the current catalog, the namespace returned by this method will be set as the current namespace.
The namespace returned by this method is not required to exist.
- Specified by:
defaultNamespace
in interfaceCatalogPlugin
- Returns:
- a multi-part namespace
-
listTables
public Identifier[] listTables(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:TableCatalog
List the tables in a namespace from the catalog.If the catalog supports views, this must return identifiers for only tables and not views.
- Specified by:
listTables
in interfaceTableCatalog
- Parameters:
namespace
- a multi-part namespace- Returns:
- an array of Identifiers for tables
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional).
-
loadTable
public Table loadTable(Identifier ident) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException Description copied from interface:TableCatalog
Load table metadata byidentifier
from the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException
.- Specified by:
loadTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifier- Returns:
- the table's metadata
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a view
-
loadTable
public Table loadTable(Identifier ident, long timestamp) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException Description copied from interface:TableCatalog
Load table metadata at a specific time byidentifier
from the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException
.- Specified by:
loadTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifiertimestamp
- timestamp of the table, which is microseconds since 1970-01-01 00:00:00 UTC- Returns:
- the table's metadata
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a view
-
loadTable
public Table loadTable(Identifier ident, String version) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException Description copied from interface:TableCatalog
Load table metadata of a specific version byidentifier
from the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException
.- Specified by:
loadTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifierversion
- version of the table- Returns:
- the table's metadata
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a view
-
invalidateTable
Description copied from interface:TableCatalog
Invalidate cached table metadata for anidentifier
.If the table is already loaded or cached, drop cached data. If the table does not exist or is not cached, do nothing. Calling this method should not query remote services.
- Specified by:
invalidateTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifier
-
tableExists
Description copied from interface:TableCatalog
Test whether a table exists using anidentifier
from the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must return false.
- Specified by:
tableExists
in interfaceTableCatalog
- Parameters:
ident
- a table identifier- Returns:
- true if the table exists, false otherwise
-
createTable
public Table createTable(Identifier ident, StructType schema, Transform[] partitions, Map<String, String> properties) throws org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceExceptionDescription copied from interface:TableCatalog
Create a table in the catalog.This is deprecated. Please override
TableCatalog.createTable(Identifier, Column[], Transform[], Map)
instead.- Specified by:
createTable
in interfaceTableCatalog
- Throws:
org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
-
createTable
public Table createTable(Identifier ident, Column[] columns, Transform[] partitions, Map<String, String> properties) throws org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceExceptionDescription copied from interface:TableCatalog
Create a table in the catalog.- Specified by:
createTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifiercolumns
- the columns of the new table.partitions
- transforms to use for partitioning data in the tableproperties
- a string map of table properties- Returns:
- metadata for the new table
- Throws:
org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
- If a table or view already exists for the identifierorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the identifier namespace does not exist (optional)
-
alterTable
public Table alterTable(Identifier ident, TableChange... changes) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException Description copied from interface:TableCatalog
Apply a set ofchanges
to a table in the catalog.Implementations may reject the requested changes. If any change is rejected, none of the changes should be applied to the table.
The requested changes must be applied in the order given.
If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException
.- Specified by:
alterTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifierchanges
- changes to apply to the table- Returns:
- updated metadata for the table
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a view
-
dropTable
Description copied from interface:TableCatalog
Drop a table in the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must not drop the view and must return false.
- Specified by:
dropTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifier- Returns:
- true if a table was deleted, false if no table exists for the identifier
-
purgeTable
Description copied from interface:TableCatalog
Drop a table in the catalog and completely remove its data by skipping a trash even if it is supported.If the catalog supports views and contains a view for the identifier and not a table, this must not drop the view and must return false.
If the catalog supports to purge a table, this method should be overridden. The default implementation throws
UnsupportedOperationException
.- Specified by:
purgeTable
in interfaceTableCatalog
- Parameters:
ident
- a table identifier- Returns:
- true if a table was deleted, false if no table exists for the identifier
-
renameTable
public void renameTable(Identifier oldIdent, Identifier newIdent) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException, org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException Description copied from interface:TableCatalog
Renames a table in the catalog.If the catalog supports views and contains a view for the old identifier and not a table, this throws
NoSuchTableException
. Additionally, if the new identifier is a table or a view, this throwsTableAlreadyExistsException
.If the catalog does not support table renames between namespaces, it throws
UnsupportedOperationException
.- Specified by:
renameTable
in interfaceTableCatalog
- Parameters:
oldIdent
- the table identifier of the existing table to renamenewIdent
- the new table identifier of the table- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table to rename doesn't exist or is a vieworg.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
- If the new table name already exists or is a view
-
listNamespaces
public String[][] listNamespaces() throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceExceptionDescription copied from interface:SupportsNamespaces
List top-level namespaces from the catalog.If an object such as a table, view, or function exists, its parent namespaces must also exist and must be returned by this discovery method. For example, if table a.b.t exists, this method must return ["a"] in the result array.
- Specified by:
listNamespaces
in interfaceSupportsNamespaces
- Returns:
- an array of multi-part namespace names
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
-
listNamespaces
public String[][] listNamespaces(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:SupportsNamespaces
List namespaces in a namespace.If an object such as a table, view, or function exists, its parent namespaces must also exist and must be returned by this discovery method. For example, if table a.b.t exists, this method invoked as listNamespaces(["a"]) must return ["a", "b"] in the result array.
- Specified by:
listNamespaces
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespace- Returns:
- an array of multi-part namespace names
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)
-
namespaceExists
Description copied from interface:SupportsNamespaces
Test whether a namespace exists.If an object such as a table, view, or function exists, its parent namespaces must also exist. For example, if table a.b.t exists, this method invoked as namespaceExists(["a"]) or namespaceExists(["a", "b"]) must return true.
- Specified by:
namespaceExists
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespace- Returns:
- true if the namespace exists, false otherwise
-
loadNamespaceMetadata
public Map<String,String> loadNamespaceMetadata(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:SupportsNamespaces
Load metadata properties for a namespace.- Specified by:
loadNamespaceMetadata
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespace- Returns:
- a string map of properties for the given namespace
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)
-
createNamespace
public void createNamespace(String[] namespace, Map<String, String> metadata) throws org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsExceptionDescription copied from interface:SupportsNamespaces
Create a namespace in the catalog.- Specified by:
createNamespace
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespacemetadata
- a string map of properties for the given namespace- Throws:
org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException
- If the namespace already exists
-
alterNamespace
public void alterNamespace(String[] namespace, NamespaceChange... changes) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:SupportsNamespaces
Apply a set of metadata changes to a namespace in the catalog.- Specified by:
alterNamespace
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespacechanges
- a collection of changes to apply to the namespace- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)
-
dropNamespace
public boolean dropNamespace(String[] namespace, boolean cascade) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException, org.apache.spark.sql.catalyst.analysis.NonEmptyNamespaceException Description copied from interface:SupportsNamespaces
Drop a namespace from the catalog with cascade mode, recursively dropping all objects within the namespace if cascade is true.If the catalog implementation does not support this operation, it may throw
UnsupportedOperationException
.- Specified by:
dropNamespace
in interfaceSupportsNamespaces
- Parameters:
namespace
- a multi-part namespacecascade
- When true, deletes all objects under the namespace- Returns:
- true if the namespace was dropped
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)org.apache.spark.sql.catalyst.analysis.NonEmptyNamespaceException
- If the namespace is non-empty and cascade is false
-
loadFunction
public UnboundFunction loadFunction(Identifier ident) throws org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException Description copied from interface:FunctionCatalog
Load a function byidentifier
from the catalog.- Specified by:
loadFunction
in interfaceFunctionCatalog
- Parameters:
ident
- a function identifier- Returns:
- an unbound function instance
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException
- If the function doesn't exist
-
listFunctions
public Identifier[] listFunctions(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:FunctionCatalog
List the functions in a namespace from the catalog.If there are no functions in the namespace, implementations should return an empty array.
- Specified by:
listFunctions
in interfaceFunctionCatalog
- Parameters:
namespace
- a multi-part namespace- Returns:
- an array of Identifiers for functions
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional).
-
functionExists
Description copied from interface:FunctionCatalog
Returns true if the function exists, false otherwise.- Specified by:
functionExists
in interfaceFunctionCatalog
-