fixes 17648: add tags and description for tableau published data source (#17678)

* tableau data-source tags and description

* tweaks

* PR review

* change test description

* black formatting
This commit is contained in:
nicor88 2024-09-03 11:25:27 +02:00 committed by Onkar Ravgan
parent a477e23854
commit d068a59aa8
4 changed files with 50 additions and 2 deletions

View File

@ -148,6 +148,24 @@ class TableauSource(DashboardServiceSource):
logger.warning(f"Could not fetch owner data due to {err}")
return None
@staticmethod
def _get_data_models_tags(dataModels: [DataSource]) -> Set[str]:
"""
Get the tags from the data model in the upstreamDatasources
"""
tags = set()
try:
for data_model in dataModels:
# tags seems to be available for upstreamDatasources only, not for dataModels
for upstream_source in data_model.upstreamDatasources or []:
for tag in upstream_source.tags:
tags.add(tag.name)
except Exception as exc:
logger.debug(traceback.format_exc())
logger.warning(f"Error fetching tags from data models: {exc}")
return tags
def yield_tags(
self, dashboard_details: TableauDashboard
) -> Iterable[Either[OMetaTagAndClassification]]:
@ -160,8 +178,14 @@ class TableauSource(DashboardServiceSource):
for elem in container:
tags.update(elem.tags)
_tags = {tag.label for tag in tags}
# retrieve tags from data models
_data_models_tags = self._get_data_models_tags(dashboard_details.dataModels)
_all_tags = _tags.union(_data_models_tags)
yield from get_ometa_tag_and_classification(
tags=[tag.label for tag in tags],
tags=[tag for tag in _all_tags],
classification_name=TABLEAU_TAG_CATEGORY,
tag_description="Tableau Tag",
classification_description="Tags associated with tableau entities",
@ -201,13 +225,23 @@ class TableauSource(DashboardServiceSource):
self.status.filter(data_model_name, "Data model filtered out.")
return
try:
data_model_tags = data_model.tags or []
data_model_request = CreateDashboardDataModelRequest(
name=EntityName(data_model.id),
displayName=data_model_name,
description=Markdown(data_model.description)
if data_model.description
else None,
service=FullyQualifiedEntityName(self.context.get().dashboard_service),
dataModelType=data_model_type.value,
serviceType=DashboardServiceType.Tableau.value,
columns=self.get_column_info(data_model),
tags=get_tag_labels(
metadata=self.metadata,
tags=[tag.name for tag in data_model_tags],
classification_name=TABLEAU_TAG_CATEGORY,
include_tags=self.source_config.includeTags,
),
sql=self._get_datamodel_sql_query(data_model=data_model),
owners=self.get_owner_ref(dashboard_details=dashboard_details),
)

View File

@ -58,6 +58,14 @@ class TableauTag(BaseModel):
label: str
class TableauDataModelTag(BaseModel):
"""
Aux class for Tag object for Tableau Data Model
"""
name: str
class TableauOwner(TableauBaseModel):
"""
Aux class for Owner object of the tableau_api_lib response
@ -121,6 +129,8 @@ class UpstreamTable(BaseModel):
class DataSource(BaseModel):
id: str
name: Optional[str] = None
description: Optional[str] = None
tags: Optional[List[TableauDataModelTag]] = []
fields: Optional[List[DatasourceField]] = None
upstreamTables: Optional[List[UpstreamTable]] = None
upstreamDatasources: Optional[List["DataSource"]] = None

View File

@ -26,6 +26,10 @@ workbooks(filter:{{luid: "{workbook_id}"}}){{
upstreamDatasources{{
id
name
description
tags {{
name
}}
fields {{
id
name

View File

@ -1,5 +1,5 @@
"""
Test Domo Dashboard using the topology
Test Tableau Dashboard
"""
from unittest import TestCase