Skip to content

fix(explore): exclude time-comparison derived columns from stacked Only Total (Closes #43068) - #43071

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/superset-43068-stacked-only-total-exclude-derived
Open

fix(explore): exclude time-comparison derived columns from stacked Only Total (Closes #43068)#43071
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/superset-43068-stacked-only-total-exclude-derived

Conversation

@waterWang

Copy link
Copy Markdown

Summary

#42881 fixed the stacked "Only Total" label so it no longer includes a sort-only metric. It handles the plain and verbose-named cases, but the exclusion is an exact-name match, so time-comparison derived columns of that same sort-only metric are still summed into the total.

Before

extractDataTotalValues creates excludedKeys with the sort-only metric labels, but a time-comparison derived column like SortMetric__1 year ago does not match SortMetric exactly, so it passes through and inflates the stacked total.

After

Check if a column key starts with any excluded key followed by the TIME_COMPARISON_SEPARATOR (__). This ensures that SortMetric__1 year ago, SortMetric__2 years ago, etc. are also excluded from the stacked total.

Impact

  • Fix: Stacked "Only Total" on time-comparison charts with a sort-only metric no longer includes the sort-only metric's derived columns
  • Scope: superset-frontend/plugins/plugin-chart-echarts/src/utils/series.tsextractDataTotalValues function
  • No regression: The original exact-match exclusion is preserved; the derived-column check is an additional guard

Closes #43068

@dosubot dosubot Bot added explore Namespace | Anything related to Explore viz:charts:echarts Related to Echarts labels Aug 11, 2026
@bito-code-review

bito-code-review Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #99a70c

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - 1
    • Missing test for time-comparison exclusion · Line 412-415
      The new time-comparison column exclusion logic lacks test coverage. Consider adding a test similar to existing tests that validates both the base metric and its time-comparison derived columns are properly excluded from totalStackedValues calculations.
Review Details
  • Files reviewed - 1 · Commit Range: eb671dc..eb671dc
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ 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

Comment on lines +413 to +415
if (Array.from(excludedKeys).some(key => curr !== key && curr.startsWith(key + TIME_COMPARISON_SEPARATOR))) {
return prev;
}

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 prefix check assumes every key beginning with an excluded key and __ is a time-comparison column, but the suffix is never validated against configured time offsets. This can exclude legitimate metrics or columns such as Sort__detail when Sort is a sort-only metric, causing those values to disappear from stacked totals. Restrict the match to known time-comparison-derived keys or pass the configured offsets into this function. [logic error]

Severity Level: Major ⚠️
- ⚠️ Legitimate aliased metrics can disappear from stacked totals.

Fix in Cursor Fix in VSCode Claude

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

**Path:** superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
**Line:** 413:415
**Comment:**
	*Logic Error: The prefix check assumes every key beginning with an excluded key and `__` is a time-comparison column, but the suffix is never validated against configured time offsets. This can exclude legitimate metrics or columns such as `Sort__detail` when `Sort` is a sort-only metric, causing those values to disappear from stacked totals. Restrict the match to known time-comparison-derived keys or pass the configured offsets into this function.

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
👍 | 👎

@bito-code-review

Copy link
Copy Markdown
Contributor

The flagged issue is correct. The current implementation uses a broad prefix check that incorrectly excludes any column starting with an excluded key followed by the separator, which can lead to the accidental exclusion of legitimate metrics like Sort__detail.

To resolve this, you should validate that the suffix following the separator is actually a recognized time-comparison offset. If you do not have access to the configured offsets in this function, you should pass them as an argument.

Here is a concise implementation of the fix:

// Update the exclusion check to validate the suffix
if (Array.from(excludedKeys).some(key => 
  curr !== key && 
  curr.startsWith(key + TIME_COMPARISON_SEPARATOR) &&
  isTimeComparisonOffset(curr.slice((key + TIME_COMPARISON_SEPARATOR).length)) // Add this validation
)) {
  return prev;
}

I have checked the available review comments, and there are no other comments on this PR. Would you like me to proceed with any other adjustments?

superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts

// Exclude time-comparison derived columns of excluded keys (e.g. SortMetric__1 year ago)
        if (Array.from(excludedKeys).some(key => 
          curr !== key && 
          curr.startsWith(key + TIME_COMPARISON_SEPARATOR) &&
          isTimeComparisonOffset(curr.slice((key + TIME_COMPARISON_SEPARATOR).length))
        )) {
          return prev;
        }

@rusackas
rusackas requested review from eschutho and a lite review from Copilot August 11, 2026 19:59

Copilot AI left a comment

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.

Pull request overview

Fixes an Explore stacked “Only Total” inflation bug for time-comparison charts by ensuring extractDataTotalValues excludes time-offset (“derived”) columns belonging to sort-only metrics (e.g. SortMetric__1 year ago) in the ECharts timeseries plugin utilities.

Changes:

  • Import TIME_COMPARISON_SEPARATOR to detect time-comparison derived column keys.
  • Extend extractDataTotalValues exclusion logic to skip keys that begin with an excluded metric label plus the time-comparison separator.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +412 to +414
// Exclude time-comparison derived columns of excluded keys (e.g. SortMetric__1 year ago)
if (Array.from(excludedKeys).some(key => curr !== key && curr.startsWith(key + TIME_COMPARISON_SEPARATOR))) {
return prev;
import { SupersetTheme } from '@apache-superset/core/theme';
import { GenericDataType } from '@apache-superset/core/common';
import { SortSeriesType, LegendPaddingType } from '@superset-ui/chart-controls';
import { SortSeriesType, LegendPaddingType, TIME_COMPARISON_SEPARATOR } from '@superset-ui/chart-controls';
Comment on lines +412 to +414
// Exclude time-comparison derived columns of excluded keys (e.g. SortMetric__1 year ago)
if (Array.from(excludedKeys).some(key => curr !== key && curr.startsWith(key + TIME_COMPARISON_SEPARATOR))) {
return prev;
@rusackas
rusackas self-requested a review August 11, 2026 20:07
@rusackas

Copy link
Copy Markdown
Member

Thanks for taking this on, @waterWang! Couple of things before this is ready.

CI's failing on oxfmt formatting in series.ts, worth running pre-commit run --all-files and pushing the reformatted file.

Also, this could use a test covering the SortMetric__1 year ago exclusion. The issue mentioned tests coming along with the fix and none landed here.

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

Labels

explore Namespace | Anything related to Explore plugins size/XS viz:charts:echarts Related to Echarts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stacked "Only Total" still includes the sort-only metric on time-comparison charts (follow-up to #42881)

3 participants