Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Fix autocomplete with incompatible args #180874

Merged
merged 12 commits into from
Apr 22, 2024
Merged

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Apr 16, 2024

Summary

Fixes #180730

I've improved the autocomplete logic a bit here with the new features from main:

  • the constantOnly check has been pushed down rather than depend on an empty string
  • autosuggestion takes into account the previous argument types now to propose the next one

Checklist

@dej611 dej611 added release_note:fix Feature:ES|QL ES|QL related features in Kibana v8.14.0 Team:ESQL ES|QL related features in Kibana labels Apr 16, 2024
@dej611 dej611 requested a review from a team as a code owner April 16, 2024 08:45
@elasticmachine
Copy link
Contributor

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

@drewdaemon
Copy link
Contributor

Awesome—glad to see this. But, you may have to pull in main because auto_bucket looks quite different now.

@dej611
Copy link
Contributor Author

dej611 commented Apr 16, 2024

Synced with main and improved the logic there with b70e9bf.
Description updated.

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

The original bug is definitely fixed. Many thanks for that.

I'm not so sure on the new suggestions. On the one hand, I like that they are another indicator of the type of the parameter.

On the other hand, I'm concerned they'll be difficult to interpret.

Take these number suggestions here

Screenshot 2024-04-16 at 12 54 33 PM

Does this mean that those are the only acceptable values? That's what the suggestions often mean, including when the user types mv_sort(field, and gets asc and desc.

Why 10, 20, 30? Are these good choices for bucket? What about for other functions in the future?

Screenshot 2024-04-16 at 12 55 01 PM

Or here, where did this date come from? Why is it a good suggestion? Does it matter which of the two I pick?

Given this, I would prefer we scope this PR to the bugfix #180730 so we can get that in for 8.14.

@dej611
Copy link
Contributor Author

dej611 commented Apr 17, 2024

Does this mean that those are the only acceptable values? That's what the suggestions often mean, including when the user types mv_sort(field, and gets asc and desc.

We had a similar logic for limit where we propose only 3 values. I think user understands that the options are not limited for that. Same applies for date math where only the single unit is proposed, rather than any multiple of them.

ASC and DESC are an enum case like chrono_literals.

Or here, where did this date come from? Why is it a good suggestion? Does it matter which of the two I pick?

This is implementing a similar logic as in formula absolute time shift. But here I've limited to the current time rather than propose any possible shift. I can see how this is a bit more opinionated, but while testing it I found it convenient as a quick placeholder rather than typing the full ISO date manually.

@dej611
Copy link
Contributor Author

dej611 commented Apr 17, 2024

The problem with removing the suggestions is that without them it feels the autocomplete is broken as nothing will be then suggested for those argument, as with the fix the constantsOnly is enforced in the suggestion system.

@drewdaemon
Copy link
Contributor

drewdaemon commented Apr 17, 2024

The problem with removing the suggestions is that without them it feels the autocomplete is broken as nothing will be then suggested for those argument, as with the fix the constantsOnly is enforced in the suggestion system.

I see what you mean. We suggest for pretty much everything else, so this is more jarring. But is it the end of the world? The user still has the inline documentation. The validation is still correct.

I'm not saying that constant suggestions are a bad idea. I'm just saying, why not take them as an enhancement request separate from this bugfix that we want in 8.14? That way, we can have time to evaluate the request, and if we decide to add, we can think through the cases and add them with some polish.

I think that there are other solutions to this problem as well. For example, #180528 would also address this, by giving the user a suggestion of the data type, if not the actual values.

But, cc @stratoula for a second opinion.

@dej611
Copy link
Contributor Author

dej611 commented Apr 17, 2024

I think that there are other solutions to this problem as well. For example, #180528 would also address this, by giving the user a suggestion of the data type, if not the actual values.

