Skip to content

Commit e4dee0d

Browse files
committed
Merge branch 'm-kovalsky/975'
2 parents d096446 + a64768e commit e4dee0d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/sempy_labs/_model_bpa_bulk.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def run_model_bpa_bulk(
5555
"Workspace B": ["Dataset5", "Dataset 8"],
5656
}
5757
"""
58+
from sempy_labs.lakehouse._schemas import is_schema_enabled
5859

5960
if not lakehouse_attached():
6061
raise ValueError(
@@ -67,7 +68,9 @@ def run_model_bpa_bulk(
6768
skip_models.extend(["ModelBPA", "Fabric Capacity Metrics"])
6869

6970
now = datetime.datetime.now()
70-
output_table = "modelbparesults"
71+
schema_enabled = is_schema_enabled()
72+
output_table = "dbo/modelbparesults" if schema_enabled else "modelbparesults"
73+
7174
lakeT = get_lakehouse_tables()
7275
lakeT_filt = lakeT[lakeT["Table Name"] == output_table]
7376
if lakeT_filt.empty:

src/sempy_labs/lakehouse/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from ._schemas import (
3838
list_schemas,
3939
schema_exists,
40+
is_schema_enabled,
4041
)
4142

4243
__all__ = [
@@ -62,4 +63,5 @@
6263
"list_lakehouses",
6364
"list_schemas",
6465
"schema_exists",
66+
"is_schema_enabled",
6567
]

src/sempy_labs/lakehouse/_schemas.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@
1313
import sempy_labs._icons as icons
1414

1515

16+
@log
17+
def is_schema_enabled(
18+
lakehouse: Optional[str | UUID] = None, workspace: Optional[str | UUID] = None
19+
) -> bool:
20+
"""
21+
Indicates whether a lakehouse has schemas enabled.
22+
23+
Parameters
24+
----------
25+
lakehouse : str | uuid.UUID, default=None
26+
The Fabric lakehouse name or ID.
27+
Defaults to None which resolves to the lakehouse attached to the notebook.
28+
workspace : str | uuid.UUID, default=None
29+
The Fabric workspace name or ID used by the lakehouse.
30+
Defaults to None which resolves to the workspace of the attached lakehouse
31+
or if no lakehouse attached, resolves to the workspace of the notebook.
32+
33+
Returns
34+
-------
35+
bool
36+
Indicates whether the lakehouse has schemas enabled.
37+
"""
38+
workspace_id = resolve_workspace_id(workspace)
39+
(item_name, item_id) = resolve_lakehouse_name_and_id(lakehouse, workspace)
40+
response = _base_api(f"/v1/workspaces/{workspace_id}/lakehouses/{item_id}")
41+
default_schema = response.json().get("properties", {}).get("defaultSchema", None)
42+
if default_schema:
43+
return True
44+
else:
45+
return False
46+
47+
1648
@log
1749
def list_schemas(
1850
lakehouse: Optional[str | UUID] = None, workspace: Optional[str | UUID] = None

0 commit comments

Comments
 (0)