Skip to content

[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value#222312

Merged
stratoula merged 7 commits intoelastic:mainfrom
stratoula:fix-where-named-param
Jun 5, 2025
Merged

[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value#222312
stratoula merged 7 commits intoelastic:mainfrom
stratoula:fix-where-named-param

Conversation

@stratoula
Copy link
Contributor

@stratoula stratoula commented Jun 3, 2025

Summary

Closes #221776

Case 1: Suggestions after the system params

image

Case 2: Suggestions after a random named param

image

Case 3: Suggestions after field named param

image

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 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
// 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)
Copy link
Contributor Author

@stratoula stratoula Jun 3, 2025

Choose a reason for hiding this comment

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

This change is irrelevant with the bug we are trying to solve here but it solves another bug. An error appears in the console when you use the named params with the ?? (such as ... | WHERE ??field)

image (99)

@stratoula stratoula changed the title [ES|QL][WIP] Fixing the suggestions in WHERE after named params Jun 4, 2025
return getExpressionType(root[0], fields, userDefinedColumns);
}

if (isLiteralItem(root) && root.literalType !== 'param') {
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 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.

@stratoula stratoula added Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// v9.1.0 v8.19.0 backport:version Backport to applied version labels release_note:fix labels Jun 4, 2025
@stratoula stratoula changed the title [ES|QL] Fixing the suggestions in WHERE after named params Jun 4, 2025
@stratoula stratoula marked this pull request as ready for review June 4, 2025 09:20
@stratoula stratoula requested a review from a team as a code owner June 4, 2025 09:20
@elasticmachine
Copy link
Contributor

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

@elastic elastic deleted a comment from elasticmachine Jun 4, 2025
@stratoula stratoula requested a review from drewdaemon June 4, 2025 15:01
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.

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';
Copy link
Contributor

@drewdaemon drewdaemon Jun 4, 2025

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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. 👍

@stratoula
Copy link
Contributor Author

@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.

@stratoula stratoula merged commit bee60b3 into elastic:main Jun 5, 2025
22 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 5, 2025
…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)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

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 Jun 5, 2025
…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>
pmuellr pushed a commit to pmuellr/kibana that referenced this pull request Jun 11, 2025
…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)
nickpeihl pushed a commit to nickpeihl/kibana that referenced this pull request Jun 12, 2025
…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)
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:fix Team:ESQL ES|QL related features in Kibana t// v8.19.0 v9.1.0

4 participants