Skip to content

Commit fe429ac

Browse files
committed
feat: add declarative api for agg fact
risk: low
1 parent f7d0935 commit fe429ac

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

gooddata-sdk/gooddata_sdk/catalog/workspace/content_service.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from gooddata_sdk.catalog.workspace.declarative_model.workspace.logical_model.ldm import CatalogDeclarativeModel
2222
from gooddata_sdk.catalog.workspace.declarative_model.workspace.workspace import LAYOUT_WORKSPACES_DIR
2323
from gooddata_sdk.catalog.workspace.entity_model.content_objects.dataset import (
24+
CatalogAggregatedFact,
2425
CatalogAttribute,
2526
CatalogFact,
2627
CatalogLabel,
@@ -191,6 +192,24 @@ def get_facts_catalog(self, workspace_id: str) -> list[CatalogFact]:
191192
catalog_facts = [CatalogFact.from_api(fact) for fact in facts.data]
192193
return catalog_facts
193194

195+
def get_aggregated_facts_catalog(self, workspace_id: str) -> list[CatalogAggregatedFact]:
196+
"""Retrieve all facts in a given workspace.
197+
198+
Args:
199+
workspace_id (str):
200+
Workspace identification string e.g. "demo"
201+
202+
Returns:
203+
list[CatalogFact]:
204+
List of all facts in a given workspace.
205+
"""
206+
get_agg_facts = functools.partial(
207+
self._entities_api.get_all_entities_aggregated_facts, workspace_id, _check_return_type=False
208+
)
209+
facts = load_all_entities(get_agg_facts)
210+
catalog_facts = [CatalogAggregatedFact.from_api(fact) for fact in facts.data]
211+
return catalog_facts
212+
194213
def get_dependent_entities_graph(self, workspace_id: str) -> CatalogDependentEntitiesResponse:
195214
"""There are dependencies among all catalog objects, the chain is the following:
196215
`fact/attribute/label → dataset → metric → visualization → dashboard`

gooddata-sdk/gooddata_sdk/catalog/workspace/declarative_model/workspace/logical_model/dataset/dataset.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import attr
88
from gooddata_api_client.model.data_source_table_identifier import DataSourceTableIdentifier
9+
from gooddata_api_client.model.declarative_aggregated_fact import DeclarativeAggregatedFact
910
from gooddata_api_client.model.declarative_attribute import DeclarativeAttribute
1011
from gooddata_api_client.model.declarative_dataset import DeclarativeDataset
1112
from gooddata_api_client.model.declarative_dataset_sql import DeclarativeDatasetSql
@@ -34,6 +35,7 @@ class CatalogDeclarativeDataset(Base):
3435
description: Optional[str] = None
3536
attributes: Optional[list[CatalogDeclarativeAttribute]] = None
3637
facts: Optional[list[CatalogDeclarativeFact]] = None
38+
agg_facts: Optional[list[CatalogDeclarativeFact]] = None
3739
data_source_table_id: Optional[CatalogDataSourceTableIdentifier] = None
3840
sql: Optional[CatalogDeclarativeDatasetSql] = None
3941
tags: Optional[list[str]] = None
@@ -86,6 +88,21 @@ def client_class() -> type[DeclarativeFact]:
8688
return DeclarativeFact
8789

8890

91+
@attr.s(auto_attribs=True, kw_only=True)
92+
class CatalogDeclarativeAggregatedFact(Base):
93+
id: str
94+
source_column: str
95+
# The type here is wrong
96+
source_fact_reference: Optional[CatalogReferenceIdentifier] = None
97+
source_column_data_type: Optional[str] = None
98+
description: Optional[str] = None
99+
tags: Optional[list[str]] = None
100+
101+
@staticmethod
102+
def client_class() -> type[DeclarativeFact]:
103+
return DeclarativeAggregatedFact
104+
105+
89106
@attr.s(auto_attribs=True, kw_only=True)
90107
class CatalogDataSourceTableIdentifier(Base):
91108
id: str

gooddata-sdk/gooddata_sdk/catalog/workspace/entity_model/content_objects/dataset.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def as_computable(self) -> Metric:
9999
# TODO - dataset?
100100

101101

102+
@attr.s(auto_attribs=True, kw_only=True)
103+
class CatalogAggregatedFact(AttrCatalogEntity):
104+
@staticmethod
105+
def client_class() -> Any:
106+
return JsonApiFactOut
107+
108+
def as_computable(self) -> Metric:
109+
return SimpleMetric(local_id=self.id, item=self.obj_id)
110+
111+
# TODO - dataset?
112+
113+
102114
@attr.s(auto_attribs=True, kw_only=True)
103115
class CatalogDataset(AttrCatalogEntity):
104116
@property

0 commit comments

Comments
 (0)