Skip to content

Commit

Permalink
Merge pull request #637 from gooddata/snapshot-master-4e1cec45-to-rel…
Browse files Browse the repository at this point in the history
…/dev

[bot] Merge master/4e1cec45 into rel/dev
  • Loading branch information
yenkins-admin authored Apr 16, 2024
2 parents 9bce4ae + 4e1cec4 commit 57f593c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gooddata-pandas/gooddata_pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ def for_exec_result_id(
result_size_dimensions_limits: ResultSizeDimensions = (),
result_size_bytes_limit: Optional[int] = None,
use_local_ids_in_headers: bool = False,
use_primary_labels_in_attributes: bool = False,
page_size: int = _DEFAULT_PAGE_SIZE,
) -> Tuple[pandas.DataFrame, DataFrameMetadata]:
"""
Expand Down Expand Up @@ -298,6 +299,7 @@ def for_exec_result_id(
result_size_dimensions_limits (ResultSizeDimensions): A tuple containing maximum size of result dimensions.
result_size_bytes_limit (Optional[int]): Maximum size of result in bytes.
use_local_ids_in_headers (bool): Use local identifier in headers.
use_primary_labels_in_attributes (bool): Use primary labels in attributes.
page_size (int): Number of records per page.
Returns:
Expand All @@ -322,5 +324,6 @@ def for_exec_result_id(
result_size_dimensions_limits=result_size_dimensions_limits,
result_size_bytes_limit=result_size_bytes_limit,
use_local_ids_in_headers=use_local_ids_in_headers,
use_primary_labels_in_attributes=use_primary_labels_in_attributes,
page_size=page_size,
)
16 changes: 15 additions & 1 deletion gooddata-pandas/gooddata_pandas/result_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def _create_header_mapper(
dim: int,
label_overrides: Optional[LabelOverrides] = None,
use_local_ids_in_headers: bool = False,
use_primary_labels_in_attributes: bool = False,
) -> Callable[[Any, Optional[int]], Optional[str]]:
"""
Prepares a header mapper function which translates header structures into appropriate labels used
Expand All @@ -317,6 +318,7 @@ def _create_header_mapper(
label_overrides (Optional[LabelOverrides]): Label overrides. Defaults to None.
use_local_ids_in_headers (bool): Use local identifiers of header attributes and metrics. Optional.
Defaults to False.
use_primary_labels_in_attributes (bool): Use primary labels in attributes. Optional. Defaults to False.
Returns:
Callable[[Any, Optional[int]], Optional[str]]: Mapper function.
Expand All @@ -334,7 +336,10 @@ def _mapper(header: Any, header_idx: Optional[int]) -> Optional[str]:
pass
elif "attributeHeader" in header:
if "labelValue" in header["attributeHeader"]:
label = header["attributeHeader"]["labelValue"]
if use_primary_labels_in_attributes:
label = header["attributeHeader"]["primaryLabelValue"]
else:
label = header["attributeHeader"]["labelValue"]
# explicitly handle '(empty value)' if it's None otherwise it's not recognizable in final MultiIndex
# backend represents ^^^ by "" (datasource value is "") or None (datasource value is NULL) therefore
# if both representation are used it's necessary to set label to unique header label (space) to avoid
Expand Down Expand Up @@ -376,6 +381,7 @@ def _headers_to_index(
response: BareExecutionResponse,
label_overrides: LabelOverrides,
use_local_ids_in_headers: bool = False,
use_primary_labels_in_attributes: bool = False,
) -> Optional[pandas.Index]:
"""Converts headers to a pandas MultiIndex.
Expand All @@ -388,6 +394,8 @@ def _headers_to_index(
response (BareExecutionResponse): The execution response object with all data.
label_overrides (LabelOverrides): A dictionary containing label overrides for the headers.
use_local_ids_in_headers (bool, optional): If True, uses local Ids in headers, otherwise not. Defaults to False.
use_primary_labels_in_attributes (bool, optional): If True, uses primary labels in attributes, otherwise not.
Defaults to False.
Returns:
Optional[pandas.Index]: A pandas MultiIndex object created from the headers, or None if the headers are empty.
Expand All @@ -400,6 +408,7 @@ def _headers_to_index(
dim=dim_idx,
label_overrides=label_overrides,
use_local_ids_in_headers=use_local_ids_in_headers,
use_primary_labels_in_attributes=use_primary_labels_in_attributes,
)

return pandas.MultiIndex.from_arrays(
Expand Down Expand Up @@ -467,6 +476,7 @@ def convert_execution_response_to_dataframe(
result_size_dimensions_limits: ResultSizeDimensions,
result_size_bytes_limit: Optional[int] = None,
use_local_ids_in_headers: bool = False,
use_primary_labels_in_attributes: bool = False,
page_size: int = _DEFAULT_PAGE_SIZE,
) -> Tuple[pandas.DataFrame, DataFrameMetadata]:
"""
Expand All @@ -480,6 +490,8 @@ def convert_execution_response_to_dataframe(
result_size_dimensions_limits (ResultSizeDimensions): Dimension limits for the dataframe.
result_size_bytes_limit (Optional[int], default=None): Size limit in bytes for the dataframe.
use_local_ids_in_headers (bool, default=False): Use local ids in headers if True, else use default settings.
use_primary_labels_in_attributes (bool, default=False): Use primary labels in attributes if True, else use
default settings.
page_size (int, default=_DEFAULT_PAGE_SIZE): Size of the page.
Returns:
Expand All @@ -503,13 +515,15 @@ def convert_execution_response_to_dataframe(
response=execution_response,
label_overrides=label_overrides,
use_local_ids_in_headers=use_local_ids_in_headers,
use_primary_labels_in_attributes=use_primary_labels_in_attributes,
),
columns=_headers_to_index(
dim_idx=1,
headers=full_headers,
response=execution_response,
label_overrides=label_overrides,
use_local_ids_in_headers=use_local_ids_in_headers,
use_primary_labels_in_attributes=use_primary_labels_in_attributes,
),
)

Expand Down
23 changes: 23 additions & 0 deletions gooddata-sdk/gooddata_sdk/catalog/workspace/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import attrs
from gooddata_api_client.exceptions import NotFoundException
from gooddata_api_client.model.resolve_settings_request import ResolveSettingsRequest

from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase
from gooddata_sdk.catalog.permission.service import CatalogPermissionService
Expand Down Expand Up @@ -188,6 +189,8 @@ def resolve_all_workspace_settings(self, workspace_id: str) -> dict:
:param workspace_id: Workspace ID
:return: Dict of settings
"""
# note: in case some settings were recently added and the API client was not regenerated it can fail on
# invalid value when validating allowed types on the client side before request is sent to the server
resolved_workspace_settings = [
setting.to_dict()
for setting in self._client.actions_api.workspace_resolve_all_settings(
Expand All @@ -197,6 +200,26 @@ def resolve_all_workspace_settings(self, workspace_id: str) -> dict:
]
return {setting["type"]: setting for setting in resolved_workspace_settings}

def resolve_workspace_settings(self, workspace_id: str, settings: list) -> dict:
"""
Resolves values for given settings in a workspace by current user, workspace, organization, or default settings
and return them as a dictionary. Proper parsing is up to the caller.
TODO: long-term we should return a proper entity object.
:param workspace_id: Workspace ID
:param settings: List of settings to resolve
:return: Dict of settings
"""
resolved_workspace_settings = [
setting.to_dict()
for setting in self._client.actions_api.workspace_resolve_settings(
workspace_id,
ResolveSettingsRequest(settings=settings),
_check_return_type=False,
)
]
return {setting["type"]: setting for setting in resolved_workspace_settings}

# Declarative methods - workspaces

def get_declarative_workspaces(self, exclude: Optional[List[str]] = None) -> CatalogDeclarativeWorkspaces:
Expand Down

0 comments on commit 57f593c

Please sign in to comment.