Skip to content

Commit

Permalink
add example to set default namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nkvuong committed May 2, 2024
1 parent 8d25659 commit 1b1275b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/settings/update_default_namespace.py
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)),
)

0 comments on commit 1b1275b

Please sign in to comment.