Skip to content

[ES|QL] support expressions in STATS#229513

Merged
drewdaemon merged 62 commits intoelastic:mainfrom
drewdaemon:216492/support-expressions-in-stats
Aug 1, 2025
Merged

[ES|QL] support expressions in STATS#229513
drewdaemon merged 62 commits intoelastic:mainfrom
drewdaemon:216492/support-expressions-in-stats

Conversation

@drewdaemon
Copy link
Contributor

@drewdaemon drewdaemon commented Jul 25, 2025

Summary

Adds first-class support for expressions within both aggregation and grouping clauses in STATS.

expressions_in_stats.mov

Part of #216492

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • Reinstate controls suggestions
  • Behavior after single field in grouping clauses
  • Reenable function arg suggestions
  • Ignore previously-used columns in grouping clauses
  • Verify suggestions after complete WHERE
  • Verify nested grouping functions
  • Write tests
offset?: number
): Promise<ISuggestionItem[]> => {
const correctedQuery = correctQuerySyntax(query);
const innerText = query.substring(0, offset ?? query.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This step that is executed in the real autocomplete routine was missed here, causing one of my tests to fail.

}
if (
isNotEnrichClauseAssigment(node, command) &&
(!isOperator(node) || (command.name === 'stats' && !withinStatsWhereClause))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This exception was designed to partially support suggestions after operators using the logic in getFunctionArgsSuggestions. Now, we are using the suggestForExpression function, so no need for this partial support anymore.

@drewdaemon drewdaemon added backport:skip This PR does not require backporting v9.2.0 release_note:enhancement labels Jul 30, 2025
@drewdaemon drewdaemon force-pushed the 216492/support-expressions-in-stats branch from fd45c47 to 62d9f84 Compare July 31, 2025 16:19
@drewdaemon drewdaemon marked this pull request as ready for review July 31, 2025 18:36
@drewdaemon drewdaemon requested a review from a team as a code owner July 31, 2025 18:36
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

LGTM, it works great!

* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { ESQLVariableType } from '@kbn/esql-types';
// import { getInsideFunctionsSuggestions } from '../../../definitions/utils/autocomplete/functions';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// import { getInsideFunctionsSuggestions } from '../../../definitions/utils/autocomplete/functions';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Picked this up in #230276

defaultMessage: 'WHERE operator',
}),
locationsAvailable: [Location.STATS],
ignoreAsSuggestion: true,
Copy link
Contributor

@stratoula stratoula Aug 1, 2025

Choose a reason for hiding this comment

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

Why don't we remove it once and for all and we add the flag instead?

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #47 / discover/group1 discover histogram should reset all histogram state when resetting the saved search

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
onechat 597.3KB 597.4KB +22.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.8MB 3.8MB +1.1KB

History

@drewdaemon drewdaemon merged commit fd9c1be into elastic:main Aug 1, 2025
12 checks passed
szaffarano pushed a commit to szaffarano/kibana that referenced this pull request Aug 5, 2025
## Summary

Adds first-class support for expressions within both aggregation and
grouping clauses in `STATS`.




https://github.com/user-attachments/assets/a435410f-9176-47d5-9ca2-412a2438e197



Part of elastic#216492

### 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
- [x] Reinstate controls suggestions
- [x] Behavior after single field in grouping clauses
- [x] Reenable function arg suggestions
- [x] Ignore previously-used columns in grouping clauses
- [x] Verify suggestions after complete WHERE
- [x] Verify nested grouping functions
- [x] Write tests

---------

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
## Summary

Adds first-class support for expressions within both aggregation and
grouping clauses in `STATS`.




https://github.com/user-attachments/assets/a435410f-9176-47d5-9ca2-412a2438e197



Part of elastic#216492

### 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
- [x] Reinstate controls suggestions
- [x] Behavior after single field in grouping clauses
- [x] Reenable function arg suggestions
- [x] Ignore previously-used columns in grouping clauses
- [x] Verify suggestions after complete WHERE
- [x] Verify nested grouping functions
- [x] Write tests

---------

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
@drewdaemon drewdaemon deleted the 216492/support-expressions-in-stats branch August 8, 2025 22:09
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
## Summary

Adds first-class support for expressions within both aggregation and
grouping clauses in `STATS`.




https://github.com/user-attachments/assets/a435410f-9176-47d5-9ca2-412a2438e197



Part of elastic#216492

### 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
- [x] Reinstate controls suggestions
- [x] Behavior after single field in grouping clauses
- [x] Reenable function arg suggestions
- [x] Ignore previously-used columns in grouping clauses
- [x] Verify suggestions after complete WHERE
- [x] Verify nested grouping functions
- [x] Write tests

---------

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v9.2.0

3 participants