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

feat(ingestion): Tableau # Embed links #6994

59 changes: 58 additions & 1 deletion metadata-ingestion/src/datahub/ingestion/source/tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
DashboardUsageStatisticsClass,
DataPlatformInstanceClass,
DatasetPropertiesClass,
EmbedClass,
OwnerClass,
OwnershipClass,
OwnershipTypeClass,
Expand Down Expand Up @@ -253,6 +254,11 @@ class TableauConfig(
default=None, description=""
)

ingest_embed_url: Optional[bool] = Field(
default=True,
description="Ingest a URL to render an embedded Preview of assets within Tableau.",
)


class WorkbookKey(PlatformKey):
workbook_id: str
Expand Down Expand Up @@ -1319,7 +1325,13 @@ def emit_sheets_as_charts(self, workbook: Dict) -> Iterable[MetadataWorkUnit]:
builder.make_global_tag_aspect_with_tag_list(tag_list_str)
)
yield self.get_metadata_change_event(chart_snapshot)

if sheet_external_url is not None and self.config.ingest_embed_url is True:
yield self.new_work_unit(
self.new_embed_aspect_mcp(
entity_urn=sheet_urn,
embed_url=sheet_external_url,
)
)
workunits = add_entity_to_container(
self.gen_workbook_key(workbook), "chart", chart_snapshot.urn
)
Expand Down Expand Up @@ -1463,6 +1475,43 @@ def _get_dashboard_stat_wu(
entityUrn=dashboard_urn,
).as_workunit()

@staticmethod
def new_mcp(
entity_urn: str,
aspect_name: str,
aspect: builder.Aspect,
change_type: Union[str, ChangeTypeClass] = ChangeTypeClass.UPSERT,
) -> MetadataChangeProposalWrapper:
"""
Create MCP
"""
return MetadataChangeProposalWrapper(
changeType=change_type,
entityUrn=entity_urn,
aspectName=aspect_name,
aspect=aspect,
)

@staticmethod
def new_embed_aspect_mcp(
entity_urn: str, embed_url: str
) -> MetadataChangeProposalWrapper:
return TableauSource.new_mcp(
entity_urn=entity_urn,
aspect_name=EmbedClass.ASPECT_NAME,
aspect=EmbedClass(renderUrl=embed_url),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

)

def new_work_unit(self, mcp: MetadataChangeProposalWrapper) -> MetadataWorkUnit:
return MetadataWorkUnit(
id="{PLATFORM}-{ENTITY_URN}-{ASPECT_NAME}".format(
PLATFORM=self.config.platform,
ENTITY_URN=mcp.entityUrn,
ASPECT_NAME=mcp.aspectName,
),
mcp=mcp,
)

def emit_dashboards(self, workbook: Dict) -> Iterable[MetadataWorkUnit]:
for dashboard in workbook.get("dashboards", []):
dashboard_urn: str = builder.make_dashboard_urn(
Expand Down Expand Up @@ -1533,6 +1582,14 @@ def emit_dashboards(self, workbook: Dict) -> Iterable[MetadataWorkUnit]:
dashboard_snapshot.aspects.append(owner)

yield self.get_metadata_change_event(dashboard_snapshot)
# Yield embed MCP
if self.config.ingest_embed_url is True:
yield self.new_work_unit(
self.new_embed_aspect_mcp(
entity_urn=dashboard_urn,
embed_url=dashboard_external_url,
)
)

workunits = add_entity_to_container(
self.gen_workbook_key(workbook), "dashboard", dashboard_snapshot.urn
Expand Down
Loading