aminghadersohi opened a new pull request, #44948:
URL: https://github.com/apache/superset/pull/44948
### SUMMARY
`get_dashboard_data` returns only the first few sample rows of each chart,
and `get_chart_data` returns the raw rows. A Big Number chart displays one
headline number derived from its data, so an assistant asked "what is the
total?" could only list sample rows and had no number to report. For example, a
Big Number with trendline over `SUM(ytd_sales)`, weekly grain, aggregation
`sum`, 19 rows: the tool returned ten weekly values and no total.
This adds a typed `headline` object to `ChartData` (`get_chart_data`) and to
each chart in `get_dashboard_data`, set for `big_number` and `big_number_total`
and null for every other chart type. It is computed from the full executed
result set, not the sample rows, with the same logic as the frontend
(`aggregationChoices` in `customControls.tsx`,
`BigNumberWithTrendline/transformProps.ts`, `BigNumberTotal/transformProps.ts`):
- `big_number_total`: the single metric value.
- `big_number`: metric values ordered by time descending, nulls dropped,
then `form_data.aggregation`: `LAST_VALUE` (default) is the latest value;
`sum`, `mean`, `min`, `max`, `median` are that statistic over all values. The
aggregation name lookup is case-insensitive with a `LAST_VALUE` fallback, as in
the frontend. `raw` ("Overall value") is read from the second, un-trended query
layer, and only for the exact string `raw`, which is the only value for which
the frontend adds that layer.
`headline` fields: `value`, `aggregation`, `rows_used`, `reason`. Rather
than return a wrong number, `value` is null with a short `reason` when:
- the fetch hit the row limit (or the source reports more rows than were
returned);
- aggregation is `raw` and no overall-value layer came back;
- a rolling window (`rolling_type`) is configured but the executed query has
no rolling/cumulative step, so the returned rows do not reflect it;
- `LAST_VALUE` is requested but the rows have no usable time values to find
the latest one;
- the result is empty, the metric column is missing, or every value is null.
The query path is unchanged, so permissions, RLS and dashboard filters apply
exactly as they do for the existing chart query. The tool descriptions tell the
model to report `headline.value` rather than derive a number from the rows.
Known difference from the frontend: when the `raw` overall-value query
returns null, the chart falls back to showing the latest trend value; here that
case returns no headline.
`get_chart_data` is included because the headline is computed inside the
shared `execute_chart_data` core, which has the form data and the executed
query, so it fit without extra plumbing.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (MCP tool response change).
### TESTING INSTRUCTIONS
```
pytest tests/unit_tests/mcp_service/chart/test_big_number_headline.py \
tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py \
tests/unit_tests/mcp_service/dashboard/tool/test_get_dashboard_data.py
```
Manually: call `get_dashboard_data` (or `get_chart_data`) on a dashboard
with a Big Number with trendline chart using aggregation `sum`;
`headline.value` should equal the number rendered in the chart, and match the
total of all trend rows, not just the sample rows.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [x] Introduces new feature or API
- [ ] Removes existing feature or API
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]