[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value#222312
[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value#222312stratoula merged 7 commits intoelastic:mainfrom
Conversation
| // and not directly after the column name or prefix e.g. "colu/" | ||
| !new RegExp(`${expressionRoot.parts.join('\\.')}$`).test(innerText) | ||
| // we are escaping the column name here as it may contain special characters such as ?? | ||
| !new RegExp(`${escapeRegExp(expressionRoot.parts.join('\\.'))}$`).test(innerText) |
| return getExpressionType(root[0], fields, userDefinedColumns); | ||
| } | ||
|
|
||
| if (isLiteralItem(root) && root.literalType !== 'param') { |
There was a problem hiding this comment.
This check was returning all the named params as of type unknown. We are filtering out suggestions for type unknown so with this change now we are returning the type param which is not filtered out.
|
Pinging @elastic/kibana-esql (Team:ESQL) |
There was a problem hiding this comment.
You are being pragmatic and obviously we don't want a degraded experience for users who are using controls. I like here that you have scoped the change down to params and retained the existing behavior for invalid expressions (type unknown).
That said, my guess is that we will have to grapple with this again in the future.
For example, we filter function call signatures by the types of the existing parameters.
Say we have the FUNC function with two call signatures: keyword, keyword, and double, double.
In the current system, FUNC(keywordField, /) should only suggest keyword things, not doubles because of the type of the first parameter.
But what if the type of the first argument is "param" (FUNC(??field, /))?
Should we then be suggesting both double and keyword things? I didn't test it, but I doubt this works right now.
| /** | ||
| * Type guard to check if the type is 'param' | ||
| */ | ||
| export const isParamExpressionType = (type: string): type is 'param' => type === 'param'; |
There was a problem hiding this comment.
nit: what does having a function for this accomplish?
As a comparable: I think most of our isSomething AST helpers only exist because we currently have to make sure that the nodes aren't randomly arrays. I would love to see them disappear and just be able to say if (node.type === 'option') instead of if (isOptionItem(node))for example.
There was a problem hiding this comment.
Oh interesting thought. I like these small functions for readability. So I prefer them from something === "param". I had them as that actually and I didnt like it.
I think if your utilities are well organized they can be really helpful for the code readability. Mostly because we have so many different types and terms. I always struggle reading this code and I feel that these small utilities help me.
I hear your point ofc. At the end of the day it is a personal preference. We should have a convention for sure. 👍
|
@drewdaemon u r right. I did the minimum to make the params work with the most popular cases in WHERE. For the sake of ES|QL controls. There are other cases that are not handled. And they can't be handled in a bug fix PR. My personal opinion after working on this code is that we need to rewrite this expression logic and have a plan for params. The code is very complex, you navigate from one function to another, there are so many things go on that is not easy to debug or fix or make enhancements. I have a note on looking into this and come with a strategy on how we should improve it. |
|
Starting backport for target branches: 8.19 |
…ue (elastic#222312) ## Summary Closes elastic#221776 **Case 1: Suggestions after the system params** <img width="925" alt="image" src="https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370" /> **Case 2: Suggestions after a random named param** <img width="1009" alt="image" src="https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520" /> **Case 3: Suggestions after field named param** <img width="469" alt="image" src="https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd" /> **Note:** Fixes are being applied to eval too. ### Some more technical info The named params (such as ?value or ??field) were typed as unknown to our code. For are not offering suggestions for this type but named params are important for controls and we should not block the suggestions because the user used a named param. This PR is changing the logic and treats the named params as of type `param` allowing the suggestions to follow. ### Checklist - [ ] [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 - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) (cherry picked from commit bee60b3)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…as ?value (#222312) (#222733) # Backport This will backport the following commits from `main` to `8.19`: - [[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value (#222312)](#222312) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Stratoula Kalafateli","email":"efstratia.kalafateli@elastic.co"},"sourceCommit":{"committedDate":"2025-06-05T05:58:39Z","message":"[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value (#222312)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/221776\n\n**Case 1: Suggestions after the system params**\n\n<img width=\"925\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370\"\n/>\n\n\n**Case 2: Suggestions after a random named param**\n\n<img width=\"1009\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520\"\n/>\n\n**Case 3: Suggestions after field named param**\n\n<img width=\"469\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd\"\n/>\n\n\n**Note:** Fixes are being applied to eval too.\n\n\n### Some more technical info\n\nThe named params (such as ?value or ??field) were typed as unknown to\nour code. For are not offering suggestions for this type but named\nparams are important for controls and we should not block the\nsuggestions because the user used a named param.\nThis PR is changing the logic and treats the named params as of type\n`param` allowing the suggestions to follow.\n\n### Checklist\n\n- [ ] [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\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"bee60b3a415f938e20e0952404a73c221d90d232","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:ES|QL","Team:ESQL","backport:version","v9.1.0","v8.19.0"],"title":"[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value","number":222312,"url":"https://github.com/elastic/kibana/pull/222312","mergeCommit":{"message":"[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value (#222312)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/221776\n\n**Case 1: Suggestions after the system params**\n\n<img width=\"925\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370\"\n/>\n\n\n**Case 2: Suggestions after a random named param**\n\n<img width=\"1009\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520\"\n/>\n\n**Case 3: Suggestions after field named param**\n\n<img width=\"469\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd\"\n/>\n\n\n**Note:** Fixes are being applied to eval too.\n\n\n### Some more technical info\n\nThe named params (such as ?value or ??field) were typed as unknown to\nour code. For are not offering suggestions for this type but named\nparams are important for controls and we should not block the\nsuggestions because the user used a named param.\nThis PR is changing the logic and treats the named params as of type\n`param` allowing the suggestions to follow.\n\n### Checklist\n\n- [ ] [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\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"bee60b3a415f938e20e0952404a73c221d90d232"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/222312","number":222312,"mergeCommit":{"message":"[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value (#222312)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/221776\n\n**Case 1: Suggestions after the system params**\n\n<img width=\"925\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370\"\n/>\n\n\n**Case 2: Suggestions after a random named param**\n\n<img width=\"1009\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520\"\n/>\n\n**Case 3: Suggestions after field named param**\n\n<img width=\"469\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd\"\n/>\n\n\n**Note:** Fixes are being applied to eval too.\n\n\n### Some more technical info\n\nThe named params (such as ?value or ??field) were typed as unknown to\nour code. For are not offering suggestions for this type but named\nparams are important for controls and we should not block the\nsuggestions because the user used a named param.\nThis PR is changing the logic and treats the named params as of type\n`param` allowing the suggestions to follow.\n\n### Checklist\n\n- [ ] [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\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"bee60b3a415f938e20e0952404a73c221d90d232"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
…ue (elastic#222312) ## Summary Closes elastic#221776 **Case 1: Suggestions after the system params** <img width="925" alt="image" src="https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370" /> **Case 2: Suggestions after a random named param** <img width="1009" alt="image" src="https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520" /> **Case 3: Suggestions after field named param** <img width="469" alt="image" src="https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd" /> **Note:** Fixes are being applied to eval too. ### Some more technical info The named params (such as ?value or ??field) were typed as unknown to our code. For are not offering suggestions for this type but named params are important for controls and we should not block the suggestions because the user used a named param. This PR is changing the logic and treats the named params as of type `param` allowing the suggestions to follow. ### Checklist - [ ] [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 - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
…ue (elastic#222312) ## Summary Closes elastic#221776 **Case 1: Suggestions after the system params** <img width="925" alt="image" src="https://github.com/user-attachments/assets/496f0b57-a834-49df-9904-374cd433e370" /> **Case 2: Suggestions after a random named param** <img width="1009" alt="image" src="https://github.com/user-attachments/assets/d5c82af5-7677-41ad-ac9b-d0888bcc4520" /> **Case 3: Suggestions after field named param** <img width="469" alt="image" src="https://github.com/user-attachments/assets/827268f2-8abd-404a-b41a-71b1431c71fd" /> **Note:** Fixes are being applied to eval too. ### Some more technical info The named params (such as ?value or ??field) were typed as unknown to our code. For are not offering suggestions for this type but named params are important for controls and we should not block the suggestions because the user used a named param. This PR is changing the logic and treats the named params as of type `param` allowing the suggestions to follow. ### Checklist - [ ] [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 - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Summary
Closes #221776
Case 1: Suggestions after the system params
Case 2: Suggestions after a random named param
Case 3: Suggestions after field named param
Note: Fixes are being applied to eval too.
Some more technical info
The named params (such as ?value or ??field) were typed as unknown to our code. For are not offering suggestions for this type but named params are important for controls and we should not block the suggestions because the user used a named param.
This PR is changing the logic and treats the named params as of type
paramallowing the suggestions to follow.Checklist
release_note:*label is applied per the guidelines