77)
88from sempy ._utils ._log import log
99from sempy_labs .tom import connect_semantic_model
10- from typing import Optional
10+ from typing import Optional , List
1111import sempy_labs ._icons as icons
1212from uuid import UUID
1313import re
@@ -19,7 +19,9 @@ def _extract_expression_list(expression):
1919 """
2020
2121 pattern_sql = r'Sql\.Database\s*\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*\)'
22- pattern_no_sql = r'AzureStorage\.DataLake\(".*?/([0-9a-fA-F\-]{36})/([0-9a-fA-F\-]{36})"'
22+ pattern_no_sql = (
23+ r'AzureStorage\.DataLake\(".*?/([0-9a-fA-F\-]{36})/([0-9a-fA-F\-]{36})"'
24+ )
2325
2426 match_sql = re .search (pattern_sql , expression )
2527 match_no_sql = re .search (pattern_no_sql , expression )
@@ -102,7 +104,7 @@ def update_direct_lake_model_connection(
102104 source_type : str = "Lakehouse" ,
103105 source_workspace : Optional [str | UUID ] = None ,
104106 use_sql_endpoint : bool = True ,
105- tables : Optional [str ] = None ,
107+ tables : Optional [str | List [ str ] ] = None ,
106108):
107109 """
108110 Remaps a Direct Lake semantic model's SQL Endpoint connection to a new lakehouse/warehouse.
@@ -127,6 +129,10 @@ def update_direct_lake_model_connection(
127129 use_sql_endpoint : bool, default=True
128130 If True, the SQL Endpoint will be used for the connection.
129131 If False, Direct Lake over OneLake will be used.
132+ tables : str | List[str], default=None
133+ The name(s) of the table(s) to update in the Direct Lake semantic model.
134+ If None, all tables will be updated (if there is only one expression).
135+ If multiple tables are specified, they must be provided as a list.
130136 """
131137 if use_sql_endpoint :
132138 icons .sll_tags .append ("UpdateDLConnection_SQL" )
@@ -192,11 +198,16 @@ def update_direct_lake_model_connection(
192198 )
193199 else :
194200 import sempy
201+
195202 sempy .fabric ._client ._utils ._init_analysis_services ()
196203 import Microsoft .AnalysisServices .Tabular as TOM
204+
197205 expr_list = _extract_expression_list (shared_expression )
198206
199- expr_name = next ((name for name , exp in expression_dict .items () if exp == expr_list ), None )
207+ expr_name = next (
208+ (name for name , exp in expression_dict .items () if exp == expr_list ),
209+ None ,
210+ )
200211
201212 # If the expression does not already exist, create it
202213 def generate_unique_name (existing_names ):
@@ -218,15 +229,9 @@ def generate_unique_name(existing_names):
218229 f"{ icons .red_dot } The table '{ t_name } ' does not exist in the '{ dataset_name } ' semantic model within the '{ workspace_name } ' workspace."
219230 )
220231 p = next (p for p in tom .model .Tables [t_name ].Partitions )
221- entity_name = p .EntityName
222- schema_name = p .SchemaName
223232 if p .Mode != TOM .ModeType .DirectLake :
224233 raise ValueError (
225234 f"{ icons .red_dot } The table '{ t_name } ' in the '{ dataset_name } ' semantic model within the '{ workspace_name } ' workspace is not in Direct Lake mode. This function is only applicable to Direct Lake tables."
226235 )
227236
228- ep = TOM .EntityPartitionSource ()
229- ep .Source .EntityName = entity_name
230- ep .ExpressionSource = tom .model .Expressions [expr_name ]
231- ep .Source .SchemaName = schema_name
232- p .Source = ep
237+ p .Source .ExpressionSource = tom .model .Expressions [expr_name ]
0 commit comments