[9.5] [Discover] [ES|QL] fix: stats by previous aggregated field (#290259) - #290297
Merged
Merged
Conversation
…90259) - Closes elastic#290060 ## Summary Fixes an unhandled `TypeError: undefined is not an object (evaluating 'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta` (used by Discover's ES|QL "cascade documents" breakdown feature) when a query has two `STATS` commands and the second groups `BY` a field that the first `STATS` declared as an **aggregate** alias rather than a `BY`-grouping alias. ### Repro ```esql FROM kibana_sample_data_logs | STATS x = MAX(bytes) | STATS c = COUNT(*) BY x ``` ### Solution `x` should be treated as a regular column, the code was incorrectly branching into a special case as `x` was defined in the previous `STATS` command (expecting to be found as new group definition). Also added a catch to avoid buggy UI when analysing the query fails, (discover was held in a permanent loading state before the fix) #### Before <img width="1724" height="945" alt="image" src="https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07" /> #### After <img width="1723" height="902" alt="image" src="https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0" /> ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit d5e1a4e)
Contributor
Author
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
total optimizer output size
Test Failures
cc @sddonne |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto9.5:Questions ?
Please refer to the Backport tool documentation