Repository navigation
feat(table/pivot-table): correct non-additive totals/subtotals via DB rollup [SIP-216] - #41184
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #41184 +/- ##
==========================================
+ Coverage 65.13% 65.19% +0.06%
==========================================
Files 2789 2791 +2
Lines 157538 157761 +223
Branches 35864 35931 +67
==========================================
+ Hits 102611 102858 +247
+ Misses 52956 52931 -25
- Partials 1971 1972 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
b28a7e6 to
89a40db
Compare
|
The SIP is up for a vote on the dev@ list... please VOTE if you wanna see this happen |
|
Following up on the earlier review: CI is currently red on this head (
That test file isn't part of this PR's own diff — it's an existing test that predates the rebase this branch picked up — and it was passing at the SHA this review was originally done against, so something in this PR's rewrite of the row/rollup logic is the likely cause rather than any of the small follow-up commits since (those only touch a control description, an unrelated table-chart test import, and a docstring). My guess, not yet confirmed: |
Code Review Agent Run #49d658Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…leaf level A result frame without GROUPING() marker columns (any query that never applied the grouping_sets extra) had every row discarded by the marker filter in splitGroupingSetsResult, rendering the chart completely blank -- surfaced by the pre-existing TableRenderer.test.tsx fixtures. Fall back to attributing all rows to the leaf level with empty rollup frames. Also replaces a raw NUL byte in the GROUP_SEP literal with the \u0000 escape so git stops treating utilities.ts as a binary file. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for catching this, @aminghadersohi. Turned out |
Code Review Agent Run #ca96b0Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
Thanks for digging in, @aminghadersohi. Good lead... though it turned out not to be the last-row logic at all. |
aminghadersohi
left a comment
There was a problem hiding this comment.
Verified at HEAD e417294: CI fully green, non-additive DB-rollup total logic correct (SUM/ratio totals computed per grouping level, not summed client-side), GROUPING SETS query construction is parameterized via SQLAlchemy (no injection surface), and the earlier TableRenderer.test.tsx/pvtRowLabelLast regression is fixed (splitGroupingSetsResult now handles marker-less result frames). All review threads resolved.
|
Been trying to get reviews on this for over a month by nagging people on slack, but I'll take the approval (thanks!) and lack of bot or human complaints as good enough... merging during the breaking change window to get it into 7.0, and will happily make touchups/fixes as needed when people do more testing than I already have. |
|
SUMMARY
Proof-of-concept for [SIP-216] / #41463 — fixing one of Superset's longest-standing correctness gaps: totals and subtotals are wrong for non-additive metrics (ratios,
COUNT_DISTINCT,AVG, percentiles, and "Percentage metrics") in both the Pivot Table and the regular Table chart.See #41463 for the full proposal, motivation, and rejected alternatives. This PR is the working implementation referenced throughout that SIP.
Core principle: totals are computed by the database at the grouping granularity, never by re-aggregating already-aggregated cells. A SQL-aggregate metric is correct at any grouping level if the same expression is evaluated grouped at that level, so no formula language is needed.
What's here (consolidates #25747, #32260, #38674, #36165, #37627, #34350/#34425/#34426):
GROUPING SETSquery (native where the engine supports it, per-level fallback otherwise); the react-pivottable aggregator becomes a passthrough that places DB-computed values. Removes the now-meaningless "Aggregation function" control.supports_grouping_setsengine capability, query-level pruning to only displayed totals.Builds on prior art in #34592 (salvages its rollup-combination generator). Out of scope: #39223.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
A
rows=[gender, state]pivot with a ratio metricSUM(CASE WHEN state='CA' …)/SUM(num):GROUPING SETSquery (verified in-app on Postgres; 25 rows = 22 leaf + 2 subtotals + 1 grand total).TESTING INSTRUCTIONS
SUM(a)/SUM(b)orCOUNT_DISTINCT) with row totals/subtotals enabled; confirm the totals reflect the metric recomputed at each level, not the sum of cells.SUM/COUNT) are unchanged.Unit + integration tests cover the rollup synthesis, GROUPING SETS clause/marker/split helpers (native + SQLite fallback), additivity detection, and the table summary path.
ADDITIONAL INFORMATION