Skip to content
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion gooddata-sdk/gooddata_sdk/catalog/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from gooddata_sdk.catalog.base import Base, JsonApiEntityBase
from gooddata_sdk.compute.model.base import ObjId
from gooddata_sdk.utils import AllPagedEntities
from gooddata_sdk.utils import AllPagedEntities, safeget_list

T = TypeVar("T", bound="AttrCatalogEntity")

Expand Down Expand Up @@ -84,6 +84,10 @@ def from_api(
def client_class() -> Any:
return NotImplemented

def _relation_entity_from_side_loads(self, entity: builtins.type[T], path: list[str]) -> list[T]:
related_fact_ids = [(x.get("id"), x.get("type")) for x in safeget_list(self.json_api_relationships, path)]
return [entity.from_api(sl) for sl in self.json_api_side_loads if (sl["id"], sl["type"]) in related_fact_ids]


class CatalogEntity:
def __init__(self, entity: dict[str, Any]) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_full_catalog(self, workspace_id: str, inject_valid_objects_func: bool =
get_datasets = functools.partial(
self._entities_api.get_all_entities_datasets,
workspace_id,
include=["attributes", "facts"],
include=["attributes", "facts", "aggregatedFacts"],
_check_return_type=False,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CatalogDeclarativeDataset(Base):
attributes: Optional[list[CatalogDeclarativeAttribute]] = None
facts: Optional[list[CatalogDeclarativeFact]] = None
aggregated_facts: Optional[list[CatalogDeclarativeAggregatedFact]] = attrs.field(factory=list)
precedence: Optional[int] = None
data_source_table_id: Optional[CatalogDataSourceTableIdentifier] = None
sql: Optional[CatalogDeclarativeDatasetSql] = None
tags: Optional[list[str]] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ class CatalogAggregatedFact(AttrCatalogEntity):
def client_class() -> Any:
return JsonApiAggregatedFactOut

def as_computable(self) -> Metric:
return SimpleMetric(local_id=self.id, item=self.obj_id)

# as_computable skipped because aggregated fact cannot be ever used in metric
# TODO - dataset?


Expand All @@ -131,20 +129,22 @@ def generate_attributes_from_api(self) -> list[CatalogAttribute]:
repr=False,
default=attr.Factory(lambda self: self.generate_attributes_from_api(), takes_self=True),
)

def generate_facts_from_api(self) -> list[CatalogFact]:
related_fact_ids = [x.get("id") for x in safeget_list(self.json_api_relationships, ["facts", "data"])]
return [
CatalogFact.from_api(sl)
for sl in self.json_api_side_loads
if sl["type"] == "fact" and sl["id"] in related_fact_ids
]

facts: list[CatalogFact] = attr.field(
repr=False,
default=attr.Factory(lambda self: self.generate_facts_from_api(), takes_self=True),
default=attr.Factory(
lambda self: self._relation_entity_from_side_loads(CatalogFact, ["facts", "data"]), takes_self=True
),
)
aggregated_facts: Optional[list[CatalogAggregatedFact]] = attr.field(
repr=False,
default=attr.Factory(
lambda self: self._relation_entity_from_side_loads(CatalogAggregatedFact, ["aggregatedFacts", "data"]),
takes_self=True,
),
)
precedence: Optional[int] = attr.field(
default=attr.Factory(lambda self: self.json_api_attributes.get("precedence"), takes_self=True)
)

grain: Optional[list] = attr.field(
default=attr.Factory(lambda self: self.json_api_attributes.get("grain"), takes_self=True)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from gooddata_sdk.catalog.types import ValidObjects
from gooddata_sdk.catalog.workspace.entity_model.content_objects.dataset import (
CatalogAggregatedFact,
CatalogAttribute,
CatalogDataset,
CatalogFact,
Expand Down Expand Up @@ -46,6 +47,10 @@ def datasets(self) -> list[CatalogDataset]:
def facts(self) -> list[CatalogFact]:
return [f for d in self._datasets for f in d.facts]

@property
def aggregated_facts(self) -> list[CatalogAggregatedFact]:
return [f for d in self._datasets for f in (d.aggregated_facts if d.aggregated_facts else [])]

@property
def attributes(self) -> list[CatalogAttribute]:
return [a for d in self._datasets for a in d.attributes]
Expand Down
Loading
Loading