MCPcopy Create free account
hub / github.com/andre-salvati/databricks-template / get_warehouse_id

Function get_warehouse_id

scripts/_sdk_sql.py:5–30  ·  view source on GitHub ↗

Resolve a SQL warehouse to use for DDL. Picking warehouses[0] is fragile — the API returns warehouses in an implementation-defined order, so on a workspace with multiple warehouses we'd silently grab whichever one happens to be first. Instead: - If `name` is provided, look it up by

(workspace: WorkspaceClient, name: str | None = None)

Source from the content-addressed store, hash-verified

3
4
5def get_warehouse_id(workspace: WorkspaceClient, name: str | None = None) -> str:
6 """Resolve a SQL warehouse to use for DDL.
7
8 Picking warehouses[0] is fragile — the API returns warehouses in an
9 implementation-defined order, so on a workspace with multiple warehouses
10 we'd silently grab whichever one happens to be first. Instead:
11
12 - If `name` is provided, look it up by name (fail loudly if missing).
13 - Otherwise, succeed only if there's exactly one warehouse; fail with
14 a clear "ambiguous, pass --warehouse-name" error when there are many.
15 """
16 warehouses = list(workspace.warehouses.list())
17 if not warehouses:
18 raise ValueError("No SQL warehouse found. Please create one to run SQL statements.")
19
20 if name:
21 match = next((w for w in warehouses if w.name == name), None)
22 if match is None:
23 raise ValueError(f"SQL warehouse {name!r} not found. Available: {[w.name for w in warehouses]}")
24 return match.id
25
26 if len(warehouses) > 1:
27 raise ValueError(
28 f"Multiple SQL warehouses found ({[w.name for w in warehouses]}); pass --warehouse-name to disambiguate."
29 )
30 return warehouses[0].id
31
32
33def run_sql(workspace: WorkspaceClient, warehouse_id: str, sql: str) -> None:

Callers 3

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected