diff --git a/src/sempy_labs/lakehouse/_shortcuts.py b/src/sempy_labs/lakehouse/_shortcuts.py index b7328d1a..b427dafa 100644 --- a/src/sempy_labs/lakehouse/_shortcuts.py +++ b/src/sempy_labs/lakehouse/_shortcuts.py @@ -1,6 +1,7 @@ import sempy.fabric as fabric import pandas as pd from sempy_labs._helper_functions import ( + resolve_item_name_and_id, resolve_lakehouse_name_and_id, resolve_workspace_name_and_id, _base_api, @@ -17,14 +18,16 @@ @log def create_shortcut_onelake( table_name: str, - source_lakehouse: str | UUID, source_workspace: str | UUID, destination_lakehouse: Optional[str | UUID] = None, destination_workspace: Optional[str | UUID] = None, shortcut_name: Optional[str] = None, + source_item: str | UUID = None, + source_item_type: str = "Lakehouse", source_path: str = "Tables", destination_path: str = "Tables", shortcut_conflict_policy: Optional[str] = None, + **kwargs, ): """ Creates a `shortcut `_ to a delta table in OneLake. @@ -37,10 +40,8 @@ def create_shortcut_onelake( ---------- table_name : str The table name for which a shortcut will be created. - source_lakehouse : str | uuid.UUID - The Fabric lakehouse in which the table resides. source_workspace : str | uuid.UUID - The name or ID of the Fabric workspace in which the source lakehouse exists. + The name or ID of the Fabric workspace in which the source data store exists. destination_lakehouse : str | uuid.UUID, default=None The Fabric lakehouse in which the shortcut will be created. Defaults to None which resolves to the lakehouse attached to the notebook. @@ -50,6 +51,10 @@ def create_shortcut_onelake( or if no lakehouse attached, resolves to the workspace of the notebook. shortcut_name : str, default=None The name of the shortcut 'table' to be created. This defaults to the 'table_name' parameter value. + source_item : str | uuid.UUID, default=None + The source Fabric data store item in which the table resides. Can be either the Name or ID of the item. + source_item_type: str, default="Lakehouse" + The source Fabric data store item type. Options are 'Lakehouse', 'Warehouse', 'MirroredDatabase', 'SQLDatabase', and 'KQLDatabase'. source_path : str, default="Tables" A string representing the full path to the table/file in the source lakehouse, including either "Files" or "Tables". Examples: Tables/FolderName/SubFolderName; Files/FolderName/SubFolderName. destination_path: str, default="Tables" @@ -58,6 +63,14 @@ def create_shortcut_onelake( When provided, it defines the action to take when a shortcut with the same name and path already exists. The default action is 'Abort'. Additional ShortcutConflictPolicy types may be added over time. """ + if source_item is None: + if "source_lakehouse" in kwargs: + source_item = kwargs.get("source_lakehouse") + else: + raise ValueError( + f"{icons.red_dot} The 'source_item' parameter must be provided." + ) + if not (source_path.startswith("Files") or source_path.startswith("Tables")): raise ValueError( f"{icons.red_dot} The 'source_path' parameter must be either 'Files' or 'Tables'." @@ -68,13 +81,20 @@ def create_shortcut_onelake( raise ValueError( f"{icons.red_dot} The 'destination_path' parameter must be either 'Files' or 'Tables'." ) + if not ( + source_item_type + in ["Lakehouse", "Warehouse", "MirroredDatabase", "SQLDatabase", "KQLDatabase"] + ): + raise ValueError( + f"{icons.red_dot} The 'source_item_type' parameter must be 'Lakehouse', 'Warehouse', 'MirroredDatabase', 'SQLDatabase', or 'KQLDatabase'" + ) (source_workspace_name, source_workspace_id) = resolve_workspace_name_and_id( source_workspace ) - (source_lakehouse_name, source_lakehouse_id) = resolve_lakehouse_name_and_id( - lakehouse=source_lakehouse, workspace=source_workspace_id + (source_item_name, source_item_id) = resolve_item_name_and_id( + item=source_item, type=source_item_type, workspace=source_workspace_id ) (destination_workspace_name, destination_workspace_id) = ( @@ -98,9 +118,9 @@ def create_shortcut_onelake( "name": actual_shortcut_name, "target": { "oneLake": { - "itemId": source_lakehouse_id, - "path": source_full_path, "workspaceId": source_workspace_id, + "itemId": source_item_id, + "path": source_full_path, } }, } @@ -143,7 +163,7 @@ def create_shortcut_onelake( ) print( - f"{icons.green_dot} The shortcut '{shortcut_name}' was created in the '{destination_lakehouse_name}' lakehouse within the '{destination_workspace_name}' workspace. It is based on the '{table_name}' table in the '{source_lakehouse_name}' lakehouse within the '{source_workspace_name}' workspace." + f"{icons.green_dot} The shortcut '{shortcut_name}' was created in the '{destination_lakehouse_name}' lakehouse within the '{destination_workspace_name}' workspace. It is based on the '{table_name}' table in the '{source_item_name}' {source_item_type} within the '{source_workspace_name}' workspace." )