w.schemas: Schemas¶
- class databricks.sdk.service.catalog.SchemasAPI¶
A schema (also called a database) is the second layer of Unity Catalog’s three-level namespace. A schema organizes tables, views, and functions. To access (or list) a table or view in a schema, users must have the USE_SCHEMA data permission on the schema and its parent catalog, and they must have the SELECT permission on the table or view.
- create(name: str, catalog_name: str [, comment: Optional[str], custom_max_retention_hours: Optional[int], properties: Optional[Dict[str, str]], storage_root: Optional[str]]) SchemaInfo¶
Usage:
import time from databricks.sdk import WorkspaceClient w = WorkspaceClient() new_catalog = w.catalogs.create(name=f"sdk-{time.time_ns()}") created = w.schemas.create(name=f"sdk-{time.time_ns()}", catalog_name=new_catalog.name) # cleanup w.catalogs.delete(name=new_catalog.name, force=True) w.schemas.delete(full_name=created.full_name)
Creates a new schema for catalog in the Metastore. The caller must be a metastore admin, or have the CREATE_SCHEMA privilege in the parent catalog.
- Parameters:
name – str Name of schema, relative to parent catalog.
catalog_name – str Name of parent catalog.
comment – str (optional) User-provided free-form text description.
custom_max_retention_hours – int (optional) Dropped objects in the schema remain recoverable for this number of hours before they are permanently purged. The value must be 0 or within the range allowed for the metastore. Schemas that do not set their own value inherit the parent catalog’s value.
properties – Dict[str,str] (optional) A map of key-value properties attached to the securable.
storage_root – str (optional) Managed tables and volumes in the schema are stored under this storage root URL. The path must be inside an external location on which the caller has the CREATE MANAGED STORAGE privilege. If omitted, managed data is stored under the parent catalog’s storage root, or under the metastore’s root storage location when the catalog has none. Schemas in Delta Sharing catalogs cannot have a storage root, and schemas in a federated Hive metastore catalog must set one.
- Returns:
- delete(full_name: str [, force: Optional[bool]])¶
Deletes the specified schema from the parent catalog. The caller must be the owner of the schema or an owner of the parent catalog.
- Parameters:
full_name – str Full name of the schema, in the form catalog_name.schema_name.
force – bool (optional) Force deletion even if the schema is not empty.
- get(full_name: str [, include_browse: Optional[bool]]) SchemaInfo¶
Usage:
import time from databricks.sdk import WorkspaceClient w = WorkspaceClient() new_catalog = w.catalogs.create(name=f"sdk-{time.time_ns()}") created = w.schemas.create(name=f"sdk-{time.time_ns()}", catalog_name=new_catalog.name) _ = w.schemas.get(full_name=created.full_name) # cleanup w.catalogs.delete(name=new_catalog.name, force=True) w.schemas.delete(full_name=created.full_name)
Gets the specified schema within the metastore. The caller must be a metastore admin, the owner of the schema, or a user that has the USE_SCHEMA privilege on the schema.
- Parameters:
full_name – str Full name of the schema, in the form catalog_name.schema_name.
include_browse – bool (optional) Whether to return the schema when the principal can only access selective metadata for it through the BROWSE privilege. The response then has browse_only set to true.
- Returns:
- list(catalog_name: str [, include_browse: Optional[bool], max_results: Optional[int], page_token: Optional[str]]) Iterator[SchemaInfo]¶
Usage:
import time from databricks.sdk import WorkspaceClient w = WorkspaceClient() new_catalog = w.catalogs.create(name=f"sdk-{time.time_ns()}") all = w.schemas.list(catalog_name=new_catalog.name) # cleanup w.catalogs.delete(name=new_catalog.name, force=True)
Gets an array of schemas for a catalog in the metastore. If the caller is the metastore admin or the owner of the parent catalog, all schemas for the catalog will be retrieved. Otherwise, only schemas owned by the caller (or for which the caller has the USE_SCHEMA privilege) will be retrieved. There is no guarantee of a specific ordering of the elements in the array.
NOTE: we recommend using max_results=0 to use the paginated version of this API. Unpaginated calls will be deprecated soon.
PAGINATION BEHAVIOR: When using pagination (max_results >= 0), a page may contain zero results while still providing a next_page_token. Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
- Parameters:
catalog_name – str Parent catalog for schemas of interest.
include_browse – bool (optional) Whether to include schemas for which the principal can only access selective metadata through the BROWSE privilege. Such schemas are returned with browse_only set to true.
max_results –
int (optional) Maximum number of schemas to return. If not set, all the schemas are returned (not recommended).
when set to a value greater than 0, the page length is the minimum of this value and a server configured value;
when set to 0, the page length is set to a server configured value (recommended);
when set to a value less than 0, an invalid parameter error is returned;
page_token – str (optional) Opaque pagination token to go to next page based on previous query.
- Returns:
Iterator over
SchemaInfo
- update(full_name: str [, comment: Optional[str], custom_max_retention_hours: Optional[int], enable_predictive_optimization: Optional[EnablePredictiveOptimization], new_name: Optional[str], owner: Optional[str], properties: Optional[Dict[str, str]]]) SchemaInfo¶
Usage:
import time from databricks.sdk import WorkspaceClient w = WorkspaceClient() new_catalog = w.catalogs.create(name=f"sdk-{time.time_ns()}") created = w.schemas.create(name=f"sdk-{time.time_ns()}", catalog_name=new_catalog.name) _ = w.schemas.update(full_name=created.full_name, comment=f"sdk-{time.time_ns()}") # cleanup w.catalogs.delete(name=new_catalog.name, force=True) w.schemas.delete(full_name=created.full_name)
Updates a schema for a catalog. The caller must be the owner of the schema or a metastore admin. If the caller is a metastore admin, only the owner field can be changed in the update. If the name field must be updated, the caller must be a metastore admin or have the CREATE_SCHEMA privilege on the parent catalog.
- Parameters:
full_name – str Full name of the schema, in the form catalog_name.schema_name.
comment – str (optional) User-provided free-form text description.
custom_max_retention_hours – int (optional) Dropped objects in the schema remain recoverable for this number of hours before they are permanently purged. The value must be 0 or within the range allowed for the metastore. Schemas that do not set their own value inherit the parent catalog’s value.
enable_predictive_optimization –
EnablePredictiveOptimization(optional) Whether predictive optimization is enabled for this schema and the objects under it. Valid values are ENABLE, DISABLE, and INHERIT, where INHERIT applies the parent catalog’s setting. New schemas start as INHERIT. It cannot be set when creating a schema; use the update method instead.new_name – str (optional) New name for the schema.
owner – str (optional) The user or group that owns the schema. The creator becomes the owner, and the owner can be changed only through the update method.
properties – Dict[str,str] (optional) A map of key-value properties attached to the securable.
- Returns: