Skip to content

Commit 01ebbfa

Browse files
committed
feat: add support for native totals
Properly support the native totals in executions and in tables. JIRA: CQ-633 risk: low
1 parent de65a0f commit 01ebbfa

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

gooddata-sdk/gooddata_sdk/compute/model/execution.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TotalDefinition:
3333
"""total's local identifier"""
3434

3535
aggregation: str
36-
"""aggregation function; case insensitive; one of SUM, MIN, MAX, MED, AVG"""
36+
"""aggregation function; case insensitive; one of SUM, MIN, MAX, MED, AVG, NAT"""
3737

3838
metric_local_id: str
3939
"""local identifier of the measure to calculate total for"""
@@ -175,13 +175,20 @@ def _create_totals(self) -> Optional[list[models.Total]]:
175175
models.Total(
176176
local_identifier=total.local_id,
177177
metric=total.metric_local_id,
178-
function=total.aggregation.upper(),
178+
function=ExecutionDefinition._convert_total_aggregation(total.aggregation),
179179
total_dimensions=total_dims,
180180
)
181181
)
182182

183183
return totals
184184

185+
@staticmethod
186+
def _convert_total_aggregation(aggregation: str) -> str:
187+
# native total is represented as NAT in visualization objects, but needs to be NATIVE in execution
188+
if aggregation.upper() == "NAT":
189+
return "NATIVE"
190+
return aggregation.upper()
191+
185192
def _create_result_spec(self) -> models.ResultSpec:
186193
dimensions = self._create_dimensions()
187194
totals = self._create_totals()

gooddata-sdk/gooddata_sdk/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
logger = logging.getLogger(__name__)
3939

4040
_MEASURE_GROUP_IDENTIFIER = "measureGroup"
41-
_TOTAL_ORDER = ["SUM", "MAX", "MIN", "AVG", "MED"]
41+
_TOTAL_ORDER = ["SUM", "MAX", "MIN", "AVG", "MED", "NAT"]
4242

4343
_TABLE_ROW_BATCH_SIZE = 512
4444
"""

0 commit comments

Comments
 (0)