@Evolving public interface TableCatalog extends CatalogPlugin
TableCatalog implementations may be case sensitive or case insensitive. Spark will pass
table identifiers
without modification. Field names passed to
alterTable(Identifier, TableChange...)
will be normalized to match the case used in the
table schema when updating, renaming, or dropping existing columns when catalyst analysis is case
insensitive.
Modifier and Type | Field and Description |
---|---|
static String |
OPTION_PREFIX
A prefix used to pass OPTIONS in table properties
|
static String |
PROP_COMMENT
A reserved property to specify the description of the table.
|
static String |
PROP_EXTERNAL
A reserved property to specify a table was created with EXTERNAL.
|
static String |
PROP_IS_MANAGED_LOCATION
A reserved property to indicate that the table location is managed, not user-specified.
|
static String |
PROP_LOCATION
A reserved property to specify the location of the table.
|
static String |
PROP_OWNER
A reserved property to specify the owner of the table.
|
static String |
PROP_PROVIDER
A reserved property to specify the provider of the table.
|
Modifier and Type | Method and Description |
---|---|
Table |
alterTable(Identifier ident,
TableChange... changes)
Apply a set of
changes to a table in the catalog. |
default java.util.Set<TableCatalogCapability> |
capabilities() |
default 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)
Deprecated.
|
boolean |
dropTable(Identifier ident)
Drop a table in the catalog.
|
default void |
invalidateTable(Identifier ident)
Invalidate cached table metadata for an
identifier . |
Identifier[] |
listTables(String[] namespace)
List the tables in a namespace from the catalog.
|
Table |
loadTable(Identifier ident)
Load table metadata by
identifier from the catalog. |
default Table |
loadTable(Identifier ident,
long timestamp)
Load table metadata at a specific time by
identifier from the catalog. |
default Table |
loadTable(Identifier ident,
java.util.Set<TableWritePrivilege> writePrivileges)
Load table metadata by
identifier from the catalog. |
default Table |
loadTable(Identifier ident,
String version)
Load table metadata of a specific version by
identifier from the catalog. |
default 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.
|
default boolean |
tableExists(Identifier ident)
Test whether a table exists using an
identifier from the catalog. |
default boolean |
useNullableQuerySchema()
If true, mark all the fields of the query schema as nullable when executing
CREATE/REPLACE TABLE ...
|
defaultNamespace, initialize, name
static final String PROP_LOCATION
static final String PROP_IS_MANAGED_LOCATION
static final String PROP_EXTERNAL
static final String PROP_COMMENT
static final String PROP_PROVIDER
static final String PROP_OWNER
static final String OPTION_PREFIX
default java.util.Set<TableCatalogCapability> capabilities()
Identifier[] listTables(String[] namespace) throws org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
If the catalog supports views, this must return identifiers for only tables and not views.
namespace
- a multi-part namespaceorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the namespace does not exist (optional).Table loadTable(Identifier ident) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
ident
- a table identifierorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewdefault Table loadTable(Identifier ident, java.util.Set<TableWritePrivilege> writePrivileges) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
identifier
from the catalog. Spark will write data
into this table later.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
ident
- a table identifierwritePrivileges
- org.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewdefault Table loadTable(Identifier ident, String version) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
ident
- a table identifierversion
- version of the tableorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
- If the table doesn't exist or is a viewdefault Table loadTable(Identifier ident, long timestamp) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this
must throw NoSuchTableException
.
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 viewdefault void invalidateTable(Identifier ident)
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.
ident
- a table identifierdefault boolean tableExists(Identifier ident)
identifier
from the catalog.
If the catalog supports views and contains a view for the identifier and not a table, this must return false.
ident
- a table identifier@Deprecated 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
This is deprecated. Please override
createTable(Identifier, Column[], Transform[], Map)
instead.
org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
org.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
default 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
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 propertiesloadTable(Identifier)
if needed (e.g. CTAS).org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
- If a table or view already exists for the identifierUnsupportedOperationException
- If a requested partition transform is not supportedorg.apache.spark.sql.catalyst.analysis.NoSuchNamespaceException
- If the identifier namespace does not exist (optional)default boolean useNullableQuerySchema()
Table alterTable(Identifier ident, TableChange... changes) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException
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
.
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 viewIllegalArgumentException
- If any change is rejected by the implementation.boolean dropTable(Identifier ident)
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.
ident
- a table identifierdefault boolean purgeTable(Identifier ident) throws UnsupportedOperationException
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
.
ident
- a table identifierUnsupportedOperationException
- If table purging is not supportedvoid renameTable(Identifier oldIdent, Identifier newIdent) throws org.apache.spark.sql.catalyst.analysis.NoSuchTableException, org.apache.spark.sql.catalyst.analysis.TableAlreadyExistsException
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
.
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 viewUnsupportedOperationException
- If the namespaces of old and new identifiers do not
match (optional)