@Evolving public abstract class DelegatingCatalogExtension extends Object implements CatalogExtension
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
.OPTION_PREFIX, PROP_COMMENT, PROP_EXTERNAL, PROP_IS_MANAGED_LOCATION, PROP_LOCATION, PROP_OWNER, PROP_PROVIDER
PROP_COMMENT, PROP_LOCATION, PROP_OWNER
Constructor and Description |
---|
DelegatingCatalogExtension() |
Modifier and Type | Method and Description |
---|---|
void |
alterNamespace(String[] namespace,
NamespaceChange... changes)
Apply a set of metadata changes to a namespace in the catalog.
|
Table |
alterTable(Identifier ident,
TableChange... changes)
Apply a set of
changes to a table in the catalog. |
java.util.Set<TableCatalogCapability> |
capabilities() |
void |
createNamespace(String[] namespace,
java.util.Map<String,String> metadata)
Create a namespace in the catalog.
|
Table |
createTable(Identifier ident,
Column[] columns,
Transform[] partitions,
java.util.Map<String,String> properties)
Create a table in the catalog.
|
Table |
createTable(Identifier ident,
StructType schema,
Transform[] partitions,
java.util.Map<String,String> properties)
Create a table in the catalog.
|
String[] |
defaultNamespace()
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.
|
void |
initialize(String name,
CaseInsensitiveStringMap options)
Called to initialize configuration.
|
void |
invalidateTable(Identifier ident)
Invalidate cached table metadata for an
identifier . |
Identifier[] |
listFunctions(String[] namespace)
List the functions in a namespace from the catalog.
|
String[][] |
listNamespaces()
List top-level namespaces from the catalog.
|
String[][] |
listNamespaces(String[] namespace)
List namespaces in a namespace.
|
Identifier[] |
listTables(String[] namespace)
List the tables in a namespace from the catalog.
|
UnboundFunction |
loadFunction(Identifier ident)
Load a function by
identifier from the catalog. |
java.util.Map<String,String> |
loadNamespaceMetadata(String[] namespace)
Load metadata properties for a namespace.
|
Table |
loadTable(Identifier ident)
Load table metadata by
identifier from the catalog. |
Table |
loadTable(Identifier ident,
long timestamp)
Load table metadata at a specific time by
identifier from the catalog. |
Table |
loadTable(Identifier ident,
String version)
Load table metadata of a specific version by
identifier from the catalog. |
String |
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.
|
void |
setDelegateCatalog(CatalogPlugin delegate)
This will be called only once by Spark to pass in the Spark built-in session catalog, after
CatalogPlugin.initialize(String, CaseInsensitiveStringMap) is called. |
boolean |
tableExists(Identifier ident)
Test whether a table exists using an
identifier from the catalog. |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
loadTable, useNullableQuerySchema
public final void setDelegateCatalog(CatalogPlugin delegate)
CatalogExtension
CatalogPlugin.initialize(String, CaseInsensitiveStringMap)
is called.setDelegateCatalog
in interface CatalogExtension
public String name()
CatalogPlugin
This method is only called after CatalogPlugin.initialize(String, CaseInsensitiveStringMap)
is
called to pass the catalog's name.
name
in interface CatalogPlugin
public final void initialize(String name, CaseInsensitiveStringMap options)
CatalogPlugin
This method is called once, just after the provider is instantiated.
initialize
in interface CatalogPlugin
name
- the name used to identify and load this catalogoptions
- a case-insensitive string map of configurationpublic java.util.Set<TableCatalogCapability> capabilities()
capabilities
in interface TableCatalog
public String[] defaultNamespace()
CatalogPlugin
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.
defaultNamespace
in interface CatalogPlugin
public Identifier[] listTables(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
TableCatalog
If the catalog supports views, this must return identifiers for only tables and not views.
listTables
in interface TableCatalog
namespace
- a multi-part namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional).public Table loadTable(Identifier ident) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
TableCatalog
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
loadTable
in interface TableCatalog
ident
- a table identifierorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewpublic Table loadTable(Identifier ident, long timestamp) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
TableCatalog
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
loadTable
in interface TableCatalog
ident
- a table identifiertimestamp
- timestamp of the table, which is microseconds since 1970-01-01 00:00:00 UTCorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewpublic Table loadTable(Identifier ident, String version) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
TableCatalog
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
loadTable
in interface TableCatalog
ident
- a table identifierversion
- version of the tableorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewpublic void invalidateTable(Identifier ident)
TableCatalog
identifier
.
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.
invalidateTable
in interface TableCatalog
ident
- a table identifierpublic boolean tableExists(Identifier ident)
TableCatalog
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this must return false.
tableExists
in interface TableCatalog
ident
- a table identifierpublic Table createTable(Identifier ident, StructType schema, Transform[] partitions, java.util.Map<String,String> properties) throws org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
TableCatalog
This is deprecated. Please override
TableCatalog.createTable(Identifier, Column[], Transform[], Map)
instead.
createTable
in interface TableCatalog
org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
public Table createTable(Identifier ident, Column[] columns, Transform[] partitions, java.util.Map<String,String> properties) throws org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException, org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
TableCatalog
createTable
in interface TableCatalog
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 propertiesTableCatalog.loadTable(Identifier)
if needed (e.g. CTAS).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)public Table alterTable(Identifier ident, TableChange... changes) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
TableCatalog
changes
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
.
alterTable
in interface TableCatalog
ident
- a table identifierchanges
- changes to apply to the tableorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewpublic boolean dropTable(Identifier ident)
TableCatalog
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.
dropTable
in interface TableCatalog
ident
- a table identifierpublic boolean purgeTable(Identifier ident)
TableCatalog
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
.
purgeTable
in interface TableCatalog
ident
- a table identifierpublic void renameTable(Identifier oldIdent, Identifier newIdent) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException, org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
TableCatalog
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 throws TableAlreadyExistsException
.
If the catalog does not support table renames between namespaces, it throws
UnsupportedOperationException
.
renameTable
in interface TableCatalog
oldIdent
- the table identifier of the existing table to renamenewIdent
- the new table identifier of the tableorg.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 viewpublic String[][] listNamespaces() throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
SupportsNamespaces
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.
listNamespaces
in interface SupportsNamespaces
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
public String[][] listNamespaces(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
SupportsNamespaces
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.
listNamespaces
in interface SupportsNamespaces
namespace
- a multi-part namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)public boolean namespaceExists(String[] namespace)
SupportsNamespaces
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.
namespaceExists
in interface SupportsNamespaces
namespace
- a multi-part namespacepublic java.util.Map<String,String> loadNamespaceMetadata(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
SupportsNamespaces
loadNamespaceMetadata
in interface SupportsNamespaces
namespace
- a multi-part namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)public void createNamespace(String[] namespace, java.util.Map<String,String> metadata) throws org.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException
SupportsNamespaces
createNamespace
in interface SupportsNamespaces
namespace
- a multi-part namespacemetadata
- a string map of properties for the given namespaceorg.apache.spark.sql.catalyst.analysis.NamespaceAlreadyExistsException
- If the namespace already existspublic void alterNamespace(String[] namespace, NamespaceChange... changes) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
SupportsNamespaces
alterNamespace
in interface SupportsNamespaces
namespace
- a multi-part namespacechanges
- a collection of changes to apply to the namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional)public boolean dropNamespace(String[] namespace, boolean cascade) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException, org.apache.spark.sql.catalyst.analysis.NonEmptyNamespaceException
SupportsNamespaces
If the catalog implementation does not support this operation, it may throw
UnsupportedOperationException
.
dropNamespace
in interface SupportsNamespaces
namespace
- a multi-part namespacecascade
- When true, deletes all objects under the namespaceorg.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 falsepublic UnboundFunction loadFunction(Identifier ident) throws org.apache.spark.sql.catalyst.analysis.NoSuchFunctionException
FunctionCatalog
identifier
from the catalog.loadFunction
in interface FunctionCatalog
ident
- a function identifierorg.apache.spark.sql.catalyst.analysis.NoSuchFunctionException
- If the function doesn't existpublic Identifier[] listFunctions(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
FunctionCatalog
If there are no functions in the namespace, implementations should return an empty array.
listFunctions
in interface FunctionCatalog
namespace
- a multi-part namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional).public boolean functionExists(Identifier ident)
FunctionCatalog
functionExists
in interface FunctionCatalog