Skip to content

Commit

Permalink
Merge pull request #582 from Tjev/cq-230-transpose-support
Browse files Browse the repository at this point in the history
feat(gooddata-sdk) - execDef assembly logic transposition support

Reviewed-by: Jan Kadlec
             https://github.com/hkad98
  • Loading branch information
gdgate authored Mar 8, 2024
2 parents 8cf5ba9 + 08690e2 commit d8c2d7f
Show file tree
Hide file tree
Showing 5 changed files with 1,110 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gooddata-sdk/gooddata_sdk/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,23 @@ def _append_attribute_sort_key(
)


def _vis_is_transposed(visualization: Visualization) -> bool:
controls = visualization.properties.get("controls")
if not controls:
return False
return controls.get("measureGroupDimension") == "rows"


def _create_dimensions(visualization: Visualization) -> list[TableDimension]:
# TODO: measures item id placement should reflect table transposition setting
measures_item_identifier = _MEASURE_GROUP_IDENTIFIER if visualization.metrics else None
row_bucket = visualization.get_bucket_of_type(BucketType.ROWS)
col_bucket = visualization.get_bucket_of_type(BucketType.COLS)
is_transposed = _vis_is_transposed(visualization)
row_measure_item_identifier = measures_item_identifier if is_transposed else None
col_measure_item_identifier = None if is_transposed else measures_item_identifier
dims = [
_create_dimension(row_bucket),
_create_dimension(col_bucket, measures_item_identifier),
_create_dimension(row_bucket, row_measure_item_identifier),
_create_dimension(col_bucket, col_measure_item_identifier),
]
return _create_dims_with_sorts(dims, visualization.sorts)

Expand Down
274 changes: 274 additions & 0 deletions gooddata-sdk/tests/table/fixtures/vis_objs/fancy_transposed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
{
"id":"463bcab4-5ba2-4854-a33f-1219c00419d2",
"type":"visualizationObject",
"attributes":{
"title":"testik",
"description":"",
"areRelationsValid":true,
"content":{
"buckets":[
{
"items":[
{
"measure":{
"localIdentifier":"08d8346c1ce7438994b251991c0fbf65",
"definition":{
"measureDefinition":{
"item":{
"identifier":{
"id":"percent_revenue_per_product",
"type":"metric"
}
},
"filters":[

]
}
},
"title":"% Revenue per Product"
}
},
{
"measure":{
"localIdentifier":"b2350c06688b4da9b3833ebcce65527f",
"definition":{
"measureDefinition":{
"item":{
"identifier":{
"id":"revenue",
"type":"metric"
}
},
"filters":[

]
}
},
"title":"Revenue"
}
}
],
"localIdentifier":"measures"
},
{
"items":[
{
"attribute":{
"localIdentifier":"6a003ffd14994237ba64c4a02c488429",
"displayForm":{
"identifier":{
"id":"products.category",
"type":"label"
}
}
}
},
{
"attribute":{
"localIdentifier":"75ea396d0c8b48098e31dccf8b5801d3",
"displayForm":{
"identifier":{
"id":"product_name",
"type":"label"
}
}
}
}
],
"localIdentifier":"attribute",
"totals":[
{
"type":"sum",
"measureIdentifier":"b2350c06688b4da9b3833ebcce65527f",
"attributeIdentifier":"6a003ffd14994237ba64c4a02c488429"
},
{
"type":"sum",
"measureIdentifier":"b2350c06688b4da9b3833ebcce65527f",
"attributeIdentifier":"75ea396d0c8b48098e31dccf8b5801d3"
}
]
},
{
"items":[
{
"attribute":{
"localIdentifier":"f06c3e7d31bc466e878e990b2b379f8c",
"displayForm":{
"identifier":{
"id":"region",
"type":"label"
}
}
}
},
{
"attribute":{
"localIdentifier":"52c625146bd245559dc236e187d6244d",
"displayForm":{
"identifier":{
"id":"state",
"type":"label"
}
}
}
}
],
"localIdentifier":"columns",
"totals":[
{
"type":"sum",
"measureIdentifier":"08d8346c1ce7438994b251991c0fbf65",
"attributeIdentifier":"52c625146bd245559dc236e187d6244d"
},
{
"type":"sum",
"measureIdentifier":"b2350c06688b4da9b3833ebcce65527f",
"attributeIdentifier":"52c625146bd245559dc236e187d6244d"
},
{
"type":"sum",
"measureIdentifier":"08d8346c1ce7438994b251991c0fbf65",
"attributeIdentifier":"f06c3e7d31bc466e878e990b2b379f8c"
},
{
"type":"sum",
"measureIdentifier":"b2350c06688b4da9b3833ebcce65527f",
"attributeIdentifier":"f06c3e7d31bc466e878e990b2b379f8c"
}
]
}
],
"filters":[
{
"negativeAttributeFilter":{
"displayForm":{
"identifier":{
"id":"customer_name",
"type":"label"
}
},
"notIn":{
"uris":[

]
}
}
},
{
"negativeAttributeFilter":{
"displayForm":{
"identifier":{
"id":"products.category",
"type":"label"
}
},
"notIn":{
"uris":[

]
}
}
},
{
"negativeAttributeFilter":{
"displayForm":{
"identifier":{
"id":"product_name",
"type":"label"
}
},
"notIn":{
"uris":[

]
}
}
}
],
"sorts":[
{
"attributeSortItem":{
"attributeIdentifier":"6a003ffd14994237ba64c4a02c488429",
"direction":"asc"
}
}
],
"properties":{
"controls":{
"columnWidths":[
{
"attributeColumnWidthItem":{
"attributeIdentifier":"75ea396d0c8b48098e31dccf8b5801d3",
"width":{
"value":101
}
}
}
],
"measureGroupDimension":"rows"
}
},
"visualizationUrl":"local:table",
"version":"2"
},
"createdAt":"2024-03-07 16:08",
"modifiedAt":"2024-03-07 16:09"
},
"relationships":{
"createdBy":{
"data":{
"id":"demo",
"type":"userIdentifier"
}
},
"modifiedBy":{
"data":{
"id":"demo",
"type":"userIdentifier"
}
},
"metrics":{
"data":[
{
"id":"percent_revenue_per_product",
"type":"metric"
},
{
"id":"revenue",
"type":"metric"
}
]
},
"labels":{
"data":[
{
"id":"customer_name",
"type":"label"
},
{
"id":"product_name",
"type":"label"
},
{
"id":"products.category",
"type":"label"
},
{
"id":"region",
"type":"label"
},
{
"id":"state",
"type":"label"
}
]
}
},
"meta":{
"origin":{
"originType":"NATIVE",
"originId":"demo"
}
}
}
Loading

0 comments on commit d8c2d7f

Please sign in to comment.