-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example to set default namespace
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from databricks.sdk import WorkspaceClient | ||
from databricks.sdk.errors import NotFound | ||
from databricks.sdk.service.settings import DefaultNamespaceSetting, StringMessage | ||
|
||
default_catalog = "hive_metastore" | ||
|
||
ws = WorkspaceClient() | ||
default_namespace = ws.settings.default_namespace | ||
|
||
# needs to get the etag first, before patching the setting | ||
try: | ||
etag = default_namespace.get().etag | ||
except NotFound as err: | ||
# if not found, the etag is returned in the header | ||
etag = err.details[0].metadata.get("etag") | ||
|
||
default_namespace.update( | ||
allow_missing=True, | ||
field_mask="namespace.value", | ||
setting=DefaultNamespaceSetting(etag=etag, namespace=StringMessage(default_catalog)), | ||
) |