Commit 874dfb1
# Backport
This will backport the following commits from `main` to `9.5`:
- [[Discover] [ES|QL] fix: stats by previous aggregated field
(#290259)](#290259)
<!--- Backport version: 9.6.6 -->
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)
<!--BACKPORT [{"author":{"name":"Sebastian Delle
Donne","email":"sebastian.delledonne@elastic.co"},"sourceCommit":{"committedDate":"2026-09-10T11:59:28Z","message":"[Discover]
[ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes
https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an
unhandled `TypeError: undefined is not an object
(evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta`
(used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when
a query has\ntwo `STATS` commands and the second groups `BY` a field
that the first\n`STATS` declared as an **aggregate** alias rather than a
`BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM
kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY
x\n```\n\n### Solution\n`x` should be treated as a regular column, the
code was incorrectly\nbranching into a special case as `x` was defined
in the previous `STATS`\ncommand (expecting to be found as new group
definition).\nAlso added a catch to avoid buggy UI when analysing the
query fails,\n(discover was held in a permanent loading state before the
fix)\n\n#### Before\n<img width=\"1724\" height=\"945\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n####
After\n<img width=\"1723\" height=\"902\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n###
Checklist\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c","branchLabelMapping":{"^v9.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","Team:ESQL","backport:version","v9.6.0","v9.5.5"],"title":"[Discover]
[ES|QL] fix: stats by previous aggregated
field","number":290259,"url":"https://github.com/elastic/kibana/pull/290259","mergeCommit":{"message":"[Discover]
[ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes
https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an
unhandled `TypeError: undefined is not an object
(evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta`
(used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when
a query has\ntwo `STATS` commands and the second groups `BY` a field
that the first\n`STATS` declared as an **aggregate** alias rather than a
`BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM
kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY
x\n```\n\n### Solution\n`x` should be treated as a regular column, the
code was incorrectly\nbranching into a special case as `x` was defined
in the previous `STATS`\ncommand (expecting to be found as new group
definition).\nAlso added a catch to avoid buggy UI when analysing the
query fails,\n(discover was held in a permanent loading state before the
fix)\n\n#### Before\n<img width=\"1724\" height=\"945\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n####
After\n<img width=\"1723\" height=\"902\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n###
Checklist\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c"}},"sourceBranch":"main","suggestedTargetBranches":["9.5"],"targetPullRequestStates":[{"branch":"main","label":"v9.6.0","branchLabelMappingKey":"^v9.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/290259","number":290259,"mergeCommit":{"message":"[Discover]
[ES|QL] fix: stats by previous aggregated field (#290259)\n\n- Closes
https://github.com/elastic/kibana/issues/290060\n## Summary\n\nFixes an
unhandled `TypeError: undefined is not an object
(evaluating\n'groupFieldNode.arg')` thrown by `getESQLStatsQueryMeta`
(used by\nDiscover's ES|QL \"cascade documents\" breakdown feature) when
a query has\ntwo `STATS` commands and the second groups `BY` a field
that the first\n`STATS` declared as an **aggregate** alias rather than a
`BY`-grouping\nalias.\n\n### Repro\n\n```esql\nFROM
kibana_sample_data_logs\n| STATS x = MAX(bytes)\n| STATS c = COUNT(*) BY
x\n```\n\n### Solution\n`x` should be treated as a regular column, the
code was incorrectly\nbranching into a special case as `x` was defined
in the previous `STATS`\ncommand (expecting to be found as new group
definition).\nAlso added a catch to avoid buggy UI when analysing the
query fails,\n(discover was held in a permanent loading state before the
fix)\n\n#### Before\n<img width=\"1724\" height=\"945\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/17ba47a5-84f3-48fc-b09f-bb6263d1ae07\"\n/>\n\n####
After\n<img width=\"1723\" height=\"902\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/c137f927-01e3-4705-8d0d-ad50663f08e0\"\n/>\n\n\n\n###
Checklist\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios","sha":"d5e1a4e37970834570aaa52d0488081ded16123c"}},{"branch":"9.5","label":"v9.5.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
Co-authored-by: Sebastian Delle Donne <sebastian.delledonne@elastic.co>
1 parent ac235c9 commit 874dfb1
2 files changed
Lines changed: 134 additions & 15 deletions
File tree
Lines changed: 77 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
152 | 186 | | |
153 | 187 | | |
154 | 188 | | |
| |||
367 | 401 | | |
368 | 402 | | |
369 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
370 | 431 | | |
371 | 432 | | |
372 | 433 | | |
| |||
916 | 977 | | |
917 | 978 | | |
918 | 979 | | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
919 | 996 | | |
920 | 997 | | |
921 | 998 | | |
| |||
Lines changed: 57 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
96 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
97 | 118 | | |
98 | 119 | | |
99 | 120 | | |
| |||
163 | 184 | | |
164 | 185 | | |
165 | 186 | | |
166 | | - | |
167 | | - | |
168 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
169 | 198 | | |
170 | 199 | | |
171 | 200 | | |
| |||
350 | 379 | | |
351 | 380 | | |
352 | 381 | | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
359 | 393 | | |
360 | 394 | | |
361 | 395 | | |
| |||
708 | 742 | | |
709 | 743 | | |
710 | 744 | | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
717 | 759 | | |
718 | 760 | | |
719 | 761 | | |
| |||
0 commit comments