Skip to content

Commit cc1455c

Browse files
committed
Merge branch 'm-kovalsky/mlvapis'
2 parents 044a88f + 91e9292 commit cc1455c

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

src/sempy_labs/lakehouse/_materialized_lake_views.py

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from typing import Optional
22
from sempy_labs._helper_functions import (
3+
resolve_workspace_id,
34
resolve_workspace_name_and_id,
45
resolve_lakehouse_name_and_id,
56
_base_api,
7+
_create_dataframe,
68
)
79
from uuid import UUID
810
from sempy._utils._log import log
@@ -46,8 +48,6 @@ def refresh_materialized_lake_views(
4648

4749
response = _base_api(
4850
request=f"/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/jobs/instances?jobType=RefreshMaterializedLakeViews",
49-
method="post",
50-
status_codes=[202],
5151
)
5252

5353
print(
@@ -74,3 +74,93 @@ def refresh_materialized_lake_views(
7474
)
7575

7676
return df
77+
78+
79+
def _get_materialized_lake_views_schedule(
80+
lakehouse: Optional[str | UUID] = None, workspace: Optional[str | UUID] = None
81+
) -> pd.DataFrame:
82+
"""
83+
Get the schedule details for the MaterializedLakeViews job instance.
84+
85+
Parameters
86+
----------
87+
lakehouse : str | uuid.UUID, default=None
88+
The Fabric lakehouse name or ID.
89+
Defaults to None which resolves to the lakehouse attached to the notebook.
90+
workspace : str | uuid.UUID, default=None
91+
The Fabric workspace name or ID used by the lakehouse.
92+
Defaults to None which resolves to the workspace of the attached lakehouse
93+
or if no lakehouse attached, resolves to the workspace of the notebook.
94+
95+
Returns
96+
-------
97+
pandas.DataFrame
98+
A DataFrame containing the schedule details of the materialized lake views job instance.
99+
"""
100+
101+
workspace_id = resolve_workspace_id(workspace)
102+
(lakehouse_name, lakehouse_id) = resolve_lakehouse_name_and_id(
103+
lakehouse=lakehouse, workspace=workspace_id
104+
)
105+
106+
columns = {
107+
"Job Schedule Id": "string",
108+
"Enabled": "bool",
109+
"Created DateTime": "datetime",
110+
"Type": "string",
111+
"Start DateTime": "datetime",
112+
"End DateTime": "datetime",
113+
"Local TimeZoneId": "string",
114+
"Interval": "int",
115+
"Owner Id": "string",
116+
"Owner Type": "string",
117+
}
118+
119+
df = _create_dataframe(columns=columns)
120+
121+
response = _base_api(
122+
request=f"/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/jobs/RefreshMaterializedLakeViews/schedules",
123+
)
124+
125+
df = pd.json_normalize(response.json().get("value", []))
126+
127+
return df
128+
129+
130+
@log
131+
def _delete_materialized_lake_view_schedule(
132+
schedule_id: UUID,
133+
lakehouse: Optional[str | UUID] = None,
134+
workspace: Optional[str | UUID] = None,
135+
):
136+
"""
137+
Delete an existing Refresh MaterializedLakeViews schedule for a lakehouse.
138+
139+
This is a wrapper function for the following API: `Background Jobs - Delete Refresh Materialized Lake Views Schedule <https://learn.microsoft.com/rest/api/fabric/lakehouse/background-jobs/delete-refresh-materialized-lake-views-schedule>`_.
140+
141+
Parameters
142+
----------
143+
schedule_id : uuid.UUID
144+
The ID of the job schedule to delete.
145+
lakehouse : str | uuid.UUID, default=None
146+
The Fabric lakehouse name or ID.
147+
Defaults to None which resolves to the lakehouse attached to the notebook.
148+
workspace : str | uuid.UUID, default=None
149+
The Fabric workspace name or ID used by the lakehouse.
150+
Defaults to None which resolves to the workspace of the attached lakehouse
151+
or if no lakehouse attached, resolves to the workspace of the notebook.
152+
"""
153+
154+
workspace_id = resolve_workspace_id(workspace)
155+
(lakehouse_name, lakehouse_id) = resolve_lakehouse_name_and_id(
156+
lakehouse=lakehouse, workspace=workspace_id
157+
)
158+
159+
_base_api(
160+
request=f"/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}/jobs/RefreshMaterializedLakeViews/schedules/{schedule_id}",
161+
method="delete",
162+
)
163+
164+
print(
165+
f"{icons.green_dot} The materialized lake view schedule with ID '{schedule_id}' has been deleted from the '{lakehouse_name}' lakehouse within the '{workspace_id}' workspace."
166+
)

0 commit comments

Comments
 (0)