1- from typing import Optional
1+ from typing import Optional , List
22from uuid import UUID
33import requests
44from sempy ._utils ._log import log
1212 _base_api ,
1313 resolve_workspace_name_and_id ,
1414)
15+ import sempy_labs ._icons as icons
16+
17+
18+ _url_prefix = "https://onelake.table.fabric.microsoft.com/delta"
1519
1620
1721def _get_headers ():
@@ -30,38 +34,33 @@ def list_schemas(
3034
3135 columns = {
3236 "Schema Name" : "str" ,
33- # "Created At": "datetime",
34- # "Updated At": "datetime"
3537 }
3638 df = _create_dataframe (columns = columns )
3739 workspace_id = resolve_workspace_id (workspace )
3840 item_id = resolve_lakehouse_id (lakehouse , workspace )
3941 response = requests .get (
40- f"https://onelake.table.fabric.microsoft.com/delta /{ workspace_id } /{ item_id } /api/2.1/unity-catalog/schemas?catalog_name={ item_id } " ,
42+ f"{ _url_prefix } /{ workspace_id } /{ item_id } /api/2.1/unity-catalog/schemas?catalog_name={ item_id } " ,
4143 headers = _get_headers (),
4244 )
4345
4446 rows = []
4547 for s in response .json ().get ("schemas" , []):
4648 rows .append (
4749 {
48- "Schema Name" : s .get ("name" , {}),
49- # "Created At": s.get('created_at', {}),
50- # "Updated At": s.get('updated_at', {}),
50+ "Schema Name" : s .get ("name" , None ),
5151 }
5252 )
5353
5454 if rows :
5555 df = pd .DataFrame (rows , columns = list (columns .keys ()))
56- _update_dataframe_datatypes (df , columns )
5756
5857 return df
5958
6059
6160def list_tables (
6261 lakehouse : Optional [str | UUID ] = None ,
6362 workspace : Optional [str | UUID ] = None ,
64- schema : Optional [str ] = None ,
63+ schema : Optional [str | List [ str ] ] = None ,
6564) -> pd .DataFrame :
6665
6766 (workspace_name , workspace_id ) = resolve_workspace_name_and_id (workspace )
@@ -85,11 +84,16 @@ def list_tables(
8584 rows = []
8685 if schema_enabled :
8786 schemas = list_schemas (lakehouse = lakehouse , workspace = workspace )
87+ if schema :
88+ if isinstance (schema , str ):
89+ schema = [schema ]
90+ schemas = schemas [schemas ["Schema Name" ].isin (schema )]
91+
8892 # Loop through schemas
8993 for _ , r in schemas .iterrows ():
9094 schema_name = r ["Schema Name" ]
9195 response = requests .get (
92- f"https://onelake.table.fabric.microsoft.com/delta /{ workspace_id } /{ item_id } /api/2.1/unity-catalog/tables?catalog_name={ item_id } &schema_name={ schema_name } " ,
96+ f"{ _url_prefix } /{ workspace_id } /{ item_id } /api/2.1/unity-catalog/tables?catalog_name={ item_id } &schema_name={ schema_name } " ,
9397 headers = _get_headers (),
9498 )
9599 # Loop through tables
@@ -106,6 +110,10 @@ def list_tables(
106110 }
107111 )
108112 else :
113+ if schema :
114+ print (
115+ f"{ icons .info } The schema parameter has been ignored as the '{ item_name } ' lakehouse within the '{ workspace_name } ' workspace has schemas disabled."
116+ )
109117 responses = _base_api (
110118 request = f"v1/workspaces/{ workspace_id } /lakehouses/{ item_id } /tables" ,
111119 uses_pagination = True ,
0 commit comments