66import sempy_labs ._icons as icons
77from sempy ._utils ._log import log
88from sempy_labs ._helper_functions import (
9+ resolve_lakehouse_name_and_id ,
910 retry ,
1011 _convert_data_type ,
1112 resolve_dataset_name_and_id ,
@@ -83,7 +84,7 @@ def generate_direct_lake_semantic_model(
8384 workspace : Optional [str | UUID ] = None ,
8485 lakehouse : Optional [str ] = None ,
8586 lakehouse_workspace : Optional [str | UUID ] = None ,
86- schema : str = "dbo" ,
87+ schema : Optional [ str ] = None ,
8788 overwrite : bool = False ,
8889 refresh : bool = True ,
8990):
@@ -107,7 +108,7 @@ def generate_direct_lake_semantic_model(
107108 The Fabric workspace name or ID in which the lakehouse resides.
108109 Defaults to None which resolves to the workspace of the attached lakehouse
109110 or if no lakehouse attached, resolves to the workspace of the notebook.
110- schema : str, default="dbo"
111+ schema : str, default=None
111112 The schema used for the lakehouse.
112113 overwrite : bool, default=False
113114 If set to True, overwrites the existing semantic model if it already exists.
@@ -127,10 +128,16 @@ def generate_direct_lake_semantic_model(
127128 lakehouse_tables = [lakehouse_tables ]
128129
129130 (workspace_name , workspace_id ) = resolve_workspace_name_and_id (workspace )
130- if lakehouse_workspace is None :
131- lakehouse_workspace = workspace
131+ (lakehouse_workspace_name , lakehouse_workspace_id ) = resolve_workspace_name_and_id (
132+ lakehouse_workspace
133+ )
134+ (lakehouse_name , lakehouse_id ) = resolve_lakehouse_name_and_id (
135+ lakehouse , lakehouse_workspace_id
136+ )
132137
133- dfLT = get_lakehouse_tables (lakehouse = lakehouse , workspace = lakehouse_workspace )
138+ dfLT = get_lakehouse_tables (
139+ lakehouse = lakehouse_id , workspace = lakehouse_workspace_id
140+ )
134141
135142 icons .sll_tags .append ("GenerateDLModel" )
136143
@@ -141,9 +148,9 @@ def generate_direct_lake_semantic_model(
141148 f"{ icons .red_dot } The '{ t } ' table does not exist as a delta table in the '{ lakehouse } ' within the '{ workspace_name } ' workspace."
142149 )
143150
144- dfLC = get_lakehouse_columns (lakehouse = lakehouse , workspace = lakehouse_workspace )
151+ dfLC = get_lakehouse_columns (lakehouse = lakehouse , workspace = lakehouse_workspace_id )
145152 expr = generate_shared_expression (
146- item_name = lakehouse , item_type = "Lakehouse" , workspace = lakehouse_workspace
153+ item_name = lakehouse , item_type = "Lakehouse" , workspace = lakehouse_workspace_id
147154 )
148155 dfD = fabric .list_datasets (workspace = workspace_id , mode = "rest" )
149156 dfD_filt = dfD [dfD ["Dataset Name" ] == dataset ]
@@ -179,9 +186,17 @@ def dyn_connect():
179186
180187 for t in lakehouse_tables :
181188 tom .add_table (name = t )
182- tom .add_entity_partition (table_name = t , entity_name = t , schema_name = schema )
189+ tom .add_entity_partition (
190+ table_name = t , entity_name = t , schema_name = schema or "dbo"
191+ )
183192 dfLC_filt = dfLC [dfLC ["Table Name" ] == t ]
184- for i , r in dfLC_filt .iterrows ():
193+ if schema :
194+ dfLC_filt = dfLC_filt [dfLC_filt ["Schema Name" ] == schema ]
195+ if dfLC_filt .empty :
196+ raise ValueError (
197+ f"{ icons .red_dot } No columns found for the '{ t } ' table in the '{ lakehouse_name } ' lakehouse. Please ensure the table has columns and if a schema is provided, that the schema name is correct."
198+ )
199+ for _ , r in dfLC_filt .iterrows ():
185200 lakeCName = r ["Column Name" ]
186201 dType = r ["Data Type" ]
187202 dt = _convert_data_type (dType )
0 commit comments