Skip to content

[ES|QL] Autocomplete for STATS...WHERE#216379

Merged
drewdaemon merged 32 commits intoelastic:mainfrom
drewdaemon:expressions-in-moar-places
Apr 2, 2025
Merged

[ES|QL] Autocomplete for STATS...WHERE#216379
drewdaemon merged 32 commits intoelastic:mainfrom
drewdaemon:expressions-in-moar-places

Conversation

@drewdaemon
Copy link
Contributor

@drewdaemon drewdaemon commented Mar 28, 2025

Summary

Resolve #209359

(No match operator or full-text search functions)

Checklist

@drewdaemon drewdaemon added release_note:enhancement Feature:ES|QL ES|QL related features in Kibana labels Apr 1, 2025
@drewdaemon drewdaemon added Team:ESQL ES|QL related features in Kibana t// v9.1.0 v8.19.0 labels Apr 1, 2025
@drewdaemon drewdaemon marked this pull request as ready for review April 1, 2025 03:42
@drewdaemon drewdaemon requested a review from a team as a code owner April 1, 2025 03:42
@elasticmachine
Copy link
Contributor

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

@stratoula stratoula added the backport:version Backport to applied version labels label Apr 1, 2025
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.

This looks really nice indeed! I have some comments and a bug:

When I do something like
image

I get an error in the console and I dont have suggestions either (I am selecting the comma from the dropdown)
image

/**
* @todo re-enable when expression autocomplete is officially supported for STATS ... BY
*/
// await assertSuggestions('from a | stats avg(b) by integerField % /', [
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these tests are commented out? Our changes should not affect them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we detected an operator in STATS we were sending the code to getFunctionArgsSuggestions which worked in this case. So it was kind of a half-hearted attempt to support expressions in the STATS <here>.

I removed that logic from getAstContext because it was sending us to the wrong place in the STATS ... WHERE <here>.

At the time, I was thinking I would add first-class expressions support for this case too, but that is for later in #216492.

I should be able to adjust the getAstContext logic to restore the original behavior without ruining the work done for STATS... WHERE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restored in 40ada59

test('suggests `??function` option', async () => {
const { suggest } = await setup();

test('suggests `?function` option', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change the test here? It should suggest ??function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't... maybe a merge thing. Will clean it up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test('suggests `??field` option', async () => {
const { suggest } = await setup();

test('suggests `?field` option', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Suggested change
test('suggests `?field` option', async () => {
test('suggests `??field` option', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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


/**
* Encapsulates handling of the "is null" and "is not null"
* checks...
Copy link
Contributor

Choose a reason for hiding this comment

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

Something missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. That's all I have to say 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I can expand a bit)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 866a5e4

// command ... "<here>"
return { type: 'value' as const, command, node, option, containingFunction };
}
// /**
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

leftover, will remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 866a5e4

@drewdaemon
Copy link
Contributor Author

drewdaemon commented Apr 1, 2025

Some observations about the bug

  • It's reproducible on main... just copy FROM kibana_sample_data_logs | STATS count = COUNT(*) /* you can group by a field using the BY operator */ WHERE extension.keyword != "" and type ,
  • It only happens when there's a comment
  • The error is happening within the AST building... I've traced it to this line

I'll dig a bit more. If the fix is simple, I can pull it into this PR.

@drewdaemon
Copy link
Contributor Author

Looks like we get an undefined node with this particular query, so the code is trying to attach the comment to an undefined AST node.
Screenshot 2025-04-01 at 11 25 16 AM

@drewdaemon
Copy link
Contributor Author

Fixed in f03e5b6

@drewdaemon drewdaemon requested a review from stratoula April 1, 2025 17:47
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.

Awesome, thanx for fixing the bug in this PR too 🙌

@drewdaemon drewdaemon enabled auto-merge (squash) April 2, 2025 14:54
@elasticmachine
Copy link
Contributor

elasticmachine commented Apr 2, 2025

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #2 / autocomplete.suggest STATS [ BY ] ... ... ...WHERE expression... Parity with WHERE command matches WHERE suggestions after a boolean expression
  • [job] [logs] Jest Tests #2 / autocomplete.suggest STATS [ BY ] ... ... ...WHERE expression... Parity with WHERE command matches WHERE suggestions after a boolean expression
  • [job] [logs] Jest Tests #2 / autocomplete.suggest STATS [ BY ] ... ... ...WHERE expression... Parity with WHERE command matches WHERE suggestions after a keyword expression
  • [job] [logs] Jest Tests #2 / autocomplete.suggest STATS [ BY ] ... ... ...WHERE expression... Parity with WHERE command matches WHERE suggestions after a keyword expression

Metrics [docs]

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.6MB 3.6MB +935.0B

History

@drewdaemon drewdaemon merged commit 2fda88c into elastic:main Apr 2, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14228097110

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 2, 2025
## Summary

Resolve elastic#209359

(No match operator or full-text search functions)

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [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 2fda88c)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 3, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Autocomplete for `STATS...WHERE`
(#216379)](#216379)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Drew
Tate","email":"drew.tate@elastic.co"},"sourceCommit":{"committedDate":"2025-04-02T19:37:49Z","message":"[ES|QL]
Autocomplete for `STATS...WHERE` (#216379)\n\n## Summary\n\nResolve
https://github.com/elastic/kibana/issues/209359\n\n(No match operator or
full-text search functions)\n\n### Checklist\n\n- [x] Any text added
follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\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":"2fda88c1660336baca61bec8a582a7f399b9d0ea","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Feature:ES|QL","Team:ESQL","backport:version","v9.1.0","v8.19.0"],"title":"[ES|QL]
Autocomplete for
`STATS...WHERE`","number":216379,"url":"https://github.com/elastic/kibana/pull/216379","mergeCommit":{"message":"[ES|QL]
Autocomplete for `STATS...WHERE` (#216379)\n\n## Summary\n\nResolve
https://github.com/elastic/kibana/issues/209359\n\n(No match operator or
full-text search functions)\n\n### Checklist\n\n- [x] Any text added
follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\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":"2fda88c1660336baca61bec8a582a7f399b9d0ea"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216379","number":216379,"mergeCommit":{"message":"[ES|QL]
Autocomplete for `STATS...WHERE` (#216379)\n\n## Summary\n\nResolve
https://github.com/elastic/kibana/issues/209359\n\n(No match operator or
full-text search functions)\n\n### Checklist\n\n- [x] Any text added
follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\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":"2fda88c1660336baca61bec8a582a7f399b9d0ea"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Drew Tate <drew.tate@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:ES|QL ES|QL related features in Kibana release_note:enhancement Team:ESQL ES|QL related features in Kibana t// v8.19.0 v9.1.0

4 participants