Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update _data_pipelines.py #319

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/sempy_labs/_data_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,53 @@ def get_data_pipeline_definition(
payload = content["payload"].iloc[0]

return _decode_b64(payload)


def update_data_pipeline_definition(
hurtn marked this conversation as resolved.
Show resolved Hide resolved
name: str, pipeline_content: str, workspace: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't the content be in dict format? Check out the _conv_b64 function in sempy_labs._helper_functions.

let's use the parameter' content' instead of 'pipeline_content'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can change it to dict, was using your update notebook definition as a template

def update_notebook_definition(

LMK

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah but the content/definition for a notebook isn't in json format. it's in .py format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, make sense. i'll update tomorrow!

):
"""
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."
)