Skip to content

fix(pivot-table): Rename 'Subtotal' to 'Subvalue' with aggregation fu…#40513

Open
divyeshreddy02 wants to merge 4 commits into
apache:masterfrom
divyeshreddy02:fix/rename-subtotal-to-subvalue
Open

fix(pivot-table): Rename 'Subtotal' to 'Subvalue' with aggregation fu…#40513
divyeshreddy02 wants to merge 4 commits into
apache:masterfrom
divyeshreddy02:fix/rename-subtotal-to-subvalue

Conversation

@divyeshreddy02
Copy link
Copy Markdown

…nction

The Pivot Table visualization previously used 'Subtotal' as a label for subgroup aggregations regardless of which aggregation function was used (e.g., Sum, Average, Max). This was confusing because 'Subtotal' implies a specific 'Sum' operation.

This change:

  • Renames 'Subtotal' to 'Subvalue (%(aggfunc)s)'
  • Includes the actual aggregation function name (Sum, Average, etc.)
  • Makes the label consistent with 'Total (Sum)' at the top level

Fixes #35089

SUMMARY

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

…nction

The Pivot Table visualization previously used 'Subtotal' as a label for
subgroup aggregations regardless of which aggregation function was used
(e.g., Sum, Average, Max). This was confusing because 'Subtotal' implies
a specific 'Sum' operation.

This change:
- Renames 'Subtotal' to 'Subvalue (%(aggfunc)s)'
- Includes the actual aggregation function name (Sum, Average, etc.)
- Makes the label consistent with 'Total (Sum)' at the top level

Fixes apache#35089
@dosubot dosubot Bot added the viz:charts:pivot Related to the Pivot Table charts label May 29, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 29, 2026

Code Review Agent Run #878742

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/charts/test_client_processing.py - 2
  • superset/charts/client_processing.py - 2
Review Details
  • Files reviewed - 2 · Commit Range: f07d7ad..f07d7ad
    • superset/charts/client_processing.py
    • tests/unit_tests/charts/test_client_processing.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions
Copy link
Copy Markdown
Contributor

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

Please read our New Contributor Welcome & Expectations guide.

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

subtotal = pivot_v2_aggfunc_map[aggfunc](df.iloc[:, slice_], axis=1)
depth = df.columns.nlevels - len(subgroup) - 1
total = metric_name if level == 0 else __("Subtotal")
total = metric_name if level == 0 else __("Subvalue (%(aggfunc)s)", aggfunc=aggfunc)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This new subtotal label diverges from the frontend pivot-table renderer, which still renders subgroup headers as Subtotal. Since this module is meant to reproduce client-side processing for reports, changing only the backend label creates a contract mismatch (Explore UI vs CSV/JSON/report output labels differ). Keep both sides aligned by updating the frontend subtotal label logic in the same change or using the same label here. [api mismatch]

Severity Level: Major ⚠️
- ⚠️ Pivot table CSV subtotals differ from Explore UI.
- ⚠️ Scheduled pivot_table_v2 reports show renamed subtotal labels.
- ⚠️ Downstream tooling relying on UI labels may misalign.
Steps of Reproduction ✅
1. Note that `superset/charts/client_processing.py:18-25` documents this module as
reproducing client-side post-processing so that reports show the same data as Explore
(pivot table UI).

2. On the frontend, `pivot_table_v2` uses the pivot-table plugin wired via
`transformProps` at
`superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts:98-120`
and `PivotTableChart` (see plugin wiring); it passes subtotal controls
(`rowSubtotalPosition`, `colSubtotalPosition`, etc.) but does not receive or override the
backend subtotal label, so the UI continues to use the pivot library's built‑in subtotal
labeling (currently "Subtotal").

3. For reports/exports, the backend entrypoint `apply_client_processing()` at
`superset/charts/client_processing.py:13-27` routes `viz_type == "pivot_table_v2"` through
`pivot_table_v2()`, which in turn calls `pivot_df()` with
`aggfunc=form_data["aggregateFunction"]` to recompute the pivot for CSV/JSON (see tests
`test_apply_client_processing_json_format` and `test_apply_client_processing_csv_format`
at `tests/unit_tests/charts/test_client_processing.py:1193-1379`).

4. Inside `pivot_df()`, subtotals are now labeled with `__("Subvalue (%(aggfunc)s)",
aggfunc=aggfunc)` for non-top levels (`superset/charts/client_processing.py:77` for
`metric_name` and lines `119` and `26` for `total`), so for `aggfunc="Sum"` the exported
CSV/JSON indices contain "Subvalue (Sum)" while the Explore UI subtotal headers remain
"Subtotal"; this breaks the intended parity between Explore and exported reports for
subtotal labels.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/charts/client_processing.py
**Line:** 178:178
**Comment:**
	*Api Mismatch: This new subtotal label diverges from the frontend pivot-table renderer, which still renders subgroup headers as `Subtotal`. Since this module is meant to reproduce client-side processing for reports, changing only the backend label creates a contract mismatch (Explore UI vs CSV/JSON/report output labels differ). Keep both sides aligned by updating the frontend subtotal label logic in the same change or using the same label here.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +374 to +377
