From 086c333e934fd219344209fe342c02f7b61f174b Mon Sep 17 00:00:00 2001 From: Nick Hurt Date: Fri, 29 Nov 2024 17:21:38 +0000 Subject: [PATCH 1/3] Update _data_pipelines.py Added update data pipeline definition method --- src/sempy_labs/_data_pipelines.py | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/sempy_labs/_data_pipelines.py b/src/sempy_labs/_data_pipelines.py index 3062a6c4..6c9122b5 100644 --- a/src/sempy_labs/_data_pipelines.py +++ b/src/sempy_labs/_data_pipelines.py @@ -170,3 +170,53 @@ def get_data_pipeline_definition( payload = content["payload"].iloc[0] return _decode_b64(payload) + + +def update_data_pipeline_definition( + name: str, pipeline_content: str, workspace: Optional[str] = None +): + """ + Updates an existing data pipeline with a new definition. + + Parameters + ---------- + name : str + The name of the data pipeline. + pipeline_content : str + The data pipeline content (not in Base64 format). + workspace : str, default=None + The name of the workspace. + Defaults to None which resolves to the workspace of the attached lakehouse + or if no lakehouse attached, resolves to the workspace of the notebook. + """ + + (workspace, workspace_id) = resolve_workspace_name_and_id(workspace) + client = fabric.FabricRestClient() + pipeline_payload = base64.b64encode(pipeline_content.encode('utf-8')).decode('utf-8') + pipeline_id = fabric.resolve_item_id( + item_name=name, type="DataPipeline", workspace=workspace + ) + + request_body = { + "definition": { + "parts": [ + { + "path": "pipeline-content.json", + "payload": pipeline_payload, + "payloadType": "InlineBase64" + } + ] + } + } + + + response = client.post( + f"v1/workspaces/{workspace_id}/items/{pipeline_id}/updateDefinition", + json=request_body, + ) + + lro(client, response, return_status_code=True) + + print( + f"{icons.green_dot} The '{name}' pipeline was updated within the '{workspace}' workspace." + ) From 626d786c880ce2dd0ffe96662a1c0c58e33939e2 Mon Sep 17 00:00:00 2001 From: Nick Hurt Date: Mon, 9 Dec 2024 22:21:25 +0000 Subject: [PATCH 2/3] Update _data_pipelines.py Update pipeline_content to dict --- src/sempy_labs/_data_pipelines.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sempy_labs/_data_pipelines.py b/src/sempy_labs/_data_pipelines.py index 6c9122b5..461561a6 100644 --- a/src/sempy_labs/_data_pipelines.py +++ b/src/sempy_labs/_data_pipelines.py @@ -173,7 +173,7 @@ def get_data_pipeline_definition( def update_data_pipeline_definition( - name: str, pipeline_content: str, workspace: Optional[str] = None + name: str, pipeline_content: dict, workspace: Optional[str] = None ): """ Updates an existing data pipeline with a new definition. @@ -182,7 +182,7 @@ def update_data_pipeline_definition( ---------- name : str The name of the data pipeline. - pipeline_content : str + pipeline_content : dict The data pipeline content (not in Base64 format). workspace : str, default=None The name of the workspace. @@ -192,7 +192,7 @@ def update_data_pipeline_definition( (workspace, workspace_id) = resolve_workspace_name_and_id(workspace) client = fabric.FabricRestClient() - pipeline_payload = base64.b64encode(pipeline_content.encode('utf-8')).decode('utf-8') + pipeline_payload = base64.b64encode(json.dumps(pipeline_content).encode('utf-8')).decode('utf-8') pipeline_id = fabric.resolve_item_id( item_name=name, type="DataPipeline", workspace=workspace ) From 71d3b6d47a12b62cc4c18aa7fe22335e9f65cbb0 Mon Sep 17 00:00:00 2001 From: Nick Hurt Date: Mon, 9 Dec 2024 22:23:45 +0000 Subject: [PATCH 3/3] Update __init__.py Added new function to data_pipelines --- src/sempy_labs/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sempy_labs/__init__.py b/src/sempy_labs/__init__.py index 90cead12..b08ba761 100644 --- a/src/sempy_labs/__init__.py +++ b/src/sempy_labs/__init__.py @@ -60,6 +60,7 @@ create_data_pipeline, delete_data_pipeline, get_data_pipeline_definition, + update_data_pipeline_definition, ) from sempy_labs._eventhouses import ( create_eventhouse,