diff --git a/src/sempy_labs/_model_bpa_bulk.py b/src/sempy_labs/_model_bpa_bulk.py index 70a8a5dd..1ecf08f4 100644 --- a/src/sempy_labs/_model_bpa_bulk.py +++ b/src/sempy_labs/_model_bpa_bulk.py @@ -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( @@ -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: diff --git a/src/sempy_labs/lakehouse/__init__.py b/src/sempy_labs/lakehouse/__init__.py index 2e4bc1be..e0be4da7 100644 --- a/src/sempy_labs/lakehouse/__init__.py +++ b/src/sempy_labs/lakehouse/__init__.py @@ -37,6 +37,7 @@ from ._schemas import ( list_schemas, schema_exists, + is_schema_enabled, ) __all__ = [ @@ -62,4 +63,5 @@ "list_lakehouses", "list_schemas", "schema_exists", + "is_schema_enabled", ] diff --git a/src/sempy_labs/lakehouse/_schemas.py b/src/sempy_labs/lakehouse/_schemas.py index 59ef3dbc..75cb52a3 100644 --- a/src/sempy_labs/lakehouse/_schemas.py +++ b/src/sempy_labs/lakehouse/_schemas.py @@ -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