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

fix: export_tabular_by_visualization_id does not need to call afm #856

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
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,
Vojtasii marked this conversation as resolved.
Show resolved Hide resolved
)
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
Loading