diff --git a/packages/gooddata-sdk/src/gooddata_sdk/__init__.py b/packages/gooddata-sdk/src/gooddata_sdk/__init__.py index da95627fb..06838056c 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/__init__.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/__init__.py @@ -215,6 +215,7 @@ from gooddata_sdk.catalog.validate_by_item import CatalogValidateByItem from gooddata_sdk.catalog.workspace.aac import ( aac_attribute_hierarchy_to_declarative, + aac_computed_attribute_to_declarative, aac_dashboard_to_declarative, aac_dataset_to_declarative, aac_date_dataset_to_declarative, @@ -222,6 +223,7 @@ aac_plugin_to_declarative, aac_visualization_to_declarative, declarative_attribute_hierarchy_to_aac, + declarative_computed_attribute_to_aac, declarative_dashboard_to_aac, declarative_dataset_to_aac, declarative_date_instance_to_aac, @@ -239,6 +241,8 @@ from gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model import ( CatalogAbsolutePublisherDocumentPeriod, CatalogDeclarativeAnalytics, + CatalogDeclarativeComputedAttribute, + CatalogDeclarativeComputedAttributeContent, CatalogDeclarativeMemoryItem, CatalogDeclarativeMetric, CatalogDeclarativeParameter, @@ -292,6 +296,13 @@ CatalogDeclarativeWorkspaceModel, CatalogDeclarativeWorkspaces, ) + from gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute import ( + CatalogComputedAttribute, + CatalogComputedAttributeAttributes, + CatalogComputedAttributeContent, + CatalogComputedAttributeDocument, + CatalogComputedAttributePostDocument, + ) from gooddata_sdk.catalog.workspace.entity_model.content_objects.custom_application_setting import ( CatalogCustomApplicationSetting, ) @@ -416,6 +427,11 @@ "CatalogBedrockAccessKeyAuth": "gooddata_sdk.catalog.organization.entity_model.llm_provider", "CatalogColorPalette": "gooddata_sdk.catalog.appearance.entity_model.color_palette", "CatalogColorPaletteAttributes": "gooddata_sdk.catalog.appearance.entity_model.color_palette", + "CatalogComputedAttribute": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute", + "CatalogComputedAttributeAttributes": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute", + "CatalogComputedAttributeContent": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute", + "CatalogComputedAttributeDocument": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute", + "CatalogComputedAttributePostDocument": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute", "CatalogContentSlideTemplate": "gooddata_sdk.catalog.organization.common.slide_template", "CatalogCoverSlideTemplate": "gooddata_sdk.catalog.organization.common.slide_template", "CatalogCspDirective": "gooddata_sdk.catalog.organization.entity_model.directive", @@ -446,6 +462,8 @@ "CatalogDeclarativeAttribute": "gooddata_sdk.catalog.workspace.declarative_model.workspace.logical_model.dataset.dataset", "CatalogDeclarativeAutomation": "gooddata_sdk.catalog.workspace.declarative_model.workspace.automation", "CatalogDeclarativeColumn": "gooddata_sdk.catalog.data_source.declarative_model.physical_model.table", + "CatalogDeclarativeComputedAttribute": "gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model", + "CatalogDeclarativeComputedAttributeContent": "gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model", "CatalogDeclarativeDashboardPermissionsForAssignee": "gooddata_sdk.catalog.permission.declarative_model.permission", "CatalogDeclarativeDashboardPermissionsForAssigneeRule": "gooddata_sdk.catalog.permission.declarative_model.permission", "CatalogDeclarativeDataSource": "gooddata_sdk.catalog.data_source.declarative_model.data_source", @@ -649,6 +667,7 @@ "VisualizationMetric": "gooddata_sdk.visualization", "VisualizationService": "gooddata_sdk.visualization", "aac_attribute_hierarchy_to_declarative": "gooddata_sdk.catalog.workspace.aac", + "aac_computed_attribute_to_declarative": "gooddata_sdk.catalog.workspace.aac", "aac_dashboard_to_declarative": "gooddata_sdk.catalog.workspace.aac", "aac_dataset_to_declarative": "gooddata_sdk.catalog.workspace.aac", "aac_date_dataset_to_declarative": "gooddata_sdk.catalog.workspace.aac", @@ -656,6 +675,7 @@ "aac_plugin_to_declarative": "gooddata_sdk.catalog.workspace.aac", "aac_visualization_to_declarative": "gooddata_sdk.catalog.workspace.aac", "declarative_attribute_hierarchy_to_aac": "gooddata_sdk.catalog.workspace.aac", + "declarative_computed_attribute_to_aac": "gooddata_sdk.catalog.workspace.aac", "declarative_dashboard_to_aac": "gooddata_sdk.catalog.workspace.aac", "declarative_dataset_to_aac": "gooddata_sdk.catalog.workspace.aac", "declarative_date_instance_to_aac": "gooddata_sdk.catalog.workspace.aac", @@ -695,6 +715,11 @@ "CatalogBedrockAccessKeyAuth", "CatalogColorPalette", "CatalogColorPaletteAttributes", + "CatalogComputedAttribute", + "CatalogComputedAttributeAttributes", + "CatalogComputedAttributeContent", + "CatalogComputedAttributeDocument", + "CatalogComputedAttributePostDocument", "CatalogContentSlideTemplate", "CatalogCoverSlideTemplate", "CatalogCspDirective", @@ -725,6 +750,8 @@ "CatalogDeclarativeAttribute", "CatalogDeclarativeAutomation", "CatalogDeclarativeColumn", + "CatalogDeclarativeComputedAttribute", + "CatalogDeclarativeComputedAttributeContent", "CatalogDeclarativeDashboardPermissionsForAssignee", "CatalogDeclarativeDashboardPermissionsForAssigneeRule", "CatalogDeclarativeDataSource", @@ -928,6 +955,7 @@ "VisualizationMetric", "VisualizationService", "aac_attribute_hierarchy_to_declarative", + "aac_computed_attribute_to_declarative", "aac_dashboard_to_declarative", "aac_dataset_to_declarative", "aac_date_dataset_to_declarative", @@ -935,6 +963,7 @@ "aac_plugin_to_declarative", "aac_visualization_to_declarative", "declarative_attribute_hierarchy_to_aac", + "declarative_computed_attribute_to_aac", "declarative_dashboard_to_aac", "declarative_dataset_to_aac", "declarative_date_instance_to_aac", diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py index 39cf3b51c..47b44e6e6 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/aac.py @@ -8,6 +8,7 @@ from gooddata_code_convertors import ( ConversionError, declarative_attribute_hierarchy_to_yaml, + declarative_computed_attribute_to_yaml, declarative_dashboard_to_yaml, declarative_dataset_to_yaml, declarative_date_instance_to_yaml, @@ -19,6 +20,7 @@ declarative_publisher_page_template_to_yaml_v2, declarative_visualisation_to_yaml, yaml_attribute_hierarchy_to_declarative, + yaml_computed_attribute_to_declarative, yaml_dashboard_to_declarative, yaml_dataset_to_declarative, yaml_date_dataset_to_declarative, @@ -73,6 +75,7 @@ "plugin", "attribute_hierarchy", "parameter", + "computed_attribute", "document", "document_template", "page_template", @@ -214,6 +217,11 @@ def aac_attribute_hierarchy_to_declarative(aac: dict[str, Any]) -> dict[str, Any return yaml_attribute_hierarchy_to_declarative(aac) +def aac_computed_attribute_to_declarative(aac: dict[str, Any]) -> dict[str, Any]: + """Convert an AAC computed attribute dict to declarative format.""" + return yaml_computed_attribute_to_declarative(aac) + + def aac_document_to_declarative(aac: dict[str, Any]) -> dict[str, Any]: """Convert an AAC document dict to declarative format. @@ -317,6 +325,11 @@ def declarative_attribute_hierarchy_to_aac(declarative: dict[str, Any]) -> dict[ return declarative_attribute_hierarchy_to_yaml(declarative) +def declarative_computed_attribute_to_aac(declarative: dict[str, Any]) -> dict[str, Any]: + """Convert a declarative computed attribute dict to AAC format.""" + return declarative_computed_attribute_to_yaml(declarative) + + def declarative_document_to_aac(declarative: dict[str, Any]) -> dict[str, Any]: """Convert a declarative document dict to AAC format. @@ -373,6 +386,7 @@ def detect_yaml_format(path: Path) -> Literal["aac", "declarative"]: "plugins", "attributeHierarchies", "parameters", + "computedAttributes", "documents", "documentTemplates", "pageTemplates", @@ -451,6 +465,7 @@ def load_aac_workspace_from_disk( dashboard_plugins: list[dict[str, Any]] = [] attribute_hierarchies: list[dict[str, Any]] = [] parameters: list[dict[str, Any]] = [] + computed_attributes: list[dict[str, Any]] = [] documents: list[dict[str, Any]] = [] document_templates: list[dict[str, Any]] = [] page_templates: list[dict[str, Any]] = [] @@ -478,6 +493,8 @@ def load_aac_workspace_from_disk( attribute_hierarchies.append(aac_attribute_hierarchy_to_declarative(aac)) case "parameter": parameters.append(aac_parameter_to_declarative(aac)) + case "computed_attribute": + computed_attributes.append(aac_computed_attribute_to_declarative(aac)) case "document": documents.append(aac_document_to_declarative(aac)) case "document_template": @@ -510,6 +527,8 @@ def load_aac_workspace_from_disk( analytics["attributeHierarchyObjects"] = attribute_hierarchies if parameters: analytics["parameters"] = parameters + if computed_attributes: + analytics["computedAttributes"] = computed_attributes if documents: analytics["documents"] = documents if document_templates: @@ -539,7 +558,7 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_ """Convert a declarative workspace model to AAC YAML files and write to disk. Creates typed subdirectories (datasets/, metrics/, visualisations/, dashboards/, - plugins/, attributeHierarchies/, parameters/, documents/, documentTemplates/, pageTemplates/) + plugins/, attributeHierarchies/, parameters/, computedAttributes/, documents/, documentTemplates/, pageTemplates/) under source_dir. Raises: @@ -591,6 +610,11 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_ result = declarative_parameter_to_aac(parameter) _write_aac_file(source_dir, "parameters", parameter["id"], result["content"]) + # The layout omits computedAttributes when a workspace has none, so the key may be missing. + for computed_attribute in analytics.get("computedAttributes") or []: + result = declarative_computed_attribute_to_aac(computed_attribute) + _write_aac_file(source_dir, "computedAttributes", computed_attribute["id"], result["content"]) + for document_id, result in documents: _write_aac_file(source_dir, "documents", document_id, result["content"]) diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/content_service.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/content_service.py index 047316f73..2b00dab06 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/content_service.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/content_service.py @@ -553,7 +553,12 @@ def _prepare_afm_for_availability(items: list[ValidObjectTypes]) -> afm_models.A return compute_model_to_api_model(attributes=attributes, metrics=metrics, filters=filters) - def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) -> ValidObjects: + def compute_valid_objects( + self, + workspace_id: str, + ctx: ValidObjectsInputType, + types: list[str] | None = None, + ) -> ValidObjects: """ Returns attributes, facts, and metrics which are valid to add to a context that already contains some entities from the semantic model. The entities are typically used to compute analytics and @@ -565,6 +570,9 @@ def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) - Workspace identification string e.g. "demo" ctx (ValidObjectsInputType): items already in context. you can specify context in one of the following ways: + types (Optional[list[str]]): + object types to ask for. Defaults to facts, attributes and measures. + Pass "computedAttributes" as well to include computed attributes. Returns: ValidObjects: @@ -578,7 +586,9 @@ def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) - else: afm = self._prepare_afm_for_availability([ctx]) - query = afm_models.AfmValidObjectsQuery(afm=afm, types=["facts", "attributes", "measures"]) + query = afm_models.AfmValidObjectsQuery( + afm=afm, types=types if types is not None else ["facts", "attributes", "measures"] + ) response = self._actions_api.compute_valid_objects(workspace_id=workspace_id, afm_valid_objects_query=query) by_type: dict[str, set[str]] = dict() diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/analytics_model/analytics_model.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/analytics_model/analytics_model.py index f78e11040..e683cfa03 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/analytics_model/analytics_model.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/declarative_model/workspace/analytics_model/analytics_model.py @@ -15,6 +15,8 @@ from gooddata_api_client.model.declarative_analytics import DeclarativeAnalytics from gooddata_api_client.model.declarative_analytics_layer import DeclarativeAnalyticsLayer from gooddata_api_client.model.declarative_attribute_hierarchy import DeclarativeAttributeHierarchy +from gooddata_api_client.model.declarative_computed_attribute import DeclarativeComputedAttribute +from gooddata_api_client.model.declarative_computed_attribute_content import DeclarativeComputedAttributeContent from gooddata_api_client.model.declarative_dashboard_plugin import DeclarativeDashboardPlugin from gooddata_api_client.model.declarative_filter_context import DeclarativeFilterContext from gooddata_api_client.model.declarative_memory_item import DeclarativeMemoryItem @@ -71,6 +73,7 @@ LAYOUT_VISUALIZATION_OBJECTS_DIR = "visualization_objects" LAYOUT_VISUALIZATION_OBJECT_EXTENSIONS_DIR = "visualization_object_extensions" ATTRIBUTE_HIERARCHY_OBJECTS_DIR = "attribute_hierarchy_objects" +COMPUTED_ATTRIBUTES_DIR = "computed_attributes" EXPORT_DEFINITION_DIR = "export_definitions" MEMORY_ITEMS_DIR = "memory_items" PARAMETERS_DIR = "parameters" @@ -111,6 +114,10 @@ class CatalogDeclarativeAnalyticsLayer(Base): analytical_dashboards: list[CatalogDeclarativeAnalyticalDashboard] = field(factory=list) analytical_dashboard_extensions: list[CatalogDeclarativeAnalyticalDashboardExtension] = field(factory=list) attribute_hierarchies: list[CatalogDeclarativeAttributeHierarchy] = field(factory=list) + # Optional, unlike its siblings: the backend omits `computedAttributes` from the layout + # entirely when a workspace has none (it returns `[]` for attributeHierarchies and the + # rest). Defaulting to an empty list would make the SDK emit a key the API never sent. + computed_attributes: list[CatalogDeclarativeComputedAttribute] | None = None dashboard_plugins: list[CatalogDeclarativeDashboardPlugin] = field(factory=list) filter_contexts: list[CatalogDeclarativeFilterContext] = field(factory=list) metrics: list[CatalogDeclarativeMetric] = field(factory=list) @@ -176,6 +183,12 @@ def get_attribute_hierarchy_folder(analytics_model_folder: Path) -> Path: create_directory(folder) return folder + @staticmethod + def get_computed_attributes_folder(analytics_model_folder: Path) -> Path: + folder = analytics_model_folder / COMPUTED_ATTRIBUTES_DIR + create_directory(folder) + return folder + @staticmethod def get_export_definition_folder(analytics_model_folder: Path) -> Path: folder = analytics_model_folder / EXPORT_DEFINITION_DIR @@ -247,6 +260,7 @@ def store_to_disk(self, workspace_folder: Path, sort: bool = False) -> None: metrics_folder = self.get_metrics_folder(analytics_model_folder) visualization_objects_folder = self.get_visualization_objects_folder(analytics_model_folder) attribute_hierarchy_folder = self.get_attribute_hierarchy_folder(analytics_model_folder) + computed_attributes_folder = self.get_computed_attributes_folder(analytics_model_folder) export_definition_folder = self.get_export_definition_folder(analytical_dashboards_folder) memory_item_folder = self.get_memory_item_folder(analytics_model_folder) parameters_folder = self.get_parameters_folder(analytics_model_folder) @@ -283,6 +297,9 @@ def store_to_disk(self, workspace_folder: Path, sort: bool = False) -> None: for attribute_hierarchy in self.attribute_hierarchies: attribute_hierarchy.store_to_disk(attribute_hierarchy_folder, sort=sort) + for computed_attribute in self.computed_attributes or []: + computed_attribute.store_to_disk(computed_attributes_folder, sort=sort) + for export_definition in self.export_definitions: export_definition.store_to_disk(export_definition_folder, sort=sort) @@ -311,6 +328,7 @@ def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalyticsLa metrics_folder = cls.get_metrics_folder(analytics_model_folder) visualization_objects_folder = cls.get_visualization_objects_folder(analytics_model_folder) attribute_hierarchy_folder = cls.get_attribute_hierarchy_folder(analytics_model_folder) + computed_attributes_folder = cls.get_computed_attributes_folder(analytics_model_folder) export_definition_folder = cls.get_export_definition_folder(analytical_dashboards_folder) memory_item_folder = cls.get_memory_item_folder(analytics_model_folder) parameters_folder = cls.get_parameters_folder(analytics_model_folder) @@ -325,6 +343,7 @@ def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalyticsLa metric_files = get_sorted_yaml_files(metrics_folder) visualization_object_files = get_sorted_yaml_files(visualization_objects_folder) attribute_hierarchy_files = get_sorted_yaml_files(attribute_hierarchy_folder) + computed_attribute_files = get_sorted_yaml_files(computed_attributes_folder) export_definition_files = get_sorted_yaml_files(export_definition_folder) memory_item_files = get_sorted_yaml_files(memory_item_folder) parameter_files = get_sorted_yaml_files(parameters_folder) @@ -364,6 +383,10 @@ def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalyticsLa CatalogDeclarativeAttributeHierarchy.load_from_disk(attribute_hierarchy_file) for attribute_hierarchy_file in attribute_hierarchy_files ] + computed_attributes = [ + CatalogDeclarativeComputedAttribute.load_from_disk(computed_attribute_file) + for computed_attribute_file in computed_attribute_files + ] export_definitions = [ CatalogDeclarativeExportDefinition.load_from_disk(export_definition_file) for export_definition_file in export_definition_files @@ -387,6 +410,7 @@ def load_from_disk(cls, workspace_folder: Path) -> CatalogDeclarativeAnalyticsLa analytical_dashboards=analytical_dashboards, analytical_dashboard_extensions=analytical_dashboard_extensions, attribute_hierarchies=attribute_hierarchy_objects, + computed_attributes=computed_attributes or None, dashboard_plugins=dashboard_plugins, filter_contexts=filter_contexts, metrics=metrics, @@ -532,6 +556,35 @@ def client_class() -> type[DeclarativeAttributeHierarchy]: return DeclarativeAttributeHierarchy +@define(kw_only=True) +class CatalogDeclarativeComputedAttributeContent(Base): + maql: str + format: str | None = None + metric_type: str | None = None + + @staticmethod + def client_class() -> type[DeclarativeComputedAttributeContent]: + return DeclarativeComputedAttributeContent + + +@define(kw_only=True) +class CatalogDeclarativeComputedAttribute(CatalogAnalyticsBaseMeta): + title: str + content: CatalogDeclarativeComputedAttributeContent + description: str | None = None + tags: list[str] | None = None + data_type: str | None = None + locale: str | None = None + value_type: str | None = None + is_hidden: bool | None = None + is_nullable: bool | None = None + null_value: str | None = None + + @staticmethod + def client_class() -> type[DeclarativeComputedAttribute]: + return DeclarativeComputedAttribute + + @define(kw_only=True) class CatalogDeclarativeMemoryItem(CatalogAnalyticsBaseMeta): instruction: str diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/entity_model/content_objects/computed_attribute.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/entity_model/content_objects/computed_attribute.py new file mode 100644 index 000000000..5507e4986 --- /dev/null +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/entity_model/content_objects/computed_attribute.py @@ -0,0 +1,132 @@ +# (C) 2026 GoodData Corporation +from __future__ import annotations + +from attrs import define +from gooddata_api_client.model.json_api_computed_attribute_in import JsonApiComputedAttributeIn +from gooddata_api_client.model.json_api_computed_attribute_in_attributes import JsonApiComputedAttributeInAttributes +from gooddata_api_client.model.json_api_computed_attribute_in_attributes_content import ( + JsonApiComputedAttributeInAttributesContent, +) +from gooddata_api_client.model.json_api_computed_attribute_in_document import JsonApiComputedAttributeInDocument +from gooddata_api_client.model.json_api_computed_attribute_post_optional_id import ( + JsonApiComputedAttributePostOptionalId, +) +from gooddata_api_client.model.json_api_computed_attribute_post_optional_id_document import ( + JsonApiComputedAttributePostOptionalIdDocument, +) + +from gooddata_sdk.catalog.base import Base + + +@define(kw_only=True) +class CatalogComputedAttributeDocument(Base): + data: CatalogComputedAttribute + + @staticmethod + def client_class() -> type[JsonApiComputedAttributeInDocument]: + return JsonApiComputedAttributeInDocument + + def to_api(self) -> JsonApiComputedAttributeInDocument: + return JsonApiComputedAttributeInDocument(data=self.data.to_api()) + + +@define(kw_only=True) +class CatalogComputedAttributePostDocument(Base): + """Request body of the create (POST) endpoint, where the id is optional. + + Unlike filter views, computed attributes have a dedicated POST schema: the backend + generates the id when it is omitted, so the create endpoint takes this document and + only the update (PUT) endpoint takes CatalogComputedAttributeDocument. + """ + + data: CatalogComputedAttribute + + @staticmethod + def client_class() -> type[JsonApiComputedAttributePostOptionalIdDocument]: + return JsonApiComputedAttributePostOptionalIdDocument + + def to_api(self) -> JsonApiComputedAttributePostOptionalIdDocument: + return JsonApiComputedAttributePostOptionalIdDocument(data=self.data.to_post_api()) + + +@define(kw_only=True) +class CatalogComputedAttribute(Base): + # None only when creating a computed attribute whose id the backend generates. + id: str | None = None + attributes: CatalogComputedAttributeAttributes + + @staticmethod + def client_class() -> type[JsonApiComputedAttributeIn]: + return JsonApiComputedAttributeIn + + @classmethod + def init( + cls, + maql: str, + computed_attribute_id: str | None = None, + title: str | None = None, + description: str | None = None, + format: str | None = None, + metric_type: str | None = None, + data_type: str | None = None, + locale: str | None = None, + value_type: str | None = None, + is_hidden: bool | None = None, + is_nullable: bool | None = None, + null_value: str | None = None, + tags: list[str] | None = None, + are_relations_valid: bool | None = None, + ) -> CatalogComputedAttribute: + attributes = CatalogComputedAttributeAttributes( + content=CatalogComputedAttributeContent(maql=maql, format=format, metric_type=metric_type), + title=title, + description=description, + data_type=data_type, + locale=locale, + value_type=value_type, + is_hidden=is_hidden, + is_nullable=is_nullable, + null_value=null_value, + tags=tags, + are_relations_valid=are_relations_valid, + ) + return cls(id=computed_attribute_id, attributes=attributes) + + def to_api(self) -> JsonApiComputedAttributeIn: + if self.id is None: + raise ValueError("Computed attribute id is required for an update, use to_post_api() to create one.") + return JsonApiComputedAttributeIn(id=self.id, attributes=self.attributes.to_api()) + + def to_post_api(self) -> JsonApiComputedAttributePostOptionalId: + optional_id = {} if self.id is None else {"id": self.id} + return JsonApiComputedAttributePostOptionalId(attributes=self.attributes.to_api(), **optional_id) + + +@define(kw_only=True) +class CatalogComputedAttributeAttributes(Base): + content: CatalogComputedAttributeContent + title: str | None = None + description: str | None = None + data_type: str | None = None + locale: str | None = None + value_type: str | None = None + is_hidden: bool | None = None + is_nullable: bool | None = None + null_value: str | None = None + tags: list[str] | None = None + are_relations_valid: bool | None = None + + @staticmethod + def client_class() -> type[JsonApiComputedAttributeInAttributes]: + return JsonApiComputedAttributeInAttributes + + +@define(kw_only=True) +class CatalogComputedAttributeContent(Base): + maql: str + format: str | None = None + metric_type: str | None = None + + @staticmethod + def client_class() -> type[JsonApiComputedAttributeInAttributesContent]: + return JsonApiComputedAttributeInAttributesContent diff --git a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/service.py b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/service.py index eb5fcda9e..2e401c2ef 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/service.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/service.py @@ -30,6 +30,11 @@ CatalogDeclarativeWorkspaces, get_workspace_folder, ) +from gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute import ( + CatalogComputedAttribute, + CatalogComputedAttributeDocument, + CatalogComputedAttributePostDocument, +) from gooddata_sdk.catalog.workspace.entity_model.content_objects.custom_application_setting import ( CatalogCustomApplicationSetting, ) @@ -1600,6 +1605,105 @@ def delete_filter_view(self, workspace_id: str, filter_view_id: str) -> None: """ self._entities_api.delete_entity_filter_views(workspace_id=workspace_id, object_id=filter_view_id) + def list_computed_attributes(self, workspace_id: str) -> list[CatalogComputedAttribute]: + """List all computed attributes. + + Args: + workspace_id (str): + String containing id of the workspace. + + Returns: + list[CatalogComputedAttribute]: + List of computed attribute entities. + """ + get_computed_attributes = functools.partial( + self._entities_api.get_all_entities_computed_attributes, + workspace_id, + _check_return_type=False, + ) + computed_attributes = load_all_entities_dict(get_computed_attributes, camel_case=False) + return [CatalogComputedAttribute.from_dict(ca, camel_case=False) for ca in computed_attributes["data"]] + + def create_or_update_computed_attribute( + self, workspace_id: str, computed_attribute: CatalogComputedAttribute + ) -> UpsertOutcome: + """Create a new computed attribute or overwrite an existing one. + + Args: + workspace_id (str): + String containing id of the workspace. + computed_attribute (CatalogComputedAttribute): + ComputedAttribute entity object. + + Returns: + UpsertOutcome: + CREATED if the computed attribute did not exist yet, UPDATED if it did. + + Note: + A computed attribute with no id always takes the create branch; the backend + generates the id. + """ + + def create() -> UpsertOutcome: + # The create endpoint takes the POST document, whose id is optional. + self._entities_api.create_entity_computed_attributes( + workspace_id=workspace_id, + json_api_computed_attribute_post_optional_id_document=CatalogComputedAttributePostDocument( + data=computed_attribute + ).to_api(), + _check_return_type=False, + ) + return UpsertOutcome.CREATED + + if computed_attribute.id is None: + return create() + try: + self.get_computed_attribute(workspace_id=workspace_id, computed_attribute_id=computed_attribute.id) + except NotFoundException: + return create() + self._entities_api.update_entity_computed_attributes( + workspace_id=workspace_id, + object_id=computed_attribute.id, + json_api_computed_attribute_in_document=CatalogComputedAttributeDocument(data=computed_attribute).to_api(), + _check_return_type=False, + ) + return UpsertOutcome.UPDATED + + def get_computed_attribute(self, workspace_id: str, computed_attribute_id: str) -> CatalogComputedAttribute: + """Get computed attribute by its id. + + Args: + workspace_id (str): + String containing id of the workspace. + computed_attribute_id (str): + String containing id of the computed attribute. + + Returns: + CatalogComputedAttribute: + ComputedAttribute entity object. + """ + computed_attribute_dict = self._entities_api.get_entity_computed_attributes( + workspace_id=workspace_id, + object_id=computed_attribute_id, + _check_return_type=False, + ).data + + return CatalogComputedAttribute.from_dict(computed_attribute_dict, camel_case=True) + + def delete_computed_attribute(self, workspace_id: str, computed_attribute_id: str) -> None: + """Delete computed attribute. + + Args: + workspace_id (str): + String containing id of the workspace. + computed_attribute_id (str): + String containing id of the deleted computed attribute. + + Returns: + None + """ + self._entities_api.delete_entity_computed_attributes(workspace_id=workspace_id, object_id=computed_attribute_id) + def get_declarative_filter_views(self, workspace_id: str) -> list[CatalogDeclarativeFilterView]: """Retrieve a list of declarative filter views. diff --git a/packages/gooddata-sdk/src/gooddata_sdk/compute/model/attribute.py b/packages/gooddata-sdk/src/gooddata_sdk/compute/model/attribute.py index 79503f9c0..216f9063c 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/compute/model/attribute.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/compute/model/attribute.py @@ -14,7 +14,9 @@ def __init__(self, local_id: str, label: Union[ObjId, str], show_all_values: boo Args: local_id: identifier of the attribute within the execution - label: identifier of the label to use for slicing or dicing; specified either as ObjId or str the label id + label: identifier of the label to use for slicing or dicing; specified either as ObjId or str + the label id. An ObjId typed "computedAttribute" slices by that computed attribute + instead; any other ObjId type is treated as a label. show_all_values: request show all values functionality for a given attribute """ super().__init__() diff --git a/packages/gooddata-sdk/src/gooddata_sdk/compute/model/base.py b/packages/gooddata-sdk/src/gooddata_sdk/compute/model/base.py index e6ef23afd..b97c11b5c 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/compute/model/base.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/compute/model/base.py @@ -27,8 +27,13 @@ def as_afm_id(self) -> afm_models.AfmObjectIdentifier: ) def as_afm_id_label(self) -> afm_models.AfmObjectIdentifierLabel: + # A computed attribute occupies the label slot of an AFM attribute, so its type is passed + # through. Every other type is coerced to "label", as it always was: callers pass ObjIds of + # other types here - a visualization ref carries whatever type it was stored with - and + # forwarding those would turn them into ApiValueError. + label_type = self._type if self._type == "computedAttribute" else "label" return afm_models.AfmObjectIdentifierLabel( - identifier=afm_models.AfmObjectIdentifierLabelIdentifier(id=self._id, type="label") + identifier=afm_models.AfmObjectIdentifierLabelIdentifier(id=self._id, type=label_type) ) def as_afm_id_dataset(self) -> afm_models.AfmObjectIdentifierDataset: diff --git a/packages/gooddata-sdk/tests/catalog/expected/declarative_analytics_model_documents.json b/packages/gooddata-sdk/tests/catalog/expected/declarative_analytics_model_documents.json index d98f91872..0b13ee623 100644 --- a/packages/gooddata-sdk/tests/catalog/expected/declarative_analytics_model_documents.json +++ b/packages/gooddata-sdk/tests/catalog/expected/declarative_analytics_model_documents.json @@ -29,7 +29,7 @@ "createdBy": {"id": "admin", "type": "user"}, "createdAt": "2000-01-01 00:00", "modifiedBy": {"id": "admin", "type": "user"}, - "modifiedAt": "2026-11-02 11:00" + "modifiedAt": "2000-01-01 00:00" } ], "documentTemplates": [ @@ -42,7 +42,7 @@ "createdBy": {"id": "demo", "type": "user"}, "createdAt": "2000-01-01 00:00", "modifiedBy": {"id": "demo", "type": "user"}, - "modifiedAt": "2026-11-03 09:30", + "modifiedAt": "2000-01-01 00:00", "content": { "locale": "en-US", "pages": [ @@ -65,7 +65,7 @@ "createdBy": {"id": "demo", "type": "user"}, "createdAt": "2000-01-01 00:00", "modifiedBy": {"id": "demo", "type": "user"}, - "modifiedAt": "2026-11-03 09:30", + "modifiedAt": "2000-01-01 00:00", "content": {"layout": {"type": "text", "id": "t1", "markdown": "Hello"}} } ] diff --git a/packages/gooddata-sdk/tests/catalog/fixtures/workspace_content/demo_documents_store_load_and_put.yaml b/packages/gooddata-sdk/tests/catalog/fixtures/workspace_content/demo_documents_store_load_and_put.yaml index a4dff7cc3..d616a1c79 100644 --- a/packages/gooddata-sdk/tests/catalog/fixtures/workspace_content/demo_documents_store_load_and_put.yaml +++ b/packages/gooddata-sdk/tests/catalog/fixtures/workspace_content/demo_documents_store_load_and_put.yaml @@ -936,7 +936,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -972,7 +972,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -997,7 +997,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1070,7 +1070,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1106,7 +1106,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -1135,7 +1135,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1279,7 +1279,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1315,7 +1315,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -1344,7 +1344,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1474,7 +1474,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1510,7 +1510,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -1539,7 +1539,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1614,7 +1614,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1650,7 +1650,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -1679,7 +1679,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1744,7 +1744,7 @@ interactions: type: user description: Brand review id: tpl_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user @@ -1780,7 +1780,7 @@ interactions: type: user description: Monthly id: doc_1 - modifiedAt: 2026-11-02 11:00 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: admin type: user @@ -1809,7 +1809,7 @@ interactions: type: user description: Cover id: pt_1 - modifiedAt: 2026-11-03 09:30 + modifiedAt: 2000-01-01 00:00 modifiedBy: id: demo type: user diff --git a/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_generated_id.yaml b/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_generated_id.yaml new file mode 100644 index 000000000..d464b6a32 --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_generated_id.yaml @@ -0,0 +1,244 @@ +# (C) 2026 GoodData Corporation +interactions: + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: [] + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: &id001 + - PLACEHOLDER + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: + data: + attributes: + content: + maql: SELECT 1 + title: Generated id + type: computedAttribute + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + Content-Type: + - application/json + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: POST + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes + response: + body: + string: + data: + attributes: + content: + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + title: Generated id + id: 3839ff3d-13e0-412c-bdd2-778ebcdfecaa + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/3839ff3d-13e0-412c-bdd2-778ebcdfecaa + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 201 + message: Created + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: + - attributes: + areRelationsValid: true + content: + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + title: Generated id + id: 3839ff3d-13e0-412c-bdd2-778ebcdfecaa + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/3839ff3d-13e0-412c-bdd2-778ebcdfecaa + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: + - attributes: + areRelationsValid: true + content: + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + title: Generated id + id: 3839ff3d-13e0-412c-bdd2-778ebcdfecaa + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/3839ff3d-13e0-412c-bdd2-778ebcdfecaa + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: DELETE + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/3839ff3d-13e0-412c-bdd2-778ebcdfecaa + response: + body: + string: '' + headers: + Content-Type: + - application/vnd.gooddata.api+json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 204 + message: No Content +version: 1 diff --git a/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_life_cycle.yaml b/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_life_cycle.yaml new file mode 100644 index 000000000..fdc1acd26 --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/fixtures/workspaces/computed_attribute_life_cycle.yaml @@ -0,0 +1,2666 @@ +# (C) 2026 GoodData Corporation +interactions: + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: [] + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: &id001 + - PLACEHOLDER + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: + detail: The requested endpoint does not exist or you do not have permission + to access it. + status: 404 + title: Not Found + traceId: NORMALIZED_TRACE_ID_000000000000 + type: about:blank + headers: + Content-Type: + - application/problem+json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 404 + message: Not Found + - request: + body: + data: + attributes: + content: + format: '#,##0' + maql: SELECT 1 + tags: + - Test + title: Test computed attribute + id: test_computed_attribute + type: computedAttribute + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + Content-Type: + - application/json + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: POST + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes + response: + body: + string: + data: + attributes: + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + tags: + - Test + title: Test computed attribute + id: test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 201 + message: Created + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: + data: + attributes: + areRelationsValid: true + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + tags: + - Test + title: Test computed attribute + id: test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: + - attributes: + areRelationsValid: true + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + tags: + - Test + title: Test computed attribute + id: test_computed_attribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/layout/workspaces/demo/analyticsModel + response: + body: + string: + analytics: + analyticalDashboardExtensions: [] + analyticalDashboards: + - content: + attributeFilterConfigs: + - localIdentifier: product_name_0_attributeFilter + selectionType: listOrText + filterContextRef: + identifier: + id: 0c11c35c-7cf6-4787-936f-9a2a4ccc779a + type: filterContext + layout: + sections: + - items: + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: 9944eeb3-db41-46a3-9eec-d26aec590a0a + properties: {} + title: Top 10 Customers + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: 1af17019-fd35-41fd-9692-5ef755493c5f + properties: {} + title: Revenue by Category Trend + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + parameters: [] + tabs: + - attributeFilterConfigs: + - localIdentifier: product_name_0_attributeFilter + selectionType: listOrText + filterContextRef: + identifier: + id: 0c11c35c-7cf6-4787-936f-9a2a4ccc779a + type: filterContext + layout: + sections: + - items: + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: 9944eeb3-db41-46a3-9eec-d26aec590a0a + properties: {} + title: Top 10 Customers + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: 1af17019-fd35-41fd-9692-5ef755493c5f + properties: {} + title: Revenue by Category Trend + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + localIdentifier: 9aecd33c-b70d-4c49-b0da-a886ab5655e3 + parameters: [] + title: First tab + - attributeFilterConfigs: + - localIdentifier: product_name_1_attributeFilter + selectionType: listOrText + filterContextRef: + identifier: + id: 2119ec88-d69a-4d8f-8b08-10c99e074591 + type: filterContext + layout: + sections: + - header: {} + items: + - size: + xl: + gridHeight: 22 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: d1817e82-4daf-4674-846e-56a2e1536514 + title: Top 10 Customers + type: insight + - size: + xl: + gridHeight: 22 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: c8e0d583-3792-45d9-bd0e-d1ae891b72d2 + title: Revenue by Category Trend + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + localIdentifier: 05d3c478-c97a-4d81-9f36-3577b29e5f94 + parameters: [] + title: Second tab + version: '2' + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: Dashboard for summary tests + id: 31f7435f-dd98-4716-9f0f-fb4c887ddxyz + title: Dashboard Summary Multiple Tabs + - content: + attributeFilterConfigs: + - localIdentifier: product_name_0_attributeFilter + selectionType: listOrText + filterContextRef: + identifier: + id: 1db59088-c524-49b6-ab83-1099ae96caab + type: filterContext + layout: + sections: + - header: {} + items: + - size: + xl: + gridHeight: 19 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: 6e9159c0-6f09-448c-a724-0b8403805d4d + title: Top 10 Customers + type: insight + - size: + xl: + gridHeight: 19 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: 67ce777d-2ddd-404a-a4c4-2f3b1d952555 + title: Revenue by Category Trend + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + parameters: [] + tabs: + - attributeFilterConfigs: + - localIdentifier: product_name_0_attributeFilter + selectionType: listOrText + filterContextRef: + identifier: + id: 1db59088-c524-49b6-ab83-1099ae96caab + type: filterContext + layout: + sections: + - header: {} + items: + - size: + xl: + gridHeight: 19 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: ea74b756-bb43-4e34-9a71-6792412fe1d3 + title: Top 10 Customers + type: insight + - size: + xl: + gridHeight: 19 + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: 933ad632-3049-475b-931c-f9bb4ddf179f + title: Revenue by Category Trend + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + localIdentifier: 0be44463-1a33-4d76-bda2-4f96aa9bd342 + parameters: [] + title: '' + version: '2' + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + id: 55987dcf-35bf-40aa-b06b-5639caedb771 + title: Dashboard Summary Single Tab + - content: + filterContextRef: + identifier: + id: 4717b786-2c2e-4596-adb5-4f8b0ab0e19a + type: filterContext + layout: + sections: + - header: + description: All in one description + title: All in one title + items: + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: top_10_customers + type: visualizationObject + localIdentifier: 2c7400ac-5f63-46f8-aa12-a2debe13fd14 + properties: {} + title: Top 10 Customers + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_product + type: visualizationObject + localIdentifier: a50daab7-fb78-45eb-a2b4-d5cc8cbd89e9 + properties: {} + title: Revenue by Product + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: revenue_by_category_trend + type: visualizationObject + localIdentifier: efccc783-5896-4eb6-890f-2e51ece3f159 + properties: {} + title: Revenue by Category Trend + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: product_saleability + type: visualizationObject + localIdentifier: d738d85f-e935-4e2c-b8b4-a8b456f55079 + properties: {} + title: Product Saleability + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: product_categories_pie_chart + type: visualizationObject + localIdentifier: 8c194c85-bad6-42da-b4e3-08d270278316 + properties: {} + title: Product Categories Pie Chart + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: percentage_of_customers_by_region + type: visualizationObject + localIdentifier: 2c3307b2-581f-4bab-9252-6b5279565b24 + properties: {} + title: Percentage of Customers by Region + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: customers_trend + type: visualizationObject + localIdentifier: 87505bb0-d954-4add-811d-f4e75e431660 + properties: {} + title: Customers Trend + type: insight + - size: + xl: + gridWidth: 6 + type: IDashboardLayoutItem + widget: + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: campaign_spend + type: visualizationObject + localIdentifier: 0cb01f6a-6ea6-4c22-bb12-ded00a9eac66 + properties: {} + title: Campaign Spend + type: insight + - size: + xl: + gridWidth: 12 + type: IDashboardLayoutItem + widget: + dateDataSet: + identifier: + id: date + type: dataset + description: '' + drills: [] + ignoreDashboardFilters: [] + insight: + identifier: + id: percent_revenue_per_product_by_customer_and_category + type: visualizationObject + localIdentifier: 2213d6e4-6df7-458e-806d-f02bae5ce66a + properties: {} + title: '% Revenue per Product by Customer and Category' + type: insight + type: IDashboardLayoutSection + type: IDashboardLayout + version: '2' + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: b2f2d436-9831-4fe0-81df-8c59fd33242b + title: All visualizations 1 with custom filter + attributeHierarchies: [] + computedAttributes: + - content: + format: '#,##0' + maql: SELECT 1 + metricType: UNSPECIFIED + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + id: test_computed_attribute + tags: + - Test + title: Test computed attribute + dashboardPlugins: [] + exportDefinitions: [] + filterContexts: + - content: + filters: + - attributeFilter: + attributeElements: + uris: + - Biolid + - ChalkTalk + - Compglass + - Elentrix + displayForm: + identifier: + id: product_name + type: label + localIdentifier: product_name_0_attributeFilter + negativeSelection: false + version: '2' + description: '' + id: 0c11c35c-7cf6-4787-936f-9a2a4ccc779a + title: filterContext + - content: + filters: + - attributeFilter: + attributeElements: + uris: + - Biolid + - ChalkTalk + - Compglass + - Elentrix + displayForm: + identifier: + id: product_name + type: label + localIdentifier: product_name_0_attributeFilter + negativeSelection: false + version: '2' + id: 1db59088-c524-49b6-ab83-1099ae96caab + title: filterContext + - content: + filters: + - dateFilter: + from: 2024-01-01 00:00 + granularity: GDC.time.date + localIdentifier: 0_dateFilter + to: 2026-12-31 23:59 + type: absolute + - attributeFilter: + attributeElements: + uris: + - Applica + - Artego + - Biolid + - ChalkTalk + displayForm: + identifier: + id: product_name + type: label + localIdentifier: product_name_1_attributeFilter + negativeSelection: false + version: '2' + description: '' + id: 2119ec88-d69a-4d8f-8b08-10c99e074591 + title: filterContext + - content: + filters: + - attributeFilter: + attributeElements: + uris: + - Biolid + - ChalkTalk + - Compglass + - Elentrix + displayForm: + identifier: + id: product_name + type: label + filterElementsBy: [] + localIdentifier: 6b94bbb585d44c79967867719e524fae + negativeSelection: false + selectionMode: multi + version: '2' + description: '' + id: 4717b786-2c2e-4596-adb5-4f8b0ab0e19a + title: filterContext + - content: + filters: + - dateFilter: + from: '0' + granularity: GDC.time.year + localIdentifier: 0_dateFilter + to: '0' + type: relative + version: '2' + description: '' + id: 9f2b1f37-befa-450e-a6cc-dc576845c412 + title: filterContext + memoryItems: [] + metrics: + - content: + format: '#,##0' + maql: SELECT COUNT({attribute/customer_id},{attribute/order_line_id}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: amount_of_active_customers + title: '# of Active Customers' + - content: + format: '#,##0' + maql: SELECT COUNT({attribute/order_id}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: amount_of_orders + title: '# of Orders' + - content: + format: '#,##0' + maql: 'SELECT {metric/amount_of_active_customers} WHERE (SELECT + {metric/revenue} BY {attribute/customer_id}) > 10000 ' + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: amount_of_top_customers + title: '# of Top Customers' + - content: + format: '#,##0.00' + maql: SELECT {metric/amount_of_orders} WHERE NOT ({label/order_status} + IN ("null", "Returned", "Canceled")) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: amount_of_valid_orders + title: '# of Valid Orders' + - content: + format: $#,##0 + maql: SELECT SUM({fact/spend}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: campaign_spend + title: Campaign Spend + - content: + format: $#,##0 + maql: SELECT SUM({fact/price}*{fact/quantity}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: order_amount + title: Order Amount + - content: + format: '#,##0.0%' + maql: SELECT {metric/revenue} / {metric/total_revenue} + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue + title: '% Revenue' + - content: + format: '#,##0.0%' + maql: "SELECT\n (SELECT {metric/revenue} WHERE (SELECT {metric/revenue_top_10}\ + \ BY {attribute/customer_id}) > 0)\n /\n {metric/revenue}" + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_from_top_10_customers + title: '% Revenue from Top 10 Customers' + - content: + format: '#,##0.0%' + maql: "SELECT\n (SELECT {metric/revenue} WHERE (SELECT {metric/revenue_top_10_percent}\ + \ BY {attribute/customer_id}) > 0)\n /\n {metric/revenue}" + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_from_top_10_percent_customers + title: '% Revenue from Top 10% Customers' + - content: + format: '#,##0.0%' + maql: "SELECT\n (SELECT {metric/revenue} WHERE (SELECT {metric/revenue_top_10_percent}\ + \ BY {attribute/product_id}) > 0)\n /\n {metric/revenue}" + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_from_top_10_percent_products + title: '% Revenue from Top 10% Products' + - content: + format: '#,##0.0%' + maql: "SELECT\n (SELECT {metric/revenue} WHERE (SELECT {metric/revenue_top_10}\ + \ BY {attribute/product_id}) > 0)\n /\n {metric/revenue}" + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_from_top_10_products + title: '% Revenue from Top 10 Products' + - content: + format: '#,##0.0%' + maql: SELECT {metric/revenue} / (SELECT {metric/revenue} BY {attribute/products.category}, + ALL OTHER) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_in_category + title: '% Revenue in Category' + - content: + format: '#,##0.0%' + maql: SELECT {metric/revenue} / (SELECT {metric/revenue} BY ALL + {attribute/product_id}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_per_product + title: '% Revenue per Product' + - content: + format: $#,##0 + maql: SELECT {metric/order_amount} WHERE NOT ({label/order_status} + IN ("null", "Returned", "Canceled")) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue + tags: + - summary + title: Revenue + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE {label/products.category} IN + ("Clothing") + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue-clothing + title: Revenue (Clothing) + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE {label/products.category} IN + ( "Electronics") + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue-electronic + title: Revenue (Electronic) + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE {label/products.category} IN + ("Home") + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue-home + title: Revenue (Home) + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE {label/products.category} IN + ("Outdoor") + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue-outdoor + title: Revenue (Outdoor) + - content: + format: $#,##0.0 + maql: SELECT AVG(SELECT {metric/revenue} BY {attribute/customer_id}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_per_customer + title: Revenue per Customer + - content: + format: $#,##0.0 + maql: SELECT {metric/revenue} / {metric/campaign_spend} + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_per_dollar_spent + title: Revenue per Dollar Spent + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE TOP(10) OF ({metric/revenue}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_top_10 + title: Revenue / Top 10 + - content: + format: $#,##0 + maql: SELECT {metric/revenue} WHERE TOP(10%) OF ({metric/revenue}) + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_top_10_percent + title: Revenue / Top 10% + - content: + format: $#,##0 + maql: SELECT {metric/revenue} BY ALL OTHER + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: total_revenue + title: Total Revenue + - content: + format: $#,##0 + maql: SELECT {metric/total_revenue} WITHOUT PARENT FILTER + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: total_revenue-no_filters + title: Total Revenue (No Filters) + parameters: [] + visualizationObjects: + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: campaign_spend + type: metric + localIdentifier: d319bcb2d8c04442a684e3b3cd063381 + title: Campaign Spend + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: campaign_channels.category + type: label + localIdentifier: 291c085e7df8420db84117ca49f59c49 + localIdentifier: view + - items: + - attribute: + displayForm: + identifier: + id: campaign_name + type: label + localIdentifier: d9dd143d647d4d148405a60ec2cf59bc + localIdentifier: segment + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: type + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: campaign_channels.category + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: campaign_name + type: label + notIn: + values: [] + properties: + controls: + legend: + position: bottom + version: '2' + visualizationUrl: local:treemap + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: campaign_spend + title: Campaign Spend + - content: + buckets: + - items: + - measure: + alias: Active Customers + definition: + measureDefinition: + computeRatio: false + filters: [] + item: + identifier: + id: amount_of_active_customers + type: metric + localIdentifier: 2ba0b87b59ca41a4b1530e81a5c1d081 + title: '# of Active Customers' + localIdentifier: measures + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue_per_customer + type: metric + localIdentifier: ec0606894b9f4897b7beaf1550608928 + title: Revenue per Customer + localIdentifier: secondary_measures + - items: + - attribute: + displayForm: + identifier: + id: date.month + type: label + localIdentifier: 0de7d7f08af7480aa636857a26be72b6 + localIdentifier: view + filters: + - relativeDateFilter: + dataSet: + identifier: + id: date + type: dataset + from: -11 + granularity: GDC.time.month + to: 0 + properties: + controls: + colorMapping: + - color: + type: guid + value: '20' + id: 2ba0b87b59ca41a4b1530e81a5c1d081 + - color: + type: guid + value: '4' + id: ec0606894b9f4897b7beaf1550608928 + dualAxis: true + legend: + position: bottom + primaryChartType: column + secondaryChartType: line + secondary_yaxis: + measures: + - ec0606894b9f4897b7beaf1550608928 + xaxis: + name: + visible: false + rotation: auto + version: '2' + visualizationUrl: local:combo2 + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: customers_trend + title: Customers Trend + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: price + type: fact + format: '#,##0.00' + localIdentifier: 2b52c396036d438baef515cfff4c22e1 + title: Sum of Price + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: quantity + type: fact + format: '#,##0.00' + localIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + title: Sum of Quantity + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: customer_name + type: label + localIdentifier: bdb23474601943b389f21fd912c1b440 + localIdentifier: attribute + totals: + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: max + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 2b52c396036d438baef515cfff4c22e1 + type: med + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: med + filters: + - rankingFilter: + measure: + localIdentifier: 2b52c396036d438baef515cfff4c22e1 + operator: TOP + value: 3 + properties: + controls: + columnWidths: + - attributeColumnWidthItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + width: + value: 159 + measureGroupDimension: rows + sorts: + - attributeSortItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + direction: asc + version: '2' + visualizationUrl: local:table + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: Grand Total And Transposition + id: grand_total_and_transposition + title: Grand Total And Transposition + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: price + type: fact + format: '#,##0.00' + localIdentifier: 2b52c396036d438baef515cfff4c22e1 + title: Sum of Price + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: quantity + type: fact + format: '#,##0.00' + localIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + title: Sum of Quantity + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: customer_name + type: label + localIdentifier: bdb23474601943b389f21fd912c1b440 + localIdentifier: attribute + totals: + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 2b52c396036d438baef515cfff4c22e1 + type: nat + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: nat + - items: + - attribute: + displayForm: + identifier: + id: region + type: label + localIdentifier: 1d4722be2a3b40d2b44618830e429628 + localIdentifier: columns + totals: + - attributeIdentifier: 1d4722be2a3b40d2b44618830e429628 + measureIdentifier: 2b52c396036d438baef515cfff4c22e1 + type: nat + - attributeIdentifier: 1d4722be2a3b40d2b44618830e429628 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: nat + filters: + - positiveAttributeFilter: + displayForm: + identifier: + id: customer_name + type: label + in: + values: + - Abbe Mation + - Abbie Dishmon + - Abigael Emmer + localIdentifier: 3d4211d9b64d4a8f886294c58ffa3bf2 + properties: + controls: + columnWidths: + - attributeColumnWidthItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + width: + value: 159 + measureGroupDimension: rows + sorts: + - attributeSortItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + direction: asc + version: '2' + visualizationUrl: local:table + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: Insight Filters Overwrite + id: insight_filters_overwrite + title: Insight Filters Overwrite + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: percent_revenue_per_product + type: metric + localIdentifier: 08d8346c1ce7438994b251991c0fbf65 + title: '% Revenue per Product' + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: b2350c06688b4da9b3833ebcce65527f + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: customer_name + type: label + localIdentifier: 7a4045fd00ac44579f52406df679435f + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: 6a003ffd14994237ba64c4a02c488429 + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: 75ea396d0c8b48098e31dccf8b5801d3 + localIdentifier: attribute + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: customer_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + properties: + sortItems: + - attributeSortItem: + attributeIdentifier: 7a4045fd00ac44579f52406df679435f + direction: asc + version: '2' + visualizationUrl: local:table + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percent_revenue_per_product_by_customer_and_category + title: '% Revenue per Product by Customer and Category' + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: amount_of_active_customers + type: metric + localIdentifier: 1a14cdc1293c46e89a2e25d3e741d235 + title: '# of Active Customers' + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: date.month + type: label + localIdentifier: c1feca1864244ec2ace7a9b9d7fda231 + localIdentifier: view + - items: + - attribute: + displayForm: + identifier: + id: region + type: label + localIdentifier: 530cddbd7ca04d039e73462d81ed44d5 + localIdentifier: stack + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: region + type: label + notIn: + values: [] + - relativeDateFilter: + dataSet: + identifier: + id: date + type: dataset + from: -11 + granularity: GDC.time.month + to: 0 + properties: + controls: + legend: + position: bottom + stackMeasuresToPercent: true + version: '2' + visualizationUrl: local:area + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: percentage_of_customers_by_region + title: Percentage of Customers by Region + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 590d332ef686468b8878ae41b23341c6 + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: b166c71091864312a14c7ae8ff886ffe + localIdentifier: view + - items: + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: e920a50e0bbb49788df0aac53634c1cd + localIdentifier: segment + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + properties: + controls: + legend: + position: bottom + version: '2' + visualizationUrl: local:treemap + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: product_breakdown + title: Product Breakdown + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + computeRatio: true + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 162b857af49d45769bc12604a5c192b9 + title: '% Revenue' + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: fe513cef1c6244a5ac21c5f49c56b108 + localIdentifier: view + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + properties: + controls: + dataLabels: + visible: auto + legend: + position: bottom + version: '2' + visualizationUrl: local:donut + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: product_categories_pie_chart + title: Product Categories Pie Chart + - content: + buckets: + - items: + - measure: + alias: Previous Period + definition: + popMeasureDefinition: + measureIdentifier: c82e025fa2db4afea9a600a424591dbe + popAttribute: + identifier: + id: date.year + type: label + localIdentifier: c82e025fa2db4afea9a600a424591dbe_pop + - measure: + alias: This Period + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: c82e025fa2db4afea9a600a424591dbe + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: c804ef5ba7944a5a9f360c86a9e95e9a + localIdentifier: view + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + - relativeDateFilter: + dataSet: + identifier: + id: date + type: dataset + from: -11 + granularity: GDC.time.month + to: 0 + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + properties: + controls: + legend: + position: bottom + stackMeasures: false + xaxis: + name: + visible: false + yaxis: + name: + visible: false + version: '2' + visualizationUrl: local:column + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: product_revenue_comparison-over_previous_period + title: Product Revenue Comparison (over previous period) + - content: + buckets: + - items: + - measure: + alias: Number of Orders + definition: + measureDefinition: + filters: [] + item: + identifier: + id: amount_of_orders + type: metric + localIdentifier: aeb5d51a162d4b59aba3bd6ddebcc780 + title: '# of Orders' + localIdentifier: measures + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 94b3edd3a73c4a48a4d13bbe9442cc98 + title: Revenue + localIdentifier: secondary_measures + - items: + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: d2a991bdd123448eb2be73d79f1180c4 + localIdentifier: attribute + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + properties: + controls: + dataLabels: + visible: auto + grid: + enabled: true + version: '2' + visualizationUrl: local:scatter + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: product_saleability + title: Product Saleability + - content: + buckets: + - items: + - measure: + alias: Items Sold + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: quantity + type: fact + format: '#,##0.00' + localIdentifier: 29486504dd0e4a36a18b0b2f792d3a46 + title: Sum of Quantity + - measure: + definition: + measureDefinition: + aggregation: avg + filters: [] + item: + identifier: + id: price + type: fact + format: '#,##0.00' + localIdentifier: aa6391acccf1452f8011201aef9af492 + title: Avg Price + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: percent_revenue_in_category + type: metric + localIdentifier: 2cd39539d8da46c9883e63caa3ba7cc0 + title: '% Revenue in Category' + - measure: + alias: Total Revenue + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 9a0f08331c094c7facf2a0b4f418de0a + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: 06bc6b3b9949466494e4f594c11f1bff + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: 192668bfb6a74e9ab7b5d1ce7cb68ea3 + localIdentifier: attribute + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: customer_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + properties: + sortItems: + - attributeSortItem: + attributeIdentifier: 06bc6b3b9949466494e4f594c11f1bff + direction: asc + version: '2' + visualizationUrl: local:table + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_and_quantity_by_product_and_category + title: Revenue and Quantity by Product and Category + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 7df6c34387744d69b23ec92e1a5cf543 + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: date.month + type: label + localIdentifier: 4bb4fc1986c546de9ad976e6ec23fed4 + localIdentifier: trend + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: 34bddcb1cd024902a82396216b0fa9d8 + localIdentifier: segment + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + - relativeDateFilter: + dataSet: + identifier: + id: date + type: dataset + granularity: GDC.time.year + properties: + controls: + legend: + position: bottom + version: '2' + visualizationUrl: local:line + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_by_category_trend + title: Revenue by Category Trend + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 4ae3401bdbba4938afe983df4ba04e1c + title: Revenue + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: 1c8ba72dbfc84ddd913bf81dc355c427 + localIdentifier: view + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + properties: {} + version: '2' + visualizationUrl: local:bar + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_by_product + title: Revenue by Product + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: campaign_spend + type: metric + localIdentifier: 13a50d811e474ac6808d8da7f4673b35 + title: Campaign Spend + localIdentifier: measures + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue_per_dollar_spent + type: metric + localIdentifier: a0f15e82e6334280a44dbedc7d086e7c + title: Revenue per Dollar Spent + localIdentifier: secondary_measures + - items: + - attribute: + displayForm: + identifier: + id: campaign_name + type: label + localIdentifier: 1d9fa968bafb423eb29c938dfb1207ff + localIdentifier: attribute + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: campaign_name + type: label + notIn: + values: [] + properties: + controls: + xaxis: + min: '0' + yaxis: + min: '0' + version: '2' + visualizationUrl: local:scatter + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_per_usd_vs_spend_by_campaign + title: Revenue per $ vs Spend by Campaign + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + computeRatio: false + filters: [] + item: + identifier: + id: revenue + type: metric + localIdentifier: 60c854969a9c4c278ab596d99c222e92 + title: Revenue + localIdentifier: measures + - items: + - measure: + alias: Number of Orders + definition: + measureDefinition: + computeRatio: false + filters: [] + item: + identifier: + id: amount_of_orders + type: metric + localIdentifier: c2fa7ef48cc54af99f8c280eb451e051 + title: '# of Orders' + localIdentifier: secondary_measures + - items: + - attribute: + displayForm: + identifier: + id: date.month + type: label + localIdentifier: 413ac374b65648fa96826ca01d47bdda + localIdentifier: view + filters: + - relativeDateFilter: + dataSet: + identifier: + id: date + type: dataset + from: -3 + granularity: GDC.time.quarter + to: 0 + properties: + controls: + dualAxis: true + legend: + position: bottom + primaryChartType: column + secondaryChartType: line + secondary_yaxis: + measures: + - c2fa7ef48cc54af99f8c280eb451e051 + xaxis: + name: + visible: false + rotation: auto + version: '2' + visualizationUrl: local:combo2 + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: revenue_trend + title: Revenue Trend + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: price + type: fact + format: '#,##0.00' + localIdentifier: 2b52c396036d438baef515cfff4c22e1 + title: Sum of Price + - measure: + definition: + measureDefinition: + aggregation: sum + filters: [] + item: + identifier: + id: quantity + type: fact + format: '#,##0.00' + localIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + title: Sum of Quantity + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: customer_name + type: label + localIdentifier: bdb23474601943b389f21fd912c1b440 + localIdentifier: attribute + totals: + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 2b52c396036d438baef515cfff4c22e1 + type: nat + - attributeIdentifier: bdb23474601943b389f21fd912c1b440 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: nat + - items: + - attribute: + displayForm: + identifier: + id: region + type: label + localIdentifier: 1d4722be2a3b40d2b44618830e429628 + localIdentifier: columns + totals: + - attributeIdentifier: 1d4722be2a3b40d2b44618830e429628 + measureIdentifier: 2b52c396036d438baef515cfff4c22e1 + type: nat + - attributeIdentifier: 1d4722be2a3b40d2b44618830e429628 + measureIdentifier: 5f788cd3e5084c7cb3946fa6e6cbdb43 + type: nat + filters: + - positiveAttributeFilter: + displayForm: + identifier: + id: customer_name + type: label + in: + values: + - Abbe Mation + - Abbie Dishmon + - Abigael Emmer + localIdentifier: 3d4211d9b64d4a8f886294c58ffa3bf2 + properties: + controls: + columnWidths: + - attributeColumnWidthItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + width: + value: 159 + measureGroupDimension: rows + sorts: + - attributeSortItem: + attributeIdentifier: bdb23474601943b389f21fd912c1b440 + direction: asc + version: '2' + visualizationUrl: local:table + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: Rollup Total At Row And Column + id: rollup_total_at_row_and_column + title: Rollup Total At Row And Column + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue_top_10 + type: metric + localIdentifier: 3f127ccfe57a40399e23f9ae2a4ad810 + title: Revenue / Top 10 + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: customer_name + type: label + localIdentifier: f4e39e24f11e4827a191c30d65c89d2c + localIdentifier: view + - items: + - attribute: + displayForm: + identifier: + id: state + type: label + localIdentifier: bbccd430176d428caed54c99afc9589e + localIdentifier: stack + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: customer_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: state + type: label + notIn: + values: [] + properties: + controls: + legend: + position: bottom + version: '2' + visualizationUrl: local:bar + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: top_10_customers + title: Top 10 Customers + - content: + buckets: + - items: + - measure: + definition: + measureDefinition: + filters: [] + item: + identifier: + id: revenue_top_10 + type: metric + localIdentifier: 77dc71bbac92412bac5f94284a5919df + title: Revenue / Top 10 + localIdentifier: measures + - items: + - attribute: + displayForm: + identifier: + id: product_name + type: label + localIdentifier: 781952e728204dcf923142910cc22ae2 + localIdentifier: view + - items: + - attribute: + displayForm: + identifier: + id: products.category + type: label + localIdentifier: fe513cef1c6244a5ac21c5f49c56b108 + localIdentifier: stack + filters: + - negativeAttributeFilter: + displayForm: + identifier: + id: product_name + type: label + notIn: + values: [] + - negativeAttributeFilter: + displayForm: + identifier: + id: products.category + type: label + notIn: + values: [] + properties: + controls: + legend: + position: bottom + version: '2' + visualizationUrl: local:bar + createdAt: 2000-01-01 00:00 + createdBy: + id: admin + type: user + description: '' + id: top_10_products + title: Top 10 Products + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: + data: + attributes: + areRelationsValid: true + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + tags: + - Test + title: Test computed attribute + id: test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: + data: + attributes: + content: + format: '#,##0' + maql: SELECT 1 + tags: + - Test + title: Renamed + id: test_computed_attribute + type: computedAttribute + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + Content-Type: + - application/json + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: PUT + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: + data: + attributes: + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + modifiedAt: 2000-01-01 00:00 + tags: + - Test + title: Renamed + id: test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: + data: + attributes: + areRelationsValid: true + content: + format: '#,##0' + maql: SELECT 1 + createdAt: 2000-01-01 00:00 + modifiedAt: 2000-01-01 00:00 + tags: + - Test + title: Renamed + id: test_computed_attribute + meta: + origin: + originId: demo + originType: NATIVE + type: computedAttribute + links: + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: DELETE + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: '' + headers: + Content-Type: + - application/vnd.gooddata.api+json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 204 + message: No Content + - request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: GET + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + response: + body: + string: + data: [] + links: + next: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=1&size=500 + self: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes?page=0&size=500 + headers: + Content-Type: + - application/json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 200 + message: OK + - request: + body: null + headers: + Accept-Encoding: + - br, gzip, deflate + X-GDC-VALIDATE-RELATIONS: + - 'true' + X-Requested-With: + - XMLHttpRequest + method: DELETE + uri: http://localhost:3000/api/v1/entities/workspaces/demo/computedAttributes/test_computed_attribute + response: + body: + string: '' + headers: + Content-Type: + - application/vnd.gooddata.api+json + DATE: *id001 + Expires: + - '0' + Featurepolicy: + - geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr + 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope + 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none'; + Pragma: + - no-cache + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-GDC-TRACE-ID: *id001 + status: + code: 204 + message: No Content +version: 1 diff --git a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py index 8c62129f1..2665948b3 100644 --- a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py +++ b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace.py @@ -11,6 +11,7 @@ from gooddata_sdk import ( BasicCredentials, CatalogAutomationSchedule, + CatalogComputedAttribute, CatalogCustomApplicationSetting, CatalogDataSourcePostgres, CatalogDeclarativeAutomation, @@ -976,6 +977,102 @@ def test_delete_custom_application_setting(test_config): safe_delete(sdk.catalog_workspace.delete_custom_application_setting, test_config["workspace"], setting_id) +def _computed_attribute(title: str = "Test computed attribute") -> CatalogComputedAttribute: + return CatalogComputedAttribute.init( + computed_attribute_id="test_computed_attribute", + maql="SELECT 1", + title=title, + format="#,##0", + tags=["Test"], + ) + + +@gd_vcr.use_cassette(str(_fixtures_dir / "computed_attribute_life_cycle.yaml")) +def test_computed_attribute_life_cycle(test_config): + sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"]) + workspace_id = test_config["workspace"] + computed_attribute_id = "test_computed_attribute" + + # Anything the workspace already has is none of this test's business - it must not + # assume an empty workspace, nor clean up computed attributes it did not create. + existing_ids = {ca.id for ca in sdk.catalog_workspace.list_computed_attributes(workspace_id)} + assert computed_attribute_id not in existing_ids + + try: + outcome = sdk.catalog_workspace.create_or_update_computed_attribute(workspace_id, _computed_attribute()) + assert outcome == UpsertOutcome.CREATED + + computed_attribute_o = sdk.catalog_workspace.get_computed_attribute(workspace_id, computed_attribute_id) + assert computed_attribute_o.id == computed_attribute_id + assert computed_attribute_o.attributes.title == "Test computed attribute" + assert computed_attribute_o.attributes.content.maql == "SELECT 1" + assert computed_attribute_o.attributes.content.format == "#,##0" + assert computed_attribute_o.attributes.tags == ["Test"] + + listed_ids = {ca.id for ca in sdk.catalog_workspace.list_computed_attributes(workspace_id)} + assert listed_ids - existing_ids == {computed_attribute_id} + + # The same computed attribute must also show up in the declarative layout - + # analytics-as-code parity is the point of CA support (CQ-2799 / CQ-2800). + layout = sdk.catalog_workspace_content.get_declarative_analytics_model(workspace_id) + declarative = [ca for ca in layout.analytics.computed_attributes if ca.id == computed_attribute_id] + assert len(declarative) == 1 + assert declarative[0].title == "Test computed attribute" + assert declarative[0].content.maql == "SELECT 1" + assert declarative[0].content.format == "#,##0" + + # The update goes through a different endpoint (PUT) and a different request + # body (the `In` document) than the create (POST + `PostOptionalId` document). + outcome = sdk.catalog_workspace.create_or_update_computed_attribute( + workspace_id, _computed_attribute(title="Renamed") + ) + assert outcome == UpsertOutcome.UPDATED + computed_attribute_o = sdk.catalog_workspace.get_computed_attribute(workspace_id, computed_attribute_id) + assert computed_attribute_o.attributes.title == "Renamed" + + sdk.catalog_workspace.delete_computed_attribute(workspace_id, computed_attribute_id) + assert {ca.id for ca in sdk.catalog_workspace.list_computed_attributes(workspace_id)} == existing_ids + finally: + safe_delete(sdk.catalog_workspace.delete_computed_attribute, workspace_id, computed_attribute_id) + + +@gd_vcr.use_cassette(str(_fixtures_dir / "computed_attribute_generated_id.yaml")) +def test_create_computed_attribute_with_generated_id(test_config): + """A computed attribute created without an id gets one from the backend. + + Unlike filter views, user data filters and workspace settings, the computed + attribute POST schema really does accept a missing id -- see + ``TestIdLessCreateIsUnreachable`` in test_upsert_outcome.py for why the others + cannot do this. + """ + sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"]) + workspace_id = test_config["workspace"] + computed_attribute = CatalogComputedAttribute.init(maql="SELECT 1", title="Generated id") + + def _created_ids() -> set[str | None]: + return {ca.id for ca in sdk.catalog_workspace.list_computed_attributes(workspace_id)} - existing_ids + + def _delete_created() -> None: + # The SDK does not return the generated id, so the cleanup finds what this test created + # on its own instead of relying on the assertions below having run - and deletes only that. + for created_id in _created_ids(): + sdk.catalog_workspace.delete_computed_attribute(workspace_id, created_id) + + existing_ids = {ca.id for ca in sdk.catalog_workspace.list_computed_attributes(workspace_id)} + try: + outcome = sdk.catalog_workspace.create_or_update_computed_attribute(workspace_id, computed_attribute) + assert outcome == UpsertOutcome.CREATED + + created_ids = _created_ids() + assert len(created_ids) == 1 + # The backend generated the id; the SDK must not have sent a literal "None". + generated_id = created_ids.pop() + assert generated_id + assert generated_id != "None" + finally: + safe_delete(_delete_created) + + @gd_vcr.use_cassette(str(_fixtures_dir / "get_metadata_localization.yaml")) def test_get_metadata_localization(test_config): sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"]) diff --git a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace_content.py b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace_content.py index b4648b631..3ae2258e2 100644 --- a/packages/gooddata-sdk/tests/catalog/test_catalog_workspace_content.py +++ b/packages/gooddata-sdk/tests/catalog/test_catalog_workspace_content.py @@ -248,8 +248,8 @@ def test_documents_survive_store_load_and_put(test_config): identifier = test_documents_survive_store_load_and_put.__name__ path = _current_dir / "store" / "documents" recreate_directory(path) - # The seed's createdAt is the cassette normalizer's canonical value, so a replayed read returns - # the same author fields a recording run sees. + # The seed's createdAt and modifiedAt are the cassette normalizer's canonical value, so a replayed + # read returns the same author fields a recording run sees. with open(_current_dir / "expected" / "declarative_analytics_model_documents.json") as f: seed = json.load(f) seed_document = seed["analytics"]["documents"][0] diff --git a/packages/gooddata-sdk/tests/catalog/test_upsert_outcome.py b/packages/gooddata-sdk/tests/catalog/test_upsert_outcome.py index bf96ed830..805b71ab6 100644 --- a/packages/gooddata-sdk/tests/catalog/test_upsert_outcome.py +++ b/packages/gooddata-sdk/tests/catalog/test_upsert_outcome.py @@ -14,6 +14,7 @@ ) from gooddata_sdk.catalog.organization.entity_model.export_template import CatalogExportTemplateAttributes from gooddata_sdk.catalog.organization.service import CatalogOrganizationService +from gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute import CatalogComputedAttribute from gooddata_sdk.catalog.workspace.entity_model.filter_view import CatalogFilterView from gooddata_sdk.catalog.workspace.entity_model.user_data_filter import CatalogUserDataFilter from gooddata_sdk.catalog.workspace.service import CatalogWorkspaceService @@ -21,7 +22,10 @@ # The create/update branch is decided by whether the preceding entity GET raises # NotFoundException, so these stub that getter instead of replaying a cassette. # They cover what no cassette covers upstream: filter views, export templates, -# and the update branch of user data filters. +# and the update branch of user data filters. Computed attributes are covered by +# cassettes too (test_catalog_workspace.py); the stubs here additionally pin which +# generated endpoint each branch calls, because create and update take different +# request bodies. def _service(cls, getter: str, *, found: bool): @@ -48,6 +52,12 @@ def _user_data_filter(user_data_filter_id: str | None = "udf") -> CatalogUserDat return evolve(udf, id=user_data_filter_id) +def _computed_attribute(computed_attribute_id: str | None = "ca") -> CatalogComputedAttribute: + return CatalogComputedAttribute.init( + computed_attribute_id=computed_attribute_id, maql="SELECT 1", title="Test computed attribute" + ) + + def _export_template() -> CatalogExportTemplate: return CatalogExportTemplate( id="test_template", @@ -117,6 +127,48 @@ def test_created_without_id(self): service._entities_api.create_entity_custom_application_settings.assert_called_once() +class TestComputedAttributeOutcome: + def test_created_when_absent(self): + service = _service(CatalogWorkspaceService, "get_computed_attribute", found=False) + assert service.create_or_update_computed_attribute("demo", _computed_attribute()) == UpsertOutcome.CREATED + service._entities_api.create_entity_computed_attributes.assert_called_once() + service._entities_api.update_entity_computed_attributes.assert_not_called() + + def test_updated_when_present(self): + service = _service(CatalogWorkspaceService, "get_computed_attribute", found=True) + assert service.create_or_update_computed_attribute("demo", _computed_attribute()) == UpsertOutcome.UPDATED + service._entities_api.update_entity_computed_attributes.assert_called_once() + service._entities_api.create_entity_computed_attributes.assert_not_called() + + def test_create_bodies_are_not_interchangeable(self): + """Create takes the `PostOptionalId` document, update takes the `In` document. + + Regression test: the create branch was first wired to the `In` document, copied + from the filter-view template above, which raised a TypeError from the generated + client. Asserting on the keyword pins each endpoint to its own body. + """ + service = _service(CatalogWorkspaceService, "get_computed_attribute", found=False) + service.create_or_update_computed_attribute("demo", _computed_attribute()) + create_kwargs = service._entities_api.create_entity_computed_attributes.call_args.kwargs + assert "json_api_computed_attribute_post_optional_id_document" in create_kwargs + + service = _service(CatalogWorkspaceService, "get_computed_attribute", found=True) + service.create_or_update_computed_attribute("demo", _computed_attribute()) + update_kwargs = service._entities_api.update_entity_computed_attributes.call_args.kwargs + assert "json_api_computed_attribute_in_document" in update_kwargs + + def test_id_less_create_skips_the_lookup(self): + """With no id there is nothing to look up, so it goes straight to create. + + Computed attributes are the one entity where this genuinely works -- see + TestIdLessCreateIsUnreachable for why the others cannot. + """ + service = _service(CatalogWorkspaceService, "get_computed_attribute", found=True) + assert service.create_or_update_computed_attribute("demo", _computed_attribute(None)) == UpsertOutcome.CREATED + service.get_computed_attribute.assert_not_called() + service._entities_api.create_entity_computed_attributes.assert_called_once() + + class TestExportTemplateOutcome: def test_created_when_absent(self): service = _service(CatalogOrganizationService, "get_export_template", found=False) @@ -139,6 +191,10 @@ class TestIdLessCreateIsUnreachable: "accept None". These are strict xfails so that fixing the generated client (or the entity models) trips them and this file gets revisited, rather than the outcome contract silently claiming to cover a dead path. + + CatalogComputedAttribute shows the way out: its `to_post_api()` omits the id + key entirely instead of passing None, so its id-less create really does work + (TestComputedAttributeOutcome.test_id_less_create_skips_the_lookup). """ @pytest.mark.xfail(raises=ApiTypeError, strict=True, reason="generated client rejects a None id") diff --git a/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_computed_attributes.py b/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_computed_attributes.py new file mode 100644 index 000000000..21a5d9b3a --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/unit_tests/test_aac_computed_attributes.py @@ -0,0 +1,103 @@ +# (C) 2026 GoodData Corporation +from __future__ import annotations + +from pathlib import Path +from typing import Any + +from gooddata_sdk.catalog.workspace.aac import ( + _build_entities, + aac_visualization_to_declarative, + detect_yaml_format, + load_aac_workspace_from_disk, + store_aac_workspace_to_disk, +) +from gooddata_sdk.catalog.workspace.declarative_model.workspace.workspace import CatalogDeclarativeWorkspaceModel +from gooddata_sdk.utils import read_layout_from_file + +_COMPUTED_ATTRIBUTE = { + "id": "order_size", + "title": "Order size", + "description": "Orders grouped by their size", + "tags": ["Orders"], + "content": {"maql": 'SELECT CASE WHEN {metric/revenue} > 100 THEN "Large" ELSE "Small" END', "format": "#,##0"}, + "dataType": "STRING", + "isHidden": True, +} +# The AAC form of a visualization that slices by the computed attribute above. +_AAC_VISUALIZATION = { + "id": "rating_by_order_size", + "type": "table", + "title": "Rating by order size", + "query": { + "fields": { + "size": "computed_attribute/order_size", + "sum_rating": {"title": "Sum of Rating", "aggregation": "SUM", "using": "fact/rating"}, + } + }, + "metrics": [{"field": "sum_rating"}], + "view_by": ["size"], +} + + +def _model(analytics: dict[str, Any]) -> CatalogDeclarativeWorkspaceModel: + return CatalogDeclarativeWorkspaceModel.from_dict({"analytics": analytics}) + + +def _reloaded_analytics(path: Path) -> dict[str, Any]: + return load_aac_workspace_from_disk(path).to_dict(camel_case=True).get("analytics", {}) + + +def _attribute_identifiers(visualization: dict[str, Any]) -> list[dict[str, Any]]: + return [ + item["attribute"]["displayForm"]["identifier"] + for bucket in visualization["content"]["buckets"] + for item in bucket["items"] + if "attribute" in item + ] + + +def test_store_writes_computed_attribute_file(tmp_path: Path) -> None: + store_aac_workspace_to_disk(_model({"computedAttributes": [_COMPUTED_ATTRIBUTE]}), tmp_path) + + aac = read_layout_from_file(tmp_path / "computedAttributes" / "order_size.yaml") + + assert aac["type"] == "computed_attribute" + assert aac["id"] == "order_size" + assert aac["maql"] == _COMPUTED_ATTRIBUTE["content"]["maql"] + + +def test_computed_attribute_round_trips_through_aac(tmp_path: Path) -> None: + store_aac_workspace_to_disk(_model({"computedAttributes": [_COMPUTED_ATTRIBUTE]}), tmp_path) + + assert _reloaded_analytics(tmp_path)["computedAttributes"] == [_COMPUTED_ATTRIBUTE] + + +def test_visualization_reference_to_computed_attribute_round_trips(tmp_path: Path) -> None: + aac_computed_attribute = {"type": "computed_attribute", "id": "order_size", "maql": "SELECT 1"} + entities = _build_entities([aac_computed_attribute, _AAC_VISUALIZATION]) + visualization = aac_visualization_to_declarative(_AAC_VISUALIZATION, entities) + assert _attribute_identifiers(visualization) == [{"id": "order_size", "type": "computedAttribute"}] + + store_aac_workspace_to_disk( + _model({"computedAttributes": [_COMPUTED_ATTRIBUTE], "visualizationObjects": [visualization]}), tmp_path + ) + analytics = _reloaded_analytics(tmp_path) + + assert [ca["id"] for ca in analytics["computedAttributes"]] == ["order_size"] + [reloaded_visualization] = analytics["visualizationObjects"] + assert _attribute_identifiers(reloaded_visualization) == [{"id": "order_size", "type": "computedAttribute"}] + + +def test_workspace_without_computed_attributes_has_no_folder_or_key(tmp_path: Path) -> None: + store_aac_workspace_to_disk( + _model({"metrics": [{"id": "m1", "title": "Metric 1", "content": {"maql": "SELECT 1"}}]}), tmp_path + ) + + assert not (tmp_path / "computedAttributes").exists() + assert "computedAttributes" not in _reloaded_analytics(tmp_path) + + +def test_computed_attributes_folder_is_detected_as_aac(tmp_path: Path) -> None: + (tmp_path / "computedAttributes").mkdir() + + assert detect_yaml_format(tmp_path) == "aac" diff --git a/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_computed_attributes.py b/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_computed_attributes.py new file mode 100644 index 000000000..7d288b999 --- /dev/null +++ b/packages/gooddata-sdk/tests/catalog/unit_tests/test_declarative_computed_attributes.py @@ -0,0 +1,131 @@ +# (C) 2026 GoodData Corporation +"""Unit test: analytics-layer ``computed_attributes`` survive the declarative round-trip. + +The declarative round-trip is the whole point of CA support in the SDK - it is what +gives analytics-as-code parity with the backend layout API (CQ-2799 / CQ-2800). A +computed attribute that goes into ``analytics_model/computed_attributes/`` must come +back out unchanged, including the nested ``content`` ({maql, format, metricType}). +""" + +from __future__ import annotations + +from pathlib import Path + +import pytest +from gooddata_sdk import ( + CatalogComputedAttribute, + CatalogComputedAttributeDocument, + CatalogComputedAttributePostDocument, + CatalogDeclarativeAnalytics, +) +from gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model import ( + CatalogDeclarativeAnalyticsLayer, +) +from gooddata_sdk.compute.model.attribute import Attribute +from gooddata_sdk.compute.model.base import ObjId + +_COMPUTED_ATTRIBUTE = { + "id": "sales-band", + "title": "Sales Band", + "description": "Bucketed sales.", + "content": {"maql": "SELECT 1", "format": "#,##0", "metricType": "UNSPECIFIED"}, + "dataType": "STRING", + "tags": ["Sales"], +} +_LAYOUT = {"analytics": {"computedAttributes": [_COMPUTED_ATTRIBUTE]}} + + +def test_declarative_computed_attributes_survive_round_trip() -> None: + analytics = CatalogDeclarativeAnalytics.from_dict(_LAYOUT) + + computed_attributes = analytics.analytics.computed_attributes + assert len(computed_attributes) == 1 + assert computed_attributes[0].id == "sales-band" + assert computed_attributes[0].title == "Sales Band" + assert computed_attributes[0].data_type == "STRING" + # The nested content is typed, not a bare dict. + assert computed_attributes[0].content.maql == "SELECT 1" + assert computed_attributes[0].content.format == "#,##0" + assert computed_attributes[0].content.metric_type == "UNSPECIFIED" + + round_tripped = analytics.to_api().to_dict(camel_case=True) + assert round_tripped["analytics"]["computedAttributes"] == [_COMPUTED_ATTRIBUTE] + + +def test_declarative_computed_attributes_survive_disk_round_trip(tmp_path: Path) -> None: + layer = CatalogDeclarativeAnalyticsLayer.from_dict({"computedAttributes": [_COMPUTED_ATTRIBUTE]}) + + layer.store_to_disk(tmp_path) + assert (tmp_path / "analytics_model" / "computed_attributes" / "sales-band.yaml").exists() + + reloaded = CatalogDeclarativeAnalyticsLayer.load_from_disk(tmp_path) + assert reloaded.computed_attributes == layer.computed_attributes + assert reloaded.to_dict(camel_case=True)["computedAttributes"] == [_COMPUTED_ATTRIBUTE] + + +def _computed_attribute(**kwargs: object) -> CatalogComputedAttribute: + return CatalogComputedAttribute.init(maql="SELECT 1", title="Sales Band", format="#,##0", **kwargs) # type: ignore[arg-type] + + +_EXPECTED_ATTRIBUTES = {"title": "Sales Band", "content": {"maql": "SELECT 1", "format": "#,##0"}} + + +def test_computed_attribute_entity_serializes_to_json_api_document() -> None: + """The PUT (update) endpoint takes the `In` document, which requires the id.""" + document = CatalogComputedAttributeDocument(data=_computed_attribute(computed_attribute_id="sales-band")) + + assert document.to_api().to_dict(camel_case=True) == { + "data": {"id": "sales-band", "type": "computedAttribute", "attributes": _EXPECTED_ATTRIBUTES} + } + + +def test_computed_attribute_post_document_carries_the_optional_id_body() -> None: + """The POST (create) endpoint takes its own document, whose id is optional. + + Regression test: the create call was originally wired to the `In` document, copied + from the filter-view template. Computed attributes have a separate POST schema, so + that raised a TypeError from the generated client before it ever reached the backend. + """ + with_id = CatalogComputedAttributePostDocument(data=_computed_attribute(computed_attribute_id="sales-band")) + assert with_id.to_api().to_dict(camel_case=True) == { + "data": {"id": "sales-band", "type": "computedAttribute", "attributes": _EXPECTED_ATTRIBUTES} + } + + # No id - the backend generates one, so the key must be absent rather than null. + without_id = CatalogComputedAttributePostDocument(data=_computed_attribute()) + assert without_id.to_api().to_dict(camel_case=True) == { + "data": {"type": "computedAttribute", "attributes": _EXPECTED_ATTRIBUTES} + } + + +def test_computed_attribute_without_id_cannot_be_updated() -> None: + with pytest.raises(ValueError, match="id is required for an update"): + CatalogComputedAttributeDocument(data=_computed_attribute()).to_api() + + +def _label_slot(label: str | ObjId) -> dict[str, dict[str, str]]: + return Attribute(local_id="a", label=label).as_api_model().to_dict(camel_case=True)["label"] + + +def test_computed_attribute_can_slice_an_execution() -> None: + """A computed attribute is referenced through the label slot of an AFM attribute.""" + assert _label_slot(ObjId("sales-band", "computedAttribute")) == { + "identifier": {"id": "sales-band", "type": "computedAttribute"} + } + + # Plain labels keep working - the type is no longer defaulted by the generated client. + assert _label_slot("region") == {"identifier": {"id": "region", "type": "label"}} + assert _label_slot(ObjId("region", "label")) == {"identifier": {"id": "region", "type": "label"}} + + +@pytest.mark.parametrize("obj_id_type", ["attribute", "dataset", "fact", "metric"]) +def test_non_computed_attribute_obj_id_still_slices_by_label(obj_id_type: str) -> None: + """An ObjId of any other type keeps going to the API as a label. + + Regression test: `AfmObjectIdentifierLabelIdentifier.type` used to be defaulted by the + generated client, so the ObjId type was ignored and every type reached the API as a + label. Once the enum gained "computedAttribute" the type became required, and forwarding + it verbatim raised ApiValueError for external callers that pass some other type -- a + visualization ref carries whatever type it was stored with (see utils.ref_extract). + """ + assert _label_slot(ObjId("region", obj_id_type)) == {"identifier": {"id": "region", "type": "label"}} diff --git a/packages/gooddata-sdk/tests/support/test_vcr_timestamp_normalization.py b/packages/gooddata-sdk/tests/support/test_vcr_timestamp_normalization.py new file mode 100644 index 000000000..e2b256b92 --- /dev/null +++ b/packages/gooddata-sdk/tests/support/test_vcr_timestamp_normalization.py @@ -0,0 +1,43 @@ +# (C) 2026 GoodData Corporation +from __future__ import annotations + +import pytest +from tests_support.vcrpy_utils import _CANONICAL_TIMESTAMP, _normalize_hashes_in_text + +_TS = "2026-11-27 10:15" + + +@pytest.mark.parametrize( + ("text", "expected"), + [ + # stdlib JSON + (f'{{"createdAt": "{_TS}"}}', f'{{"createdAt": "{_CANONICAL_TIMESTAMP}"}}'), + (f'{{"modifiedAt": "{_TS}"}}', f'{{"modifiedAt": "{_CANONICAL_TIMESTAMP}"}}'), + # orjson + (f'{{"createdAt":"{_TS}"}}', f'{{"createdAt":"{_CANONICAL_TIMESTAMP}"}}'), + (f'{{"modifiedAt":"{_TS}"}}', f'{{"modifiedAt":"{_CANONICAL_TIMESTAMP}"}}'), + # YAML, top-level, nested and as the first key of a list item + (f"modifiedAt: {_TS}\n", f"modifiedAt: {_CANONICAL_TIMESTAMP}\n"), + (f"data:\n createdAt: {_TS}\n", f"data:\n createdAt: {_CANONICAL_TIMESTAMP}\n"), + (f"items:\n - modifiedAt: {_TS}\n", f"items:\n - modifiedAt: {_CANONICAL_TIMESTAMP}\n"), + ], +) +def test_timestamp_fields_are_normalized(text: str, expected: str) -> None: + assert _normalize_hashes_in_text(text) == expected + + +@pytest.mark.parametrize( + "text", + [ + # The key text inside a string value, in JSON and in YAML + f'{{"description": "modifiedAt: {_TS}"}}', + f"description: modifiedAt: {_TS}\n", + f"description: 'see modifiedAt: {_TS}'\n", + # A longer key that merely ends with a timestamp key + f'{{"lastModifiedAt": "{_TS}"}}', + f'{{"xcreatedAt": "{_TS}"}}', + f"xcreatedAt: {_TS}\n", + ], +) +def test_timestamp_text_outside_a_field_is_kept(text: str) -> None: + assert _normalize_hashes_in_text(text) == text diff --git a/packages/tests-support/src/tests_support/vcrpy_utils.py b/packages/tests-support/src/tests_support/vcrpy_utils.py index 9fba5b501..b10d965c0 100644 --- a/packages/tests-support/src/tests_support/vcrpy_utils.py +++ b/packages/tests-support/src/tests_support/vcrpy_utils.py @@ -61,14 +61,17 @@ _normalization_configured: bool = False # --- Timestamp normalization --- -_CREATED_AT_RE = re.compile( - r'(?<=createdAt": ")\d{4}-\d{2}-\d{2} \d{2}:\d{2}' # JSON (stdlib): "createdAt": "..." - r"|" - r'(?<=createdAt":")\d{4}-\d{2}-\d{2} \d{2}:\d{2}' # JSON (orjson): "createdAt":"..." - r"|" - r"(?<=createdAt: )\d{4}-\d{2}-\d{2} \d{2}:\d{2}" # YAML: createdAt: ... +# Entity timestamps change on every recording, so canonicalize them: otherwise a +# re-recorded cassette differs from its predecessor by timestamps alone. The key is +# matched only as a whole key: in JSON it must be quoted on both sides (stdlib +# "key": "val" or orjson "key":"val"), in YAML it must open a line, optionally as a +# list item. A string value merely containing "modifiedAt: " stays as is. +_TIMESTAMP_KEYS = "createdAt|modifiedAt" +_TIMESTAMP_RE = re.compile( + rf'(?P"(?:{_TIMESTAMP_KEYS})": ?"|^[ \t]*(?:- )?(?:{_TIMESTAMP_KEYS}): )\d{{4}}-\d{{2}}-\d{{2}} \d{{2}}:\d{{2}}', + re.MULTILINE, ) -_CANONICAL_CREATED_AT = "2000-01-01 00:00" +_CANONICAL_TIMESTAMP = "2000-01-01 00:00" # --- Transient server value normalization --- # All patterns need both stdlib JSON ("key": "val") and orjson ("key":"val") variants. @@ -280,7 +283,7 @@ def _normalize_hashes_in_text(text: str) -> str: """Replace transient server values with deterministic placeholders.""" text = _EXEC_HASH_BODY_RE.sub(_exec_hash_replacer, text) text = _EXPORT_HASH_BODY_RE.sub(_export_hash_replacer, text) - text = _CREATED_AT_RE.sub(_CANONICAL_CREATED_AT, text) + text = _TIMESTAMP_RE.sub(lambda m: m.group("key") + _CANONICAL_TIMESTAMP, text) text = _TRACE_ID_RE.sub(_CANONICAL_TRACE_ID, text) text = _AUTH_ID_RE.sub(_CANONICAL_AUTH_ID, text) text = _BEARER_TOKEN_RE.sub(_CANONICAL_BEARER_TOKEN, text)