Skip to content

Commit

Permalink
Merge pull request #856 from hkad98/jkd/trivial
Browse files Browse the repository at this point in the history
fix: export_tabular_by_visualization_id does not need to call afm
  • Loading branch information
hkad98 authored Oct 21, 2024
2 parents 18913cc + 213eafe commit 838e6d7
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 562 deletions.
1 change: 1 addition & 0 deletions gooddata-sdk/gooddata_sdk/catalog/export/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ExportRequest(Base):
format: str
file_name: str
execution_result: Optional[str] = None
visualization_object: Optional[str] = None
settings: Optional[ExportSettings] = None
custom_override: Optional[ExportCustomOverride] = None

Expand Down
38 changes: 5 additions & 33 deletions gooddata-sdk/gooddata_sdk/catalog/export/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@

from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase
from gooddata_sdk.catalog.export.request import (
ExportCustomLabel,
ExportCustomMetric,
ExportCustomOverride,
ExportRequest,
ExportSettings,
)
from gooddata_sdk.client import GoodDataApiClient
from gooddata_sdk.compute.model.metric import SimpleMetric
from gooddata_sdk.table import ExecutionTable, TableService
from gooddata_sdk.visualization import VisualizationService


Expand Down Expand Up @@ -258,33 +253,12 @@ def export_tabular(
workspace_id, export_request.to_api(), file_path, create_func, get_func, timeout, retry, max_retry
)

@staticmethod
def _custom_overrides_labels(exec_table: ExecutionTable, metrics_format: str = "#,##0") -> ExportCustomOverride:
"""
Visualizations by default use generated hash as local_id,
therefore, we might want to use dummy logic to replace it.
For attributes by label.id
For metrics by item.id
"""
labels = {
attribute.local_id: ExportCustomLabel(title=attribute.label.id) for attribute in exec_table.attributes
}
metrics = {
metric.local_id: ExportCustomMetric(
title=metric.item.id if isinstance(metric, SimpleMetric) else metric.local_id, format=metrics_format
)
for metric in exec_table.metrics
}
return ExportCustomOverride(labels=labels, metrics=metrics)

def _get_visualization_exec_table(self, workspace_id: str, visualization_id: str) -> tuple[ExecutionTable, str]:
def _get_visualization_title(self, workspace_id: str, visualization_id: str) -> str:
try:
visualization = VisualizationService(self._client).get_visualization(
workspace_id=workspace_id, visualization_id=visualization_id
)
return TableService(self._client).for_visualization(
workspace_id=workspace_id, visualization=visualization
), visualization.title
return visualization.title
except NotFoundException:
raise ValueError(
f"Either workspace workspace_id='{workspace_id}' "
Expand Down Expand Up @@ -321,15 +295,13 @@ def export_tabular_by_visualization_id(
Returns:
None
"""
exec_table, visualization_tile = self._get_visualization_exec_table(workspace_id, visualization_id)
custom_override = self._custom_overrides_labels(exec_table)
file_name = file_name if file_name is not None else visualization_tile
if file_name is None:
file_name = self._get_visualization_title(workspace_id, visualization_id)
export_request = ExportRequest(
format=file_format,
execution_result=exec_table.result_id,
visualization_object=visualization_id,
file_name=file_name,
settings=settings,
custom_override=custom_override,
)
self.export_tabular(
workspace_id=workspace_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from attrs import define, field
from gooddata_api_client.model.declarative_notification_channel import DeclarativeNotificationChannel
from gooddata_api_client.model.webhook import Webhook

from gooddata_sdk.catalog.base import Base

# TODO: there is an issue with generated client which causes these two classes to fail
Expand Down
Loading

0 comments on commit 838e6d7

Please sign in to comment.