Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/sempy_labs/_model_bpa_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def run_model_bpa_bulk(
"Workspace B": ["Dataset5", "Dataset 8"],
}
"""
from sempy_labs.lakehouse._schemas import is_schema_enabled

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

now = datetime.datetime.now()
output_table = "modelbparesults"
schema_enabled = is_schema_enabled()
output_table = "dbo/modelbparesults" if schema_enabled else "modelbparesults"

lakeT = get_lakehouse_tables()
lakeT_filt = lakeT[lakeT["Table Name"] == output_table]
if lakeT_filt.empty:
Expand Down
2 changes: 2 additions & 0 deletions src/sempy_labs/lakehouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from ._schemas import (
list_schemas,
schema_exists,
is_schema_enabled,
)

__all__ = [
Expand All @@ -62,4 +63,5 @@
"list_lakehouses",
"list_schemas",
"schema_exists",
"is_schema_enabled",
]
32 changes: 32 additions & 0 deletions src/sempy_labs/lakehouse/_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
import sempy_labs._icons as icons


@log
def is_schema_enabled(
lakehouse: Optional[str | UUID] = None, workspace: Optional[str | UUID] = None
) -> bool:
"""
Indicates whether a lakehouse has schemas enabled.

Parameters
----------
lakehouse : str | uuid.UUID, default=None
The Fabric lakehouse name or ID.
Defaults to None which resolves to the lakehouse attached to the notebook.
workspace : str | uuid.UUID, default=None
The Fabric workspace name or ID used by the lakehouse.
Defaults to None which resolves to the workspace of the attached lakehouse
or if no lakehouse attached, resolves to the workspace of the notebook.

Returns
-------
bool
Indicates whether the lakehouse has schemas enabled.
"""
workspace_id = resolve_workspace_id(workspace)
(item_name, item_id) = resolve_lakehouse_name_and_id(lakehouse, workspace)
response = _base_api(f"/v1/workspaces/{workspace_id}/lakehouses/{item_id}")
default_schema = response.json().get("properties", {}).get("defaultSchema", None)
if default_schema:
return True
else:
return False


@log
def list_schemas(
lakehouse: Optional[str | UUID] = None, workspace: Optional[str | UUID] = None
Expand Down
Loading