Skip to content

Commit 04a3270

Browse files
committed
list_lakehouses
1 parent d8b960b commit 04a3270

File tree

3 files changed

+124
-19
lines changed

3 files changed

+124
-19
lines changed

src/sempy_labs/_list_functions.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sempy.fabric as fabric
22
from sempy_labs._helper_functions import (
3+
resolve_workspace_id,
34
resolve_workspace_name_and_id,
45
create_relationship_name,
56
format_dax_object_name,
@@ -616,33 +617,50 @@ def list_lakehouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
616617
"SQL Endpoint Connection String": "string",
617618
"SQL Endpoint ID": "string",
618619
"SQL Endpoint Provisioning Status": "string",
620+
"Schema Enabled": "bool",
621+
"Default Schema": "string",
622+
"Sensitivity Label Id": "string",
619623
}
620624
df = _create_dataframe(columns=columns)
621625

622-
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
626+
workspace_id = resolve_workspace_id(workspace)
623627

624628
responses = _base_api(
625629
request=f"/v1/workspaces/{workspace_id}/lakehouses",
626630
uses_pagination=True,
627631
client="fabric_sp",
628632
)
629633

634+
rows = []
630635
for r in responses:
631636
for v in r.get("value", []):
632637
prop = v.get("properties", {})
633638
sqlEPProp = prop.get("sqlEndpointProperties", {})
639+
default_schema = prop.get("defaultSchema", None)
634640

635-
new_data = {
636-
"Lakehouse Name": v.get("displayName"),
637-
"Lakehouse ID": v.get("id"),
638-
"Description": v.get("description"),
639-
"OneLake Tables Path": prop.get("oneLakeTablesPath"),
640-
"OneLake Files Path": prop.get("oneLakeFilesPath"),
641-
"SQL Endpoint Connection String": sqlEPProp.get("connectionString"),
642-
"SQL Endpoint ID": sqlEPProp.get("id"),
643-
"SQL Endpoint Provisioning Status": sqlEPProp.get("provisioningStatus"),
644-
}
645-
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
641+
rows.append(
642+
{
643+
"Lakehouse Name": v.get("displayName"),
644+
"Lakehouse ID": v.get("id"),
645+
"Description": v.get("description"),
646+
"OneLake Tables Path": prop.get("oneLakeTablesPath"),
647+
"OneLake Files Path": prop.get("oneLakeFilesPath"),
648+
"SQL Endpoint Connection String": sqlEPProp.get("connectionString"),
649+
"SQL Endpoint ID": sqlEPProp.get("id"),
650+
"SQL Endpoint Provisioning Status": sqlEPProp.get(
651+
"provisioningStatus"
652+
),
653+
"Schema Enabled": True if default_schema else False,
654+
"Default Schema": default_schema,
655+
"Sensitivity Label Id": v.get("sensitivityLabel", {}).get(
656+
"sensitivityLabelId"
657+
),
658+
}
659+
)
660+
661+
if rows:
662+
df = pd.DataFrame(rows, columns=list(columns.keys()))
663+
_update_dataframe_datatypes(dataframe=df, column_map=columns)
646664

647665
return df
648666

@@ -672,20 +690,25 @@ def list_datamarts(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
672690
}
673691
df = _create_dataframe(columns=columns)
674692

675-
(workspace_name, workspace_id) = resolve_workspace_name_and_id(workspace)
693+
workspace_id = resolve_workspace_id(workspace)
676694

677695
responses = _base_api(
678696
request=f"/v1/workspaces/{workspace_id}/datamarts", uses_pagination=True
679697
)
680698

699+
rows = []
681700
for r in responses:
682701
for v in r.get("value", []):
683-
new_data = {
684-
"Datamart Name": v.get("displayName"),
685-
"Datamart ID": v.get("id"),
686-
"Description": v.get("description"),
687-
}
688-
df = pd.concat([df, pd.DataFrame(new_data, index=[0])], ignore_index=True)
702+
rows.append(
703+
{
704+
"Datamart Name": v.get("displayName"),
705+
"Datamart ID": v.get("id"),
706+
"Description": v.get("description"),
707+
}
708+
)
709+
710+
if rows:
711+
df = pd.DataFrame(rows, columns=list(columns.keys()))
689712

