Skip to content

Commit db08d8b

Browse files
committed
update_warehouse_snapshot
1 parent f8e5dc5 commit db08d8b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/sempy_labs/warehouse_snapshot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
list_warehouse_snapshots,
33
delete_warehouse_snapshot,
44
create_warehouse_snapshot,
5+
update_warehouse_snapshot,
56
)
67

78
__all__ = [
89
"list_warehouse_snapshots",
910
"delete_warehouse_snapshot",
1011
"create_warehouse_snapshot",
12+
"update_warehouse_snapshot",
1113
]

src/sempy_labs/warehouse_snapshot/_items.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,66 @@ def create_warehouse_snapshot(
165165
print(
166166
f"{icons.green_dot} The warehouse snapshot '{name}' has been created in the workspace '{warehouse_snapshot_workspace_name}'."
167167
)
168+
169+
170+
@log
171+
def update_warehouse_snapshot(
172+
warehouse_snapshot: str | UUID,
173+
name: Optional[str] = None,
174+
description: Optional[str] = None,
175+
snapshot_datetime: Optional[datetime] = None,
176+
workspace: Optional[str | UUID] = None,
177+
):
178+
"""
179+
Updates the properties of a warehouse snapshot in the Fabric workspace.
180+
181+
This is a wrapper function for the following API: `Items - Update Warehouse Snapshot <https://learn.microsoft.com/rest/api/fabric/warehousesnapshot/items/update-warehouse-snapshot>`_.
182+
183+
Service Principal Authentication is supported (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
184+
185+
Parameters
186+
----------
187+
warehouse_snapshot : str | uuid.UUID
188+
The name or ID of the warehouse snapshot to update.
189+
name : str, optional
190+
The new name for the warehouse snapshot.
191+
description : str, optional
192+
The new description for the warehouse snapshot.
193+
snapshot_datetime : datetime, optional
194+
The new snapshot datetime for the warehouse snapshot.
195+
Example: "2024-10-15T13:00:00Z"
196+
workspace : str | uuid.UUID, optional
197+
The Fabric workspace name or ID.
198+
Defaults to None which resolves to the workspace of the attached lakehouse
199+
or if no lakehouse attached, resolves to the workspace of the notebook.
200+
"""
201+
workspace_id = resolve_workspace_id(workspace)
202+
warehouse_snapshot_id = resolve_item_id(
203+
item=warehouse_snapshot, type="WarehouseSnapshot", workspace=workspace_id
204+
)
205+
206+
payload = {}
207+
208+
if name:
209+
payload["displayName"] = name
210+
if description:
211+
payload["description"] = description
212+
if snapshot_datetime:
213+
payload["properties"] = {"snapshotDateTime": snapshot_datetime}
214+
215+
if not payload:
216+
print(
217+
f"{icons.yellow_dot} No updates provided for warehouse snapshot '{warehouse_snapshot}'."
218+
)
219+
return
220+
221+
_base_api(
222+
request=f"/v1/workspaces/{workspace_id}/warehousesnapshots/{warehouse_snapshot_id}",
223+
client="fabric_sp",
224+
method="patch",
225+
payload=payload,
226+
)
227+
228+
print(
229+
f"{icons.green_dot} The warehouse snapshot '{warehouse_snapshot}' has been updated."
230+
)

0 commit comments

Comments
 (0)