You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Dmitry-Kucher (via GitHub)" <gi...@apache.org> on 2026/08/22 07:59:55 UTC
[PR] fix(table): keep each metric's own aggregate in the summary row by default [superset]
Dmitry-Kucher opened a new pull request, #43421:
URL: https://github.com/apache/superset/pull/43421
### SUMMARY
Fixes #43420.
#43027 added a Sum/Average control for the Table and AG Grid Table "Show summary" row, and applied it to every Simple (adhoc) metric unconditionally. The control defaults to `SUM` and is `clearable: false`, so there is no way to keep a metric's own aggregation — and a chart saved before that PR, which has no `totals_aggregate` in its form data, is coerced into `SUM` too.
That silently changes what the summary row means:
- `COUNT_DISTINCT(col)` becomes `SUM(col)`. If `col` is not numeric the database refuses the query outright — on Postgres with a `uuid` column, `function sum(uuid) does not exist`. If it is numeric, the row shows the sum of the ids and nothing signals that anything is wrong.
- The same applies to `COUNT`, `MIN` and `MAX`.
Only the summary query is affected (`queries[1]`, `columns: []`); the main query stays correct, so a partly-broken chart is easy to miss.
#43027's rationale — that swapping the aggregate is safe because the summary query has no `GROUP BY`, so each metric is evaluated fresh over all rows — holds arithmetically. What it does not account for is that the swap assumes the metric's column is summable, and that replacing the aggregate preserves the user's intent. Neither holds for the counting aggregates.
**This PR** adds `ORIGINAL` as a third choice and makes it the default:
- `getTotalsMetrics(metrics, 'ORIGINAL')` returns the metrics untouched.
- A new `toTotalsAggregate()` narrows the raw form-data value in one place, so anything that is not an explicit `SUM`/`AVG` — including charts saved before the control existed — resolves to `ORIGINAL` instead of falling into `SUM`.
- Both control panels gain an "Each metric's own" option, which becomes the default.
Sum and Average remain available exactly as designed in #43027, just as a deliberate choice rather than something applied to every chart on upgrade. Existing charts go back to the behaviour they had before that PR.
AG Grid's raw-mode summary columns are built from column names and have no aggregate of their own to preserve, so they keep summing; `ORIGINAL` maps to `SUM` on that path only.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before, a Table chart with `COUNT_DISTINCT` over a uuid column and "Show summary" enabled:
```
Ошибка базы данных
Error: function sum(uuid) does not exist
LINE 1: SELECT sum(contract_id) AS "Кол-во", SUM(contract_amount/100... ^
HINT: No function matches the given name and argument types.
```
After, the chart renders and the summary row shows the distinct count.
### TESTING INSTRUCTIONS
Manual:
1. Table chart, Aggregate mode, one dimension, one metric `COUNT_DISTINCT(<uuid column>)`.
2. Enable **Show summary**. On `master` the chart fails with `function sum(uuid) does not exist`; with this change it renders, and **Summary aggregation** shows "Each metric's own".
3. Switch **Summary aggregation** to Sum or Average — the override still applies, as added in #43027.
4. Repeat with an AG Grid Table chart, in both Aggregate and Raw mode. Raw mode still sums its summary columns.
Automated:
```
npx jest packages/superset-ui-chart-controls/src/utils/getTotalsMetrics.test.ts \
plugins/plugin-chart-table/test/buildQuery.test.ts \
plugins/plugin-chart-ag-grid-table/test/buildQuery.test.ts
```
127 tests pass. New coverage: `ORIGINAL` leaves every metric type untouched; `toTotalsAggregate` maps `SUM`/`AVG` through and everything else (including `undefined`) to `ORIGINAL`; and both plugins keep `COUNT_DISTINCT` in the summary query by default.
Two existing tests asserted the behaviour this PR changes — `defaults the totals query metric aggregate to SUM` and `defaults aggregate-mode totals to SUM for a simple metric` — and are updated to assert the metric's own aggregate is kept.
### ADDITIONAL INFORMATION
- [x] Has associated issue: #43420
- [ ] Required feature flags:
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
Introduced by #43027 (`f7a2f0ec50`). No follow-up commit has touched `getTotalsMetrics.ts` or the totals block in either plugin's `buildQuery.ts`, so `master` at `f2610e9dca` still has it.
cc @rusackas as the author of #43027 — happy to take this a different way if you would rather the override stay on by default and only be skipped for the counting aggregates; I went with an explicit default because that is also what makes the upgrade non-breaking.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(table): keep each metric's own aggregate in the summary row by default [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43421:
URL: https://github.com/apache/superset/pull/43421#issuecomment-5379872096
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43421?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 78.85%. Comparing base ([`f2610e9`](https://app.codecov.io/gh/apache/superset/commit/f2610e9dca01cb35e831bb89c3fcd5ef17111482?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`2e13315`](https://app.codecov.io/gh/apache/superset/commit/2e13315c2532568711e1c59c1c7f7ba6ad33a027?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #43421 +/- ##
=======================================
Coverage 78.85% 78.85%
=======================================
Files 2876 2876
Lines 164581 164586 +5
Branches 38011 38012 +1
=======================================
+ Hits 129786 129791 +5
Misses 32348 32348
Partials 2447 2447
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/43421/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [javascript](https://app.codecov.io/gh/apache/superset/pull/43421/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `74.21% <100.00%> (+<0.01%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43421?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(table): keep each metric's own aggregate in the summary row by default [superset]
Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe merged PR #43421:
URL: https://github.com/apache/superset/pull/43421
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(table): keep each metric's own aggregate in the summary row by default [superset]
Posted by "kokhlo (via GitHub)" <gi...@apache.org>.
kokhlo commented on PR #43421:
URL: https://github.com/apache/superset/pull/43421#issuecomment-5396486271
Thanks for picking this up — the `ORIGINAL` sentinel approach with `toTotalsAggregate()` is the right shape, and the coverage for both plugins is thorough. Two things I'd flag from reading the diff against current `master`:
**1. Raw-mode summary columns in the plain Table plugin may still need attention.**
The AG Grid plugin's `rawSummaryAggregate` fallback (`ORIGINAL` → `SUM` for raw-mode summary columns) is handled, but the plain Table plugin's summary path in raw mode goes through a different route — historically the Table summary in raw mode summarized `allColumns` (or `query_columns`) rather than metrics, and I don't see that path touched in this diff. If the raw-mode summary in plugin-chart-table also derives its aggregates through the same coercion logic, charts in raw mode saved without `totals_aggregate` would still get coerced. Worth a quick check that raw-mode `show_totals` in plugin-chart-table is either unaffected or handled.
**2. Migration semantics for charts saved with an explicit `totals_aggregate: 'SUM'`.**
The `toTotalsAggregate()` narrowing treats an explicit `'SUM'` as SUM — correct. But charts saved *after* #43027 (between 2026-08-13 and this fix) will carry `totals_aggregate: 'SUM'` in form data even when the user never touched the control (the control defaulted to SUM and was `clearable: false`, so any chart re-saved in that window carries the default baked in). For those charts the summary row keeps overriding to SUM — the exact broken behaviour the issue describes — and only manually switching the control to "Each metric's own" fixes them. That's arguably correct-by-default going forward (the stored value is what the user sees in the UI), but it means the regression isn't fully self-healing for the mid-window cohort. A heads-up in the PR description (or a follow-up migration) would save maintainers some confused issue comments later.
Minor: the regression-test comment in `plugin-chart-table/test/buildQuery.test.ts` ("Overriding this to SUM sums the counted column...") is good context — the same comment exists verbatim in the AG Grid test file; consider keeping just one and letting the other reference it, or leave as-is if duplication is preferred for test locality.
The rest checks out from my reading: `getTotalsMetrics` returning the input array by reference on `ORIGINAL` (no unnecessary clones), shared util exported from chart-controls, control descriptions rewritten to match new semantics, and both `buildQuery.ts` call sites narrowed through `toTotalsAggregate()` consistently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(table): keep each metric's own aggregate in the summary row by default [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43421:
URL: https://github.com/apache/superset/pull/43421#issuecomment-5379136470
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org