Skip to content
Merged

895 #899

Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/sempy_labs/_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def import_notebook_from_web(
if len(dfI_filt) == 0:
create_notebook(
name=notebook_name,
notebook_content=response.content.decode('utf-8'),
notebook_content=response.content.decode("utf-8"),
workspace=workspace_id,
description=description,
format="ipynb",
Expand Down Expand Up @@ -216,7 +216,9 @@ def create_notebook(
Defaults to None which places the notebook in the root of the workspace.
"""

notebook_payload = base64.b64encode(notebook_content.encode('utf-8')).decode("utf-8")
notebook_payload = base64.b64encode(notebook_content.encode("utf-8")).decode(
"utf-8"
)

definition_payload = {
"parts": [
Expand Down
58 changes: 51 additions & 7 deletions src/sempy_labs/directlake/_update_directlake_partition_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import List, Optional, Union
import sempy_labs._icons as icons
from uuid import UUID
import json


@log
Expand Down Expand Up @@ -76,6 +77,7 @@ def update_direct_lake_partition_entity(
for p in t.Partitions
if t.Name == tName
)
current_slt = tom.model.Tables[tName].SourceLineageTag

if part_name is None:
raise ValueError(
Expand All @@ -85,14 +87,56 @@ def update_direct_lake_partition_entity(
tom.model.Tables[tName].Partitions[part_name].Source.EntityName = eName

# Update source lineage tag
existing_schema = (
tom.model.Tables[tName].Partitions[part_name].Source.SchemaName or "dbo"
)
if schema is None:
schema = existing_schema
if schema:
# Only set schema for DL over SQL (not DL over OneLake)
expression_source_name = (
tom.model.Tables[tName]
.Partitions[part_name]
.Source.ExpressionSource.Name
)
expr = tom.model.Expressions[expression_source_name].Expression
if "Sql.Database" in expr:
tom.model.Tables[tName].Partitions[
part_name
].Source.SchemaName = schema
tom.model.Tables[tName].SourceLineageTag = f"[{schema}].[{eName}]"
else:
tom.model.Tables[tName].SourceLineageTag = f"[dbo].[{eName}]"

new_slt = tom.model.Tables[tName].SourceLineageTag

# PBI_RemovedChildren logic
try:
e_name = (
tom.model.Tables[tName]
.Partitions[part_name]
.Source.ExpressionSource.Name
)
ann = tom.get_annotation_value(
object=tom.model.Expressions[e_name], name="PBI_RemovedChildren"
)
if ann:
e = json.loads(ann)
for i in e:
sltag = (
i.get("remoteItemId", {})
.get("analysisServicesObject", {})
.get("sourceLineageTag", {})
)
if sltag == current_slt:
i["remoteItemId"]["analysisServicesObject"][
"sourceLineageTag"
] = new_slt
tom.set_annotation(
object=tom.model.Expressions[e_name],
name="PBI_RemovedChildren",
value=json.dumps(e),
)
except Exception as e:
print(
f"{icons.yellow_dot} Warning: Could not update PBI_RemovedChildren annotation for table '{tName}'. {str(e)}"
)

tom.model.Tables[tName].Partitions[part_name].Source.SchemaName = schema
tom.model.Tables[tName].SourceLineageTag = f"[{schema}].[{eName}]"
print(
f"{icons.green_dot} The '{tName}' table in the '{dataset_name}' semantic model within the '{workspace_name}' workspace has been updated to point to the '{eName}' table."
)
Expand Down