Pivot table result aggregation ignores per-metric/currency formatters
Bug description
Pivot Table v2's restored "Aggregation function" result-aggregation reducers (Sum/Average/Median/Sample Variance/Sample Standard Deviation/Minimum/Maximum/...) always render with hardcoded US number formatting, ignoring:
- A metric's own custom value format (currency, decimal places, d3-format string)
- Currency formatting / AUTO currency detection
- Any other per-metric formatter the metric-definition path (
showValuesAs/cellValue) already respects
Root cause
superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts's aggregators dict builds each entry with a fixed formatter baked in at module load time, e.g.:
const aggregators = (tpl => ({
Sum: tpl.sum(usFmt),
Average: tpl.average(usFmt),
...
}))(aggregatorTemplates);PivotData's resultFactory (the wrapper that powers result aggregation, see processResultRecord) calls aggregators[resultAggregation] directly with no way to pass in a different formatter. This is inherited, unmodified behavior from the pre-SIP-216 aggregators dict this feature reuses verbatim (see #44660) -- not a new regression, but a real gap now that this control is back in active use.
Fix sketch
aggregators' entries would need to become formatter-parameterized (e.g. Average: (f = usFmt) => tpl.average(f)) so resultFactory can thread this.props.defaultFormatter/per-metric custom formats/currency context through, the same way cellValue(formatter) already does for the metric-definition path. This touches the dict's shape and its existing direct callers/tests (aggregators.Average(['x'])() etc.), so it's a moderate, not a one-line, change.
How to reproduce
- Set a pivot table's metric to use a custom value format (e.g. a currency or a specific decimal precision).
- Set "Aggregation function" to anything other than "Use metric definition" (e.g. "Average").
- Cell values render with default US number formatting instead of the configured format.
Source: apache/superset