690713
return df
691714

src/sempy_labs/lakehouse/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
optimize_lakehouse_tables,
1010
vacuum_lakehouse_tables,
1111
run_table_maintenance,
12+
list_lakehouses,
1213
)
1314
from ._shortcuts import (
1415
# create_shortcut,
@@ -54,4 +55,5 @@
5455
"update_lakehouse",
5556
"load_table",
5657
"refresh_materialized_lake_views",
58+
"list_lakehouses",
5759
]

src/sempy_labs/lakehouse/_lakehouse.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
resolve_workspace_name_and_id,
99
_create_spark_session,
1010
_pure_python_notebook,
11+
_create_dataframe,
12+
_update_dataframe_datatypes,
13+
resolve_workspace_id,
1114
)
1215
import sempy_labs._icons as icons
1316
import re
@@ -18,6 +21,83 @@
1821
)
1922

2023

24+
@log
25+
def list_lakehouses(workspace: Optional[str | UUID] = None) -> pd.DataFrame:
26+
"""
27+
Shows the lakehouses within a workspace.
28+
29+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
30+
31+
Parameters
32+
----------
33+
workspace : str | uuid.UUID, default=None
34+
The Fabric workspace name or ID.
35+
Defaults to None which resolves to the workspace of the attached lakehouse
36+
or if no lakehouse attached, resolves to the workspace of the notebook.
37+
38+
Returns
39+
-------
40+
pandas.DataFrame
41+
A pandas dataframe showing the lakehouses within a workspace.
42+
"""
43+
44+
columns = {
45+
"Lakehouse Name": "string",
46+
"Lakehouse ID": "string",
47+
"Description": "string",
48+
"OneLake Tables Path": "string",
49+
"OneLake Files Path": "string",
50+
"SQL Endpoint Connection String": "string",
51+
"SQL Endpoint ID": "string",
52+
"SQL Endpoint Provisioning Status": "string",
53+
"Schema Enabled": "bool",
54+
"Default Schema": "string",
55+
"Sensitivity Label Id": "string",
56+
}
57+
df = _create_dataframe(columns=columns)
58+
59+
workspace_id = resolve_workspace_id(workspace)
60+
61+
responses = _base_api(
62+
request=f"/v1/workspaces/{workspace_id}/lakehouses",
63+
uses_pagination=True,
64+
client="fabric_sp",
65+
)
66+
67+
rows = []
68+
for r in responses:
69+
for v in r.get("value", []):
70+
prop = v.get("properties", {})
71+
sqlEPProp = prop.get("sqlEndpointProperties", {})
72+
default_schema = prop.get("defaultSchema", None)
73+
74+
rows.append(
75+
{
76+
"Lakehouse Name": v.get("displayName"),
77+
"Lakehouse ID": v.get("id"),
78+
"Description": v.get("description"),
79+
"OneLake Tables Path": prop.get("oneLakeTablesPath"),
80+
"OneLake Files Path": prop.get("oneLakeFilesPath"),
81+
"SQL Endpoint Connection String": sqlEPProp.get("connectionString"),
82+
"SQL Endpoint ID": sqlEPProp.get("id"),
83+
"SQL Endpoint Provisioning Status": sqlEPProp.get(
84+
"provisioningStatus"
85+
),
86+
"Schema Enabled": True if default_schema else False,
87+
"Default Schema": default_schema,
88+
"Sensitivity Label Id": v.get("sensitivityLabel", {}).get(
89+
"sensitivityLabelId"
90+
),
91+
}
92+
)
93+
94+
if rows:
95+
df = pd.DataFrame(rows, columns=list(columns.keys()))
96+
_update_dataframe_datatypes(dataframe=df, column_map=columns)
97+
98+
return df
99+
100+
21101
@log
22102
def lakehouse_attached() -> bool:
23103
"""

0 commit comments

Comments
 (0)