Skip to content

fix: classify numeric columns as aggregation in readAsScalar#11471

Open
krsoninikhil wants to merge 1 commit into
mainfrom
ns/pie-chart
Open

fix: classify numeric columns as aggregation in readAsScalar#11471
krsoninikhil wants to merge 1 commit into
mainfrom
ns/pie-chart

Conversation

@krsoninikhil

Copy link
Copy Markdown
Member

Pull Request


📄 Summary

readAsScalar only recognised columns named __result_N as aggregations. Any other name — including user-defined aliases like count() AS total_requests — defaulted to columnType: "group". The frontend uses this field to split columns into labels vs values for pie charts and scalar panels, so custom aliases caused charts to show "No Data".

The fix mirrors the fallback logic already present in readAsTimeSeries: if a column doesn't match an explicit marker (__result_N or a legacy alias like result/value), infer aggregation intent from the DB column's numeric type.

Issues closed by this PR

Closes #8844


✅ Change Type

  • 🐛 Bug fix

🐛 Bug Context

Root Cause

readAsScalar classified columns purely by name regex (^__result_(\d+)$). readAsTimeSeries had a fuller fallback chain (single numeric column, legacy aliases) but readAsScalar never received the same treatment.

Fix Strategy

Add two fallback conditions to readAsScalar, in priority order:

  1. Name in legacyReservedColumnTargetAliases (result, value, res, …) → aggregation
  2. Column has a numeric DB type → aggregation

Explicit __result_N markers still take priority, so all existing queries are unaffected.


🧪 Testing Strategy

  • Manual verification: pie chart with count() AS total_requests now renders correctly; count() AS __result_0 continues to work.
  • Edge cases covered: mixed query (__result_0 + custom alias), legacy aliases, string-only group columns.

⚠️ Risk & Impact Assessment

  • Blast radius: readAsScalar only — time-series and raw query paths are untouched.
  • Potential regressions: queries that intentionally used a numeric column as a group dimension will now be classified as aggregation. This is an edge case unlikely in practice (scalar queries for pie/table panels).
  • Rollback plan: revert the 5-line addition to consume.go.

📝 Changelog

Field Value
Deployment Type Cloud / OSS / Enterprise
Change Type Bug Fix
Description Pie charts and scalar panels now render correctly when ClickHouse queries use custom aggregation column aliases.

📋 Checklist

  • Tests added or explicitly not required
  • Manually tested
  • Breaking changes documented
  • Backward compatibility considered

👀 Notes for Reviewers

The change is 5 lines in readAsScalar. The key insight: readAsTimeSeries already had this fallback logic but readAsScalar never did. The fix brings them in line with each other.


Pie charts and scalar panels break when ClickHouse queries use custom
aggregation aliases (e.g. `count() AS total_requests`) because
readAsScalar only recognised __result_N pattern columns as aggregations,
returning columnType "group" for everything else.

Apply the same fallback logic already used in readAsTimeSeries: if a
column doesn't match an explicit marker (__result_N or a legacy alias),
infer aggregation from numeric DB type.

Closes #8844

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the bug Something isn't working label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Pie Chart with ClickHouse Query only works if aggregation alias is __result_[n]

1 participant