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_OWNERFields inherited from interface org.apache.spark.sql.connector.catalog.TableCatalog
OPTION_PREFIX, PROP_COLLATION, PROP_COMMENT, PROP_EXTERNAL, PROP_IS_MANAGED_LOCATION, PROP_LOCATION, PROP_OWNER, PROP_PROVIDER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidalterNamespace(String[] namespace, NamespaceChange... changes) Apply a set of metadata changes to a namespace in the catalog.alterTable(Identifier ident, TableChange... changes) Apply a set ofchangesto a table in the catalog.voidcreateNamespace(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.booleandropNamespace(String[] namespace, boolean cascade) Drop a namespace from the catalog with cascade mode, recursively dropping all objects within the namespace if cascade is true.booleandropTable(Identifier ident) Drop a table in the catalog.booleanfunctionExists(Identifier ident) Returns true if the function exists, false otherwise.voidinitialize(String name, CaseInsensitiveStringMap options) Called to initialize configuration.voidinvalidateTable(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 byidentifierfrom the catalog.loadNamespaceMetadata(String[] namespace) Load metadata properties for a namespace.loadTable(Identifier ident) Load table metadata byidentifierfrom the catalog.loadTable(Identifier ident, long timestamp) Load table metadata at a specific time byidentifierfrom the catalog.loadTable(Identifier ident, String version) Load table metadata of a specific version byidentifierfrom the catalog.name()Called to get this catalog's name.booleannamespaceExists(String[] namespace) Test whether a namespace exists.booleanpurgeTable(Identifier ident) Drop a table in the catalog and completely remove its data by skipping a trash even if it is supported.voidrenameTable(Identifier oldIdent, Identifier newIdent) Renames a table in the catalog.final voidsetDelegateCatalog(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.booleantableExists(Identifier ident) Test whether a table exists using anidentifierfrom the catalog.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.sql.connector.catalog.TableCatalog
loadTable, useNullableQuerySchema
-
Constructor Details
-
DelegatingCatalogExtension
public DelegatingCatalogExtension()
-
-
Method Details
-
setDelegateCatalog
Description copied from interface:CatalogExtensionThis will be called only once by Spark to pass in the Spark built-in session catalog, afterCatalogPlugin.initialize(String, CaseInsensitiveStringMap)is called.- Specified by:
setDelegateCatalogin interfaceCatalogExtension
-
name
Description copied from interface:CatalogPluginCalled 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:
namein interfaceCatalogPlugin
-
initialize
Description copied from interface:CatalogPluginCalled to initialize configuration.This method is called once, just after the provider is instantiated.
- Specified by:
initializein interfaceCatalogPlugin- Parameters:
name- the name used to identify and load this catalogoptions- a case-insensitive string map of configuration
-
capabilities
- Specified by:
capabilitiesin interfaceTableCatalog- Returns:
- the set of capabilities for this TableCatalog
-
defaultNamespace
Description copied from interface:CatalogPluginReturn 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:
defaultNamespacein interfaceCatalogPlugin- Returns:
- a multi-part namespace
-
listTables
public Identifier[] listTables(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException Description copied from interface:TableCatalogList 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:
listTablesin 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:TableCatalogLoad table metadata byidentifierfrom the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException.- Specified by:
loadTablein 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:TableCatalogLoad table metadata at a specific time byidentifierfrom the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException.- Specified by:
loadTablein 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:TableCatalogLoad table metadata of a specific version byidentifierfrom the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must throw
NoSuchTableException.- Specified by:
loadTablein 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:TableCatalogInvalidate 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:
invalidateTablein interfaceTableCatalog- Parameters:
ident- a table identifier
-
tableExists
Description copied from interface:TableCatalogTest whether a table exists using anidentifierfrom the catalog.If the catalog supports views and contains a view for the identifier and not a table, this must return false.
- Specified by:
tableExistsin 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:TableCatalogCreate a table in the catalog.- Specified by:
createTablein interfaceTableCatalog- Throws:
org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsExceptionorg.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:TableCatalogCreate a table in the catalog.- Specified by:
createTablein 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. This can be null if getting the metadata for the new table
is expensive. Spark will call
TableCatalog.loadTable(Identifier)if needed (e.g. CTAS). - 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:TableCatalogApply a set ofchangesto 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:
alterTablein interfaceTableCatalog- Parameters:
ident- a table identifierchanges- changes to apply to the table- Returns:
- updated metadata for the table. This can be null if getting the metadata for the updated table is expensive. Spark always discard the returned table here.
- Throws:
org.apache.spark.sql.catalyst.analysis.NoSuchTableException- If the table doesn't exist or is a view
-
dropTable
Description copied from interface:TableCatalogDrop 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:
dropTablein 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:TableCatalogDrop 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:
purgeTablein 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:TableCatalogRenames 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:
renameTablein 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:SupportsNamespacesList 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:
listNamespacesin 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:SupportsNamespacesList 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:
listNamespacesin 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:SupportsNamespacesTest 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:
namespaceExistsin 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:SupportsNamespacesLoad metadata properties for a namespace.- Specified by:
loadNamespaceMetadatain 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:SupportsNamespacesCreate a namespace in the catalog.- Specified by:
createNamespacein 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:SupportsNamespacesApply a set of metadata changes to a namespace in the catalog.- Specified by:
alterNamespacein 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:SupportsNamespacesDrop 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:
dropNamespacein 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:FunctionCatalogLoad a function byidentifierfrom the catalog.- Specified by:
loadFunctionin 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:FunctionCatalogList the functions in a namespace from the catalog.If there are no functions in the namespace, implementations should return an empty array.
- Specified by:
listFunctionsin 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:FunctionCatalogReturns true if the function exists, false otherwise.- Specified by:
functionExistsin interfaceFunctionCatalog
-