Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/workspace/catalog/catalogs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

w = WorkspaceClient()

created = w.catalogs.create(name=f"sdk-{time.time_ns()}")
created_catalog = w.catalogs.create(name=f"sdk-{time.time_ns()}")

# cleanup
w.catalogs.delete(name=created.name, force=True)
w.catalogs.delete(name=created_catalog.name, force=True)

Creates a new catalog instance in the parent metastore if the caller is a metastore admin or has the
**CREATE_CATALOG** privilege.
Expand Down Expand Up @@ -156,12 +156,13 @@
import time

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import catalog

w = WorkspaceClient()

created = w.catalogs.create(name=f"sdk-{time.time_ns()}")

_ = w.catalogs.update(name=created.name, comment="updated")
_ = w.catalogs.update(name=created.name, isolation_mode=catalog.CatalogIsolationMode.ISOLATED)

# cleanup
w.catalogs.delete(name=created.name, force=True)
Expand Down
34 changes: 16 additions & 18 deletions docs/workspace/catalog/external_locations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@

w = WorkspaceClient()

storage_credential = w.storage_credentials.create(
credential = w.storage_credentials.create(
name=f"sdk-{time.time_ns()}",
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
comment="created via SDK",
)

external_location = w.external_locations.create(
created = w.external_locations.create(
name=f"sdk-{time.time_ns()}",
credential_name=storage_credential.name,
comment="created via SDK",
url="s3://" + os.environ["TEST_BUCKET"] + "/" + f"sdk-{time.time_ns()}",
credential_name=credential.name,
url="s3://%s/%s" % (os.environ["TEST_BUCKET"], f"sdk-{time.time_ns()}"),
)

# cleanup
w.storage_credentials.delete(name=storage_credential.name)
w.external_locations.delete(name=external_location.name)
w.storage_credentials.delete(name=credential.name)
w.external_locations.delete(name=created.name)

Creates a new external location entry in the metastore. The caller must be a metastore admin or have
the **CREATE_EXTERNAL_LOCATION** privilege on both the metastore and the associated storage
Expand Down Expand Up @@ -107,20 +105,20 @@

credential = w.storage_credentials.create(
name=f"sdk-{time.time_ns()}",
aws_iam_role=catalog.AwsIamRole(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
)

created = w.external_locations.create(
name=f"sdk-{time.time_ns()}",
credential_name=credential.name,
url=f's3://{os.environ["TEST_BUCKET"]}/sdk-{time.time_ns()}',
url="s3://%s/%s" % (os.environ["TEST_BUCKET"], f"sdk-{time.time_ns()}"),
)

_ = w.external_locations.get(get=created.name)
_ = w.external_locations.get(name=created.name)

# cleanup
w.storage_credentials.delete(delete=credential.name)
w.external_locations.delete(delete=created.name)
w.storage_credentials.delete(name=credential.name)
w.external_locations.delete(name=created.name)

Gets an external location from the metastore. The caller must be either a metastore admin, the owner
of the external location, or a user that has some privilege on the external location.
Expand Down Expand Up @@ -194,24 +192,24 @@

credential = w.storage_credentials.create(
name=f"sdk-{time.time_ns()}",
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
aws_iam_role=catalog.AwsIamRole(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
)

created = w.external_locations.create(
name=f"sdk-{time.time_ns()}",
credential_name=credential.name,
url="s3://%s/%s" % (os.environ["TEST_BUCKET"], f"sdk-{time.time_ns()}"),
url=f's3://{os.environ["TEST_BUCKET"]}/sdk-{time.time_ns()}',
)

_ = w.external_locations.update(
name=created.name,
credential_name=credential.name,
url="s3://%s/%s" % (os.environ["TEST_BUCKET"], f"sdk-{time.time_ns()}"),
url=f's3://{os.environ["TEST_BUCKET"]}/sdk-{time.time_ns()}',
)

# cleanup
w.storage_credentials.delete(name=credential.name)
w.external_locations.delete(name=created.name)
w.storage_credentials.delete(delete=credential.name)
w.external_locations.delete(delete=created.name)

Updates an external location in the metastore. The caller must be the owner of the external location,
or be a metastore admin. In the second case, the admin can only update the name of the external
Expand Down
10 changes: 5 additions & 5 deletions docs/workspace/catalog/storage_credentials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

created = w.storage_credentials.create(
name=f"sdk-{time.time_ns()}",
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
aws_iam_role=catalog.AwsIamRole(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
)

# cleanup
w.storage_credentials.delete(name=created.name)
w.storage_credentials.delete(delete=created.name)

Creates a new storage credential.

Expand Down Expand Up @@ -98,13 +98,13 @@

created = w.storage_credentials.create(
name=f"sdk-{time.time_ns()}",
aws_iam_role=catalog.AwsIamRoleRequest(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
aws_iam_role=catalog.AwsIamRole(role_arn=os.environ["TEST_METASTORE_DATA_ACCESS_ARN"]),
)

by_name = w.storage_credentials.get(name=created.name)
by_name = w.storage_credentials.get(get=created.name)

# cleanup
w.storage_credentials.delete(name=created.name)
w.storage_credentials.delete(delete=created.name)

Gets a storage credential from the metastore. The caller must be a metastore admin, the owner of the
storage credential, or have some permission on the storage credential.
Expand Down
3 changes: 1 addition & 2 deletions docs/workspace/compute/clusters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,10 @@
.. code-block::

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import compute

w = WorkspaceClient()

all = w.clusters.list(compute.ListClustersRequest())
nodes = w.clusters.list_node_types()

Return information about all pinned and active clusters, and all clusters terminated within the last
30 days. Clusters terminated prior to this period are not included.
Expand Down
44 changes: 10 additions & 34 deletions docs/workspace/jobs/jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,21 +357,23 @@
w.clusters.ensure_cluster_is_running(os.environ["DATABRICKS_CLUSTER_ID"]) and os.environ["DATABRICKS_CLUSTER_ID"]
)

run = w.jobs.submit(
run_name=f"sdk-{time.time_ns()}",
created_job = w.jobs.create(
name=f"sdk-{time.time_ns()}",
tasks=[
jobs.SubmitTask(
jobs.Task(
description="test",
existing_cluster_id=cluster_id,
notebook_task=jobs.NotebookTask(notebook_path=notebook_path),
task_key=f"sdk-{time.time_ns()}",
task_key="test",
timeout_seconds=0,
)
],
).result()
)

output = w.jobs.get_run_output(run_id=run.tasks[0].run_id)
by_id = w.jobs.get(job_id=created_job.job_id)

# cleanup
w.jobs.delete_run(run_id=run.run_id)
w.jobs.delete(job_id=created_job.job_id)

Get a single job.

Expand Down Expand Up @@ -520,37 +522,11 @@

.. code-block::

import os
import time

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import jobs

w = WorkspaceClient()

notebook_path = f"/Users/{w.current_user.me().user_name}/sdk-{time.time_ns()}"

cluster_id = (
w.clusters.ensure_cluster_is_running(os.environ["DATABRICKS_CLUSTER_ID"]) and os.environ["DATABRICKS_CLUSTER_ID"]
)

created_job = w.jobs.create(
name=f"sdk-{time.time_ns()}",
tasks=[
jobs.Task(
description="test",
existing_cluster_id=cluster_id,
notebook_task=jobs.NotebookTask(notebook_path=notebook_path),
task_key="test",
timeout_seconds=0,
)
],
)

run_list = w.jobs.list_runs(job_id=created_job.job_id)

# cleanup
w.jobs.delete(job_id=created_job.job_id)
job_list = w.jobs.list(expand_tasks=False)

List jobs.

Expand Down
11 changes: 7 additions & 4 deletions docs/workspace/ml/model_registry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
w = WorkspaceClient()

model = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")

created = w.model_registry.create_model_version(name=model.registered_model.name, source="dbfs:/tmp")

Creates a new registered model with the name specified in the request body. Throws
`RESOURCE_ALREADY_EXISTS` if a registered model with the given name exists.
Expand Down Expand Up @@ -734,13 +736,14 @@

w = WorkspaceClient()

created = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")
model = w.model_registry.create_model(name=f"sdk-{time.time_ns()}")

model = w.model_registry.get_model(name=created.registered_model.name)
created = w.model_registry.create_model_version(name=model.registered_model.name, source="dbfs:/tmp")

w.model_registry.update_model(
name=model.registered_model_databricks.name,
w.model_registry.update_model_version(
description=f"sdk-{time.time_ns()}",
name=created.model_version.name,
version=created.model_version.version,
)

Updates a registered model.
Expand Down
2 changes: 1 addition & 1 deletion docs/workspace/sql/queries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
display_name=f"sdk-{time.time_ns()}",
warehouse_id=srcs[0].warehouse_id,
description="test query from Go SDK",
query_text="SELECT 1",
query_text="SHOW TABLES",
)
)

Expand Down
17 changes: 5 additions & 12 deletions docs/workspace/workspace/workspace.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

notebook = f"/Users/{w.current_user.me().user_name}/sdk-{time.time_ns()}"

export_response = w.workspace.export(format=workspace.ExportFormat.SOURCE, path=notebook)
export_response = w.workspace.export_(format=workspace.ExportFormat.SOURCE, path=notebook)

Exports an object or the contents of an entire directory.

Expand Down Expand Up @@ -175,18 +175,11 @@
notebook_path = f"/Users/{w.current_user.me().user_name}/sdk-{time.time_ns()}"

w.workspace.import_(
path=notebook_path,
overwrite=True,
content=base64.b64encode(("CREATE LIVE TABLE dlt_sample AS SELECT 1").encode()).decode(),
format=workspace.ImportFormat.SOURCE,
language=workspace.Language.PYTHON,
content=base64.b64encode(
(
"""import time
time.sleep(10)
dbutils.notebook.exit('hello')
"""
).encode()
).decode(),
language=workspace.Language.SQL,
overwrite=true_,
path=notebook_path,
)

Imports a workspace object (for example, a notebook or file) or the contents of an entire directory.
Expand Down
Loading