From 1b1275b61cb5f1f7744fff1c4a2b27b1a9c42838 Mon Sep 17 00:00:00 2001 From: Vuong Date: Tue, 23 Apr 2024 10:28:34 +0100 Subject: [PATCH] add example to set default namespace --- examples/settings/update_default_namespace.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/settings/update_default_namespace.py diff --git a/examples/settings/update_default_namespace.py b/examples/settings/update_default_namespace.py new file mode 100644 index 00000000..d18d5da7 --- /dev/null +++ b/examples/settings/update_default_namespace.py @@ -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)), +)