| ('SUM(num)', 'Subvalue') | 165188 |
| ('MAX(num)', 'boy') | 1280 |
| ('MAX(num)', 'girl') | 2588 |
| ('MAX(num)', 'Subtotal') | 3868 |
| ('MAX(num)', 'Subvalue') | 3868 |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The updated expectations still assert plain Subvalue, but the new implementation now generates Subvalue (<aggfunc>) (for example, Subvalue (Sum)). These snapshots will fail against the new behavior and make the test suite unreliable; update expected markdown labels to include the aggregation suffix consistently. [logic error]

Severity Level: Critical 🚨
- ❌ Pivot table backend unit tests fail on subtotal expectations.
- ❌ CI for charts client_processing module will be red.
- ⚠️ Future regressions in subtotal labeling harder to detect.
Steps of Reproduction ✅
1. Run the unit test `test_pivot_df_single_row_two_metrics` defined at
`tests/unit_tests/charts/test_client_processing.py:361-381`, which builds a small
DataFrame and calls `pivot_df(...)` with `aggfunc="Sum"`, `show_rows_total=True`,
`show_columns_total=True`, and `apply_metrics_on_rows=True`.

2. The test asserts on `pivoted.to_markdown()` including subtotal rows labeled
`('SUM(num)', 'Subvalue')` and `('MAX(num)', 'Subvalue')` (lines 373-378), i.e. without
any aggregation suffix.

3. At runtime, `pivot_df()` in `superset/charts/client_processing.py` now computes
`metric_name = __("Total (%(aggfunc)s)", aggfunc=aggfunc)` at line 77 and uses `total =
metric_name if level == 0 else __("Subvalue (%(aggfunc)s)", aggfunc=aggfunc)` when
inserting subtotal columns/rows at lines 119 and 26, so with `aggfunc="Sum"` the subtotal
label becomes `"Subvalue (Sum)"`, not `"Subvalue"`.

4. As a result, the MultiIndex entries emitted by `pivot_df()` for the subtotal rows
contain `"Subvalue (Sum)"`, making the `to_markdown()` output diverge from the hard-coded
expectations in `test_pivot_df_single_row_two_metrics`, causing this and other similar
tests (e.g., expectations at `tests/unit_tests/charts/test_client_processing.py:402-405`,
`543-546`, `571-574`, `1075-1085`, etc.) to fail consistently until the snapshots are
updated to include the aggregation suffix.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/charts/test_client_processing.py
**Line:** 374:377
**Comment:**
	*Logic Error: The updated expectations still assert plain `Subvalue`, but the new implementation now generates `Subvalue (<aggfunc>)` (for example, `Subvalue (Sum)`). These snapshots will fail against the new behavior and make the test suite unreliable; update expected markdown labels to include the aggregation suffix consistently.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Align the frontend pivot table subtotal label with the backend change.
Previously the backend said 'Subvalue (Sum)' while the UI said 'Subtotal'.

This change:
- Updates TableRenderers.tsx to use 'Subvalue (%(aggregatorName)s)' format
- Adds the python-format marker to the translation file
- Makes frontend consistent with backend and 'Total' labels

Fixes PR apache#40513 review feedback
@github-actions github-actions Bot added i18n Namespace | Anything related to localization plugins labels May 29, 2026
…query

The streaming CSV export path was executing raw SQL without running it
through mutate_sql_based_on_config(). This caused:

1. Trino exports to fail on SQL with trailing semicolons
   (Trino rejects 'LIMIT N;' but accepts 'LIMIT N')

The fix calls merged_database.mutate_sql_based_on_config(sql) before
executing the query, ensuring SQL transformations are applied.

This fixes Bug 1 of issue apache#40465.

Bug 2 (user impersonation) will be addressed separately.
The streaming CSV export generator runs in a new Flask app context,
but g.user was not being properly restored. This caused user
impersonation to fail - all exports ran as the service account
instead of the actual user.

Changes:
1. Modified preserve_g_context() to accept an optional user parameter
2. Capture g.user separately before creating the generator
   (g.user may not serialize properly via __dict__.copy())
3. Explicitly set g.user when restoring context

This ensures get_username() returns the correct user, enabling:
- Proper X-Trino-User header forwarding
- Correct resource group routing
- Accurate audit trails

This fixes Bug 2 of issue apache#40465.
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 29, 2026

Code Review Agent Run #79cf6f

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/commands/streaming_export/base.py - 1
    • Redundant user restoration · Line 41-57
      `captured_g` (line 230) is created via `g._get_current_object().__dict__.copy()`, which already includes `user`. The loop at lines 53-54 iterates all captured attributes and sets them via `setattr(g, key, value)`, automatically restoring `g.user` before the explicit `if user is not None: g.user = user` block (lines 56-57) runs. This makes the separate user capture (line 233) and parameter (line 41) redundant dead code in the diff.
Review Details
  • Files reviewed - 3 · Commit Range: f07d7ad..ea02f11
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.tsx
    • superset/translations/en/LC_MESSAGES/messages.po
    • superset/commands/streaming_export/base.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n Namespace | Anything related to localization plugins size/M viz:charts:pivot Related to the Pivot Table charts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename "Subtotal" to "Subvalue" in Pivot Tables

1 participant