I've implemented the signature help in the past (another issue here) - it's just 3 lines of code - and it doesn't solve the problem as it's only available for multiline editor (due to #166085 ).

@drewdaemon
Copy link
Contributor

I've implemented the signature help in the past (another issue #166089) - it's just 3 lines of code - and it doesn't solve the problem as it's only available for multiline editor (due to #166085 ).

All decisions can be reversed 🤷

@drewdaemon
Copy link
Contributor

drewdaemon commented Apr 17, 2024

Synced offline and decided with @stratoula and @dej611 to pursue the constant suggestions but to split them out into their own PR. This will allow us the time to discuss the particulars while allowing this bug to be fixed.

@dej611 dej611 added backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) v8.15.0 labels Apr 18, 2024
Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Works great in the browser but I think the tests are passing by accident.

Screenshot 2024-04-18 at 7 48 12 AM

You can see the problem by adding a conditional breakpoint (statement === 'from a | eval st_intersects(field, )') at autocomplete.test.ts:253.

The expected suggestions should be scoped down to either cartesian or geo points but instead we expect everything. The reason the test passes is that it generates no suggestions [].

All the assertions are nested in a for loop on suggestions so it being empty causes no assertions to be run. That makes the test pass.

We should probably

  • update the expected suggestions to be correct
  • figure out why the suggest fn is returning an empty array
  • add an array length assertion so that we don't get any more of these quiet failures

Another kind of strange thing (maybe not related to the PR) is that when I add a second comma, I get a list of everything as a suggestion

Screen.Recording.2024-04-18.at.7.59.05.AM.mov

Comment on lines +1167 to +1171
// @TODO: improve this to inherit the constant flag from the outer function
functions: !shouldBeConstant,
fields: !shouldBeConstant,
variables: variablesExcludingCurrentCommandOnes,
literals: shouldBeConstant,
Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I think it still makes sense to pass it down.

Comment on lines 1156 to 1157
const shouldBeConstant = validSignatures.some(({ params }) => params[argIndex]?.constantOnly);

Copy link
Contributor

Choose a reason for hiding this comment

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

Leftover?

@dej611
Copy link
Contributor Author

dej611 commented Apr 18, 2024

All the assertions are nested in a for loop on suggestions so it being empty causes no assertions to be run. That makes the test pass.

Good catch. Will fix it.

@dej611
Copy link
Contributor Author

dej611 commented Apr 18, 2024

Addressed all issues raised.
I'm not really a fan of the current experience with bucket which leaves the user on its own after the first argument, in particular for the 3rd and 4th arg.

@drewdaemon
Copy link
Contributor

drewdaemon commented Apr 18, 2024

Sorry, I still don't think the test is working correctly... maybe I'm missing something.

The signatures for st_intersects are the following

Screenshot 2024-04-18 at 9 34 02 AM

So, cartesian and geo are never mixed.

If you look at the expected suggestions that are generated for "from a | eval st_intersects(field, )", they include both cartesian and geo, even though the first field has already been populated.

Screenshot 2024-04-18 at 9 30 34 AM

Shouldn't we have just one or the other (geo or cartesian) depending on the type of field?

I'm not really a fan of the current experience with bucket which leaves the user on its own after the first argument, in particular for the 3rd and 4th arg.

Agreed. Are you still planning on adding the new suggestions in another PR?

@dej611
Copy link
Contributor Author

dej611 commented Apr 18, 2024

Shouldn't we have just one or the other (geo or cartesian) depending on the type of field?

The bug is in the test, as the passed field in the from a | eval st_intersects(field, ) doesn't hold any type information, so the existingTypes is always empty. Adding it here is not something quick, so maybe in a followup is best. I think validation testing has already some code to do it that can be borrowed.

Agreed. Are you still planning on adding the new suggestions in another PR?

It depends on the time frame and how much it would be quick to be defined and added.

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Okay, I will fix the test in another PR. Thanks!

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

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 2.9MB 2.9MB +392.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dej611 dej611 merged commit eadc173 into elastic:main Apr 22, 2024
16 checks passed
@dej611 dej611 deleted the fix/180730 branch April 22, 2024 10:35
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 22, 2024
## Summary

Fixes elastic#180730

I've improved the autocomplete logic a bit here with the new features
from `main`:
* the `constantOnly` check has been pushed down rather than depend on an
empty string
* autosuggestion takes into account the previous argument types now to
propose the next one

### 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 eadc173)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.14

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 22, 2024
…1289)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[ES|QL] Fix autocomplete with incompatible args
(#180874)](#180874)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Marco
Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-04-22T10:35:29Z","message":"[ES|QL]
Fix autocomplete with incompatible args (#180874)\n\n##
Summary\r\n\r\nFixes #180730\r\n\r\nI've improved the autocomplete logic
a bit here with the new features\r\nfrom `main`:\r\n* the `constantOnly`
check has been pushed down rather than depend on an\r\nempty string\r\n*
autosuggestion takes into account the previous argument types now
to\r\npropose the next one\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"eadc173ba23e44ed30e3dcfdf8b3b01c683b9358","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:prev-minor","Feature:ES|QL","v8.14.0","Team:ESQL","v8.15.0"],"title":"[ES|QL]
Fix autocomplete with incompatible
args","number":180874,"url":"https://github.com/elastic/kibana/pull/180874","mergeCommit":{"message":"[ES|QL]
Fix autocomplete with incompatible args (#180874)\n\n##
Summary\r\n\r\nFixes #180730\r\n\r\nI've improved the autocomplete logic
a bit here with the new features\r\nfrom `main`:\r\n* the `constantOnly`
check has been pushed down rather than depend on an\r\nempty string\r\n*
autosuggestion takes into account the previous argument types now
to\r\npropose the next one\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"eadc173ba23e44ed30e3dcfdf8b3b01c683b9358"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/180874","number":180874,"mergeCommit":{"message":"[ES|QL]
Fix autocomplete with incompatible args (#180874)\n\n##
Summary\r\n\r\nFixes #180730\r\n\r\nI've improved the autocomplete logic
a bit here with the new features\r\nfrom `main`:\r\n* the `constantOnly`
check has been pushed down rather than depend on an\r\nempty string\r\n*
autosuggestion takes into account the previous argument types now
to\r\npropose the next one\r\n\r\n\r\n\r\n### Checklist\r\n\r\n- [x]
[Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"eadc173ba23e44ed30e3dcfdf8b3b01c683b9358"}}]}]
BACKPORT-->

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) Feature:ES|QL ES|QL related features in Kibana release_note:fix Team:ESQL ES|QL related features in Kibana v8.14.0 v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] autocomplete suggests things incompatible with previous args
5 participants