Skip to content

Conversation

@niladrix719
Copy link
Contributor

@niladrix719 niladrix719 commented Oct 10, 2025

📄 Summary

Modified the formula evaluation logic in formula.go to normalize query names to uppercase during parsing and use case-insensitive matching when looking up time series data, allowing formulas like A/B, a/b, A/b, and a/B to produce same results


✅ Changes

  • Feature: Brief description
  • Bug fix: Brief description

🏷️ Required: Add Relevant Labels

⚠️ Manually add appropriate labels in the PR sidebar
Please select one or more labels (as applicable):

ex:

  • backend

👥 Reviewers

Tag the relevant teams for review:

  • frontend / backend / devops

🧪 How to Test

  1. go to Dashboards
  2. add time series panel
  3. create matrices & formula
  4. test with different case queries

🔍 Related Issues

Closes #9216


📸 Screenshots / Screen Recording (if applicable / mandatory for UI related changes)

Screen.Recording.2025-10-10.at.8.49.24.AM.mov

📋 Checklist

  • Dev Review
  • Test cases added (Unit/ Integration / E2E)
  • Manually tested the changes

👀 Notes for Reviewers


Note

Normalize query names for formulas to be case-insensitive (variables, lookups, and defaults), plus tests validating mixed-case usage.

  • Backend – pkg/types/querybuildertypes/querybuildertypesv5/formula.go:
    • Normalize query/variable names to uppercase in parseAggregationReference and when building lookup maps for EvaluateFormula to enable case-insensitive matching between expressions and timeSeriesData keys.
    • Normalize canDefaultZero keys to include original, upper, and lower cases for consistent access.
  • Tests – pkg/types/querybuildertypes/querybuildertypesv5/formula_test.go:
    • Add TestCaseInsensitiveQueryNames covering mixed/mismatched case across expressions and data keys.

Written by Cursor Bugbot for commit 2b06446. This will update automatically on new commits. Configure here.

@srikanthccv srikanthccv added the safe-to-test Run CI tests for dependabot and external contributors label Oct 10, 2025
Signed-off-by: “niladrix719” <[email protected]>
@primus-bot primus-bot bot removed the safe-to-test Run CI tests for dependabot and external contributors label Oct 11, 2025
@srikanthccv srikanthccv added safe-to-test Run CI tests for dependabot and external contributors safe-to-integrate Run integration tests labels Nov 7, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bug: Case-Insensitive Key Mismatch in Default-To-Zero Lookup

The canDefaultZero lookup uses the original variable case from the expression (e.g., "a"), but canDefaultZero is keyed by query names from the spec (e.g., "A"). When formulas use lowercase variables like "a / b" but queries are named "A" and "B", the lookup fe.canDefaultZero[variable] fails, breaking default-to-zero behavior. The canDefaultZero map keys need normalization to uppercase to match the case-insensitive query name handling.

pkg/types/querybuildertypes/querybuildertypesv5/formula.go#L502-L503

for _, variable := range fe.variables {
if _, exists := values[variable]; !exists && fe.canDefaultZero[variable] {

Fix in Cursor Fix in Web


@srikanthccv
Copy link
Member

@niladrix719 check the above ^

@primus-bot primus-bot bot removed the safe-to-test Run CI tests for dependabot and external contributors label Nov 20, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

normalizedCanDefaultZero[k] = v
normalizedCanDefaultZero[strings.ToUpper(k)] = v
normalizedCanDefaultZero[strings.ToLower(k)] = v
}
Copy link

Choose a reason for hiding this comment

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

Bug: Non-deterministic behavior with conflicting case-sensitive keys

The normalization logic creates non-deterministic behavior when canDefaultZero contains the same key in different cases with conflicting values (e.g., {"A": true, "a": false}). Since Go map iteration order is random, the final normalized values become unpredictable as later iterations overwrite earlier ones. This causes inconsistent formula evaluation results across runs when conflicting case-sensitive keys exist in the input.

Fix in Cursor Fix in Web

normalizedSeriesMap := make(map[string]*TimeSeriesData, len(timeSeriesData))
for name, ts := range timeSeriesData {
normalizedSeriesMap[strings.ToUpper(name)] = ts
}
Copy link

Choose a reason for hiding this comment

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

Bug: Non-deterministic data loss with case-conflicting time series keys

The normalization logic causes data loss when timeSeriesData contains multiple keys differing only in case (e.g., {"a": data1, "A": data2}). Since Go map iteration order is random, which time series data survives the uppercase normalization is non-deterministic. This leads to unpredictable formula evaluation results when case-conflicting query names exist in the input data, potentially using the wrong time series for calculations.

Fix in Cursor Fix in Web

@srikanthccv srikanthccv added the safe-to-test Run CI tests for dependabot and external contributors label Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs not required safe-to-integrate Run integration tests safe-to-test Run CI tests for dependabot and external contributors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Case-insensitve query names in formula

2 participants