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] Separate EVAL autocomplete routine #212996

Merged
merged 44 commits into from
Mar 18, 2025

Conversation

drewdaemon
Copy link
Contributor

@drewdaemon drewdaemon commented Mar 3, 2025

Summary

Part of #195418

Gives EVAL autocomplete logic its own home 🏡

Expression suggestions function

This PR also introduces a semi-generic function for generating suggestions within an expression. This is so that the logic can be shared between EVAL and WHERE. It also gets us closer to supporting filtering in STATS (#195363).

To make this happen, I took stock of where we have differences in our expression suggestions between WHERE and EVAL. In some cases, the differences seemed important. In other cases, I felt ok removing them.

EVAL

Behavior Plan
Suggests pipe and comma after complete column names (column/ or column /) get rid of it because an expression consisting of just a single column name is essentially useless in EVAL
Doesn't suggest fields after an assignment get rid of it. why act any different than an expression not assigned an alias?
Suggests assignment operator after new column name (newColumn /) keep it
Suggests assignment snippet for empty expression keep it
Suggests time literal completions after literal number in assignment (newColumn = 1 /) remove it. it doesn't feel that useful and removing it makes it easier to have a generic expression suggestions function. It will still be around in functions and operators (e.g. 1 day + 2 /).
Supports multiple expressions keep it

WHERE

Behavior Plan
Suggests pipe after complete boolean expression (foo AND bar /) keep it, but outside of the expression suggestion function
Suggests boolean operators to make a boolean expression (timestamp > "2002" AND doubleField /) keep it... maybe we're being too smart but we can always remove it later

Other changes

  • the suggestions for CASE(foo != /) used to differ based on the trigger kind. This seemed inadvertent so I removed the difference.
  • we now add spaces after fields that are inserted in expressions. E.g. WHERE foo + <insert field><space>. I'm not sure if this is best or not...

Checklist

Identify risks

  • As with any refactor, there's a possibility this will introduce a regression in the behavior of commands. However, all automated tests are passing and I have tested the behavior manually and can detect no regression.

@drewdaemon drewdaemon added release_note:skip Skip the PR/issue when compiling release notes Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Mar 3, 2025
@drewdaemon drewdaemon marked this pull request as ready for review March 14, 2025 02:41
@drewdaemon drewdaemon requested a review from a team as a code owner March 14, 2025 02:41
@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.

This looks nice, I have added some questions to understand better some decisions

@@ -1036,6 +1037,8 @@ describe('autocomplete', () => {
'AND $0',
'NOT',
'OR $0',
', ',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why comma and pipe got added 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.

"IS NOT N" gets parsed into our AST as a complete "IS NOT NULL" (see #199401). Because the AST is complete, it detects this as a complete expression.

I don't think it will matter to the user, but I will double check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I guess I do need to fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0e6fc40

I realized this was an existing bug in WHERE too, so they're both fixed now.

// e.g. CASE(field != /)
//
// So, it is handled as a special branch...
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this branch be moved inside the eval autocomplete as it is an eval 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 will check... I'm pretty sure you can use it other places.

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 do agree that this is not a good long-term home for it but this is actually where it was before. It was just hidden in the generic code. I am doing some thinking about the role of function suggestion routines in relation to the command 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.

Yeah, for example if we moved it to EVAL, we'd lose the right behavior in SORT

Screenshot 2025-03-14 at 1 37 46 PM

WDYT

Copy link
Contributor

Choose a reason for hiding this comment

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

Mmmm I see 🤔 Yes leave it there but we need to rethink it in the future

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 agree. Consider this refactor in flux...

commandName: 'eval',
});

// EVAL-specific stuff
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't get this comment here

Copy link
Contributor

Choose a reason for hiding this comment

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

I got it, these are the code that eval does differently 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0e6fc40


break;
}
// WHERE-specific stuff
Copy link
Contributor

@stratoula stratoula Mar 14, 2025

Choose a reason for hiding this comment

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

Same here 🤔

Update: This is where you differentiate 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.

I'll remove the comment. I think it is confusing—you're already in where/index.ts—of course it is WHERE-specific

Copy link
Contributor

Choose a reason for hiding this comment

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

yes and the eval too, I think this is why I got confused in the first place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0e6fc40


break;

case 'empty_expression':
Copy link
Contributor

Choose a reason for hiding this comment

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

So I understand that this is a very common code between eval and where and why we decided to move everything in one helper. But we still need to differentiate between where and eval as there are functions that do not exist in eval. I wonder if we can keep the split here and share code only when necessary. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'm open to duplicating the contents of this function between WHERE and EVAL if that's what you mean?

The reasons I was thinking a shared function with customization through arguments were

  1. suggestions within an expression (by "expression" I mean some values plus some operators) are not very different between the two commands
  2. having a shared function will make it easier to extend this functionality to other expressions within ES|QL

For example, ES|QL allows expressions in

  • SORT
  • STATS ... BY
  • STATS ... WHERE
  • within function parameters

We don't currently give help in any of the above contexts, with the exception of the first argument in CASE. We know we want to extend to STATS...WHERE and we may want to extend to more of these.

Let me know what you want me to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are yes and I understand why you decided to go that way. It is just the fact that there will always be some differences:

  • STATS ... WHERE doesnt support full text search
  • SORT neither
  • EVAL has a functionality that doesnt exist in WHERE etc
  • How will this look as the language will evolve? More if else? I don't know, I am mostly wondering if this approach will suit us or we will need to change it in the future

I wasn't really suggesting to duplicate everything. I was just wondering if maybe we can share code but have the differences to be set in the distinct code. So for example:

  • search functions and the match operator is a where thingy. Can we set them up in the where code and pass it to the shared one in order to make the shared a bit more generic?

Copy link
Contributor Author

@drewdaemon drewdaemon Mar 14, 2025

Choose a reason for hiding this comment

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

Ok then we are on the same page. I agree that the commands should be able to configure expression suggestion behavior based on context and we can do this better than it is happening now. For example, have the suggestion routines build a set of configuration parameters that they pass to the expression suggestions function

getExpressionSuggestions(... { 
    suggestFunctions: () => { only suggest functions supported in this context }, 
    preferredExpressionType: 'boolean'... 
})

In a similar vein we should definitely

  • clean up the "function argument suggestions function" as well—it is littered with special cases and command awareness, etc.,
  • possibly put function suggestions within the command routines instead of as its own separate top-level branch
  • get the editor marker under control
  • remove options and settings and other defunct stuff

But I want to scope this PR to just moving EVAL stuff to its own place. When I start diving into side-quests in these PRs (for example, removing all command-awareness from all the sub functions in getExpressionSuggestions), they tend to get very unmanageable. I know the file counts aren’t large here, but untangling the logic is very complicated.

 So, I agree with your direction and I want to clean up more, but I would rather focus here on first putting per-command boundaries on the craziness. 🤪

Now that we actually know what all this logic does, we can evolve it however we need to with very little refactoring

Copy link
Contributor

Choose a reason for hiding this comment

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

ok I am fine with it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll like what you see when I take care of #209359

@@ -243,6 +245,7 @@ export const commandDefinitions: Array<CommandDefinition<any>> = [
modes: [],
// Reusing the same validation logic as stats command
validate: statsValidator,
suggest: suggestForStats,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this added to add autocomplete support to inlinestats? If yes it doesnt seem to work as expected

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks... actually what is the status of inlinestats? I don't see it in our docs...

Copy link
Contributor

Choose a reason for hiding this comment

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

Inlinestats is paused atm in favor of joins. Let's remove it the suggest here and deal with it when inlinestats is back in the roadmap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0e6fc40

@drewdaemon
Copy link
Contributor Author

@elasticmachine merge upstream

@drewdaemon drewdaemon requested a review from stratoula March 17, 2025 18:02
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/esql-validation-autocomplete 186 188 +2

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/esql-validation-autocomplete 12 13 +1

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 -3.2KB
Unknown metric groups

API count

id before after diff
@kbn/esql-validation-autocomplete 198 200 +2

Unreferenced deprecated APIs

id before after diff
@kbn/esql-validation-autocomplete 1 2 +1

History

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.

Looks nice,k thanx for addressing the comments and the brainstorming

@@ -1008,10 +1009,6 @@ describe('autocomplete', () => {
'AND $0',
'NOT',
'OR $0',
// pipe doesn't make sense here, but Monaco will filter it out.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@drewdaemon drewdaemon merged commit 74c31fb into elastic:main Mar 18, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

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

Part of elastic#195418

Gives `EVAL` autocomplete logic its own home 🏡

### Expression suggestions function

This PR also introduces a semi-generic function for generating
suggestions within an expression. This is so that the logic can be
shared between `EVAL` and `WHERE`. It also gets us closer to supporting
filtering in `STATS` (elastic#195363).

To make this happen, I took stock of where we have differences in our
expression suggestions between `WHERE` and `EVAL`. In some cases, the
differences seemed important. In other cases, I felt ok removing them.

#### EVAL

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe and comma after complete column names (`column/` or
`column /`)| get rid of it because an expression consisting of just a
single column name is essentially useless in `EVAL` |
| Doesn't suggest fields after an assignment | get rid of it. why act
any different than an expression not assigned an alias? |
| Suggests assignment operator after new column name (`newColumn /`) |
keep it |
| Suggests assignment snippet for empty expression | keep it |
| Suggests time literal completions after literal number in assignment
(`newColumn = 1 /`) | remove it. it doesn't feel that useful and
removing it makes it easier to have a generic expression suggestions
function. It will still be around in functions and operators (e.g. `1
day + 2 /`). |
| Supports multiple expressions | keep it |

#### WHERE

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe after complete boolean expression (`foo AND bar /`) |
keep it, but outside of the expression suggestion function |
| Suggests boolean operators to make a boolean expression (`timestamp >
"2002" AND doubleField /`) | keep it... maybe we're being too smart but
we can always remove it later |

### Other changes
- the suggestions for `CASE(foo != /)` used to differ based on the
trigger kind. This seemed inadvertent so I removed the difference.
- we now add spaces after fields that are inserted in expressions. E.g.
`WHERE foo + <insert field><space>`. I'm not sure if this is best or
not...

### 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

### Identify risks

- [ ] As with any refactor, there's a possibility this will introduce a
regression in the behavior of commands. However, all automated tests are
passing and I have tested the behavior manually and can detect no
regression.

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 74c31fb)
@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 Mar 18, 2025
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Separate `EVAL` autocomplete routine
(#212996)](#212996)

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

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

<!--BACKPORT [{"author":{"name":"Drew
Tate","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-03-18T12:24:50Z","message":"[ES|QL]
Separate `EVAL` autocomplete routine (#212996)\n\n## Summary\n\nPart of
https://github.com/elastic/kibana/issues/195418\n\nGives `EVAL`
autocomplete logic its own home 🏡\n\n\n### Expression suggestions
function\n\nThis PR also introduces a semi-generic function for
generating\nsuggestions within an expression. This is so that the logic
can be\nshared between `EVAL` and `WHERE`. It also gets us closer to
supporting\nfiltering in `STATS`
(https://github.com/elastic/kibana/issues/195363).\n\nTo make this
happen, I took stock of where we have differences in our\nexpression
suggestions between `WHERE` and `EVAL`. In some cases, the\ndifferences
seemed important. In other cases, I felt ok removing them.\n\n####
EVAL\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe and comma after complete column names (`column/`
or\n`column /`)| get rid of it because an expression consisting of just
a\nsingle column name is essentially useless in `EVAL` |\n| Doesn't
suggest fields after an assignment | get rid of it. why act\nany
different than an expression not assigned an alias? |\n| Suggests
assignment operator after new column name (`newColumn /`) |\nkeep it
|\n| Suggests assignment snippet for empty expression | keep it |\n|
Suggests time literal completions after literal number in
assignment\n(`newColumn = 1 /`) | remove it. it doesn't feel that useful
and\nremoving it makes it easier to have a generic expression
suggestions\nfunction. It will still be around in functions and
operators (e.g. `1\nday + 2 /`). |\n| Supports multiple expressions |
keep it |\n\n#### WHERE\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe after complete boolean expression (`foo AND bar /`)
|\nkeep it, but outside of the expression suggestion function |\n|
Suggests boolean operators to make a boolean expression (`timestamp
>\n\"2002\" AND doubleField /`) | keep it... maybe we're being too smart
but\nwe can always remove it later |\n\n### Other changes\n- the
suggestions for `CASE(foo != /)` used to differ based on the\ntrigger
kind. This seemed inadvertent so I removed the difference.\n- we now add
spaces after fields that are inserted in expressions. E.g.\n`WHERE foo +
<insert field><space>`. I'm not sure if this is best or\nnot...\n\n\n###
Checklist\n\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\n\n### Identify
risks\n\n- [ ] As with any refactor, there's a possibility this will
introduce a\nregression in the behavior of commands. However, all
automated tests are\npassing and I have tested the behavior manually and
can detect no\nregression.\n\n---------\n\nCo-authored-by: Stratoula
Kalafateli <[email protected]>\nCo-authored-by: Elastic
Machine
<[email protected]>","sha":"74c31fbc862a1e26871f46802d0f9e9869c3d296","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:ES|QL","Team:ESQL","backport:version","v9.1.0","v8.19.0"],"title":"[ES|QL]
Separate `EVAL` autocomplete
routine","number":212996,"url":"https://github.com/elastic/kibana/pull/212996","mergeCommit":{"message":"[ES|QL]
Separate `EVAL` autocomplete routine (#212996)\n\n## Summary\n\nPart of
https://github.com/elastic/kibana/issues/195418\n\nGives `EVAL`
autocomplete logic its own home 🏡\n\n\n### Expression suggestions
function\n\nThis PR also introduces a semi-generic function for
generating\nsuggestions within an expression. This is so that the logic
can be\nshared between `EVAL` and `WHERE`. It also gets us closer to
supporting\nfiltering in `STATS`
(https://github.com/elastic/kibana/issues/195363).\n\nTo make this
happen, I took stock of where we have differences in our\nexpression
suggestions between `WHERE` and `EVAL`. In some cases, the\ndifferences
seemed important. In other cases, I felt ok removing them.\n\n####
EVAL\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe and comma after complete column names (`column/`
or\n`column /`)| get rid of it because an expression consisting of just
a\nsingle column name is essentially useless in `EVAL` |\n| Doesn't
suggest fields after an assignment | get rid of it. why act\nany
different than an expression not assigned an alias? |\n| Suggests
assignment operator after new column name (`newColumn /`) |\nkeep it
|\n| Suggests assignment snippet for empty expression | keep it |\n|
Suggests time literal completions after literal number in
assignment\n(`newColumn = 1 /`) | remove it. it doesn't feel that useful
and\nremoving it makes it easier to have a generic expression
suggestions\nfunction. It will still be around in functions and
operators (e.g. `1\nday + 2 /`). |\n| Supports multiple expressions |
keep it |\n\n#### WHERE\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe after complete boolean expression (`foo AND bar /`)
|\nkeep it, but outside of the expression suggestion function |\n|
Suggests boolean operators to make a boolean expression (`timestamp
>\n\"2002\" AND doubleField /`) | keep it... maybe we're being too smart
but\nwe can always remove it later |\n\n### Other changes\n- the
suggestions for `CASE(foo != /)` used to differ based on the\ntrigger
kind. This seemed inadvertent so I removed the difference.\n- we now add
spaces after fields that are inserted in expressions. E.g.\n`WHERE foo +
<insert field><space>`. I'm not sure if this is best or\nnot...\n\n\n###
Checklist\n\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\n\n### Identify
risks\n\n- [ ] As with any refactor, there's a possibility this will
introduce a\nregression in the behavior of commands. However, all
automated tests are\npassing and I have tested the behavior manually and
can detect no\nregression.\n\n---------\n\nCo-authored-by: Stratoula
Kalafateli <[email protected]>\nCo-authored-by: Elastic
Machine
<[email protected]>","sha":"74c31fbc862a1e26871f46802d0f9e9869c3d296"}},"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/212996","number":212996,"mergeCommit":{"message":"[ES|QL]
Separate `EVAL` autocomplete routine (#212996)\n\n## Summary\n\nPart of
https://github.com/elastic/kibana/issues/195418\n\nGives `EVAL`
autocomplete logic its own home 🏡\n\n\n### Expression suggestions
function\n\nThis PR also introduces a semi-generic function for
generating\nsuggestions within an expression. This is so that the logic
can be\nshared between `EVAL` and `WHERE`. It also gets us closer to
supporting\nfiltering in `STATS`
(https://github.com/elastic/kibana/issues/195363).\n\nTo make this
happen, I took stock of where we have differences in our\nexpression
suggestions between `WHERE` and `EVAL`. In some cases, the\ndifferences
seemed important. In other cases, I felt ok removing them.\n\n####
EVAL\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe and comma after complete column names (`column/`
or\n`column /`)| get rid of it because an expression consisting of just
a\nsingle column name is essentially useless in `EVAL` |\n| Doesn't
suggest fields after an assignment | get rid of it. why act\nany
different than an expression not assigned an alias? |\n| Suggests
assignment operator after new column name (`newColumn /`) |\nkeep it
|\n| Suggests assignment snippet for empty expression | keep it |\n|
Suggests time literal completions after literal number in
assignment\n(`newColumn = 1 /`) | remove it. it doesn't feel that useful
and\nremoving it makes it easier to have a generic expression
suggestions\nfunction. It will still be around in functions and
operators (e.g. `1\nday + 2 /`). |\n| Supports multiple expressions |
keep it |\n\n#### WHERE\n\n| Behavior | Plan
|\n\n|--------------------------------------------------------------------------|------|\n|
Suggests pipe after complete boolean expression (`foo AND bar /`)
|\nkeep it, but outside of the expression suggestion function |\n|
Suggests boolean operators to make a boolean expression (`timestamp
>\n\"2002\" AND doubleField /`) | keep it... maybe we're being too smart
but\nwe can always remove it later |\n\n### Other changes\n- the
suggestions for `CASE(foo != /)` used to differ based on the\ntrigger
kind. This seemed inadvertent so I removed the difference.\n- we now add
spaces after fields that are inserted in expressions. E.g.\n`WHERE foo +
<insert field><space>`. I'm not sure if this is best or\nnot...\n\n\n###
Checklist\n\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\n\n### Identify
risks\n\n- [ ] As with any refactor, there's a possibility this will
introduce a\nregression in the behavior of commands. However, all
automated tests are\npassing and I have tested the behavior manually and
can detect no\nregression.\n\n---------\n\nCo-authored-by: Stratoula
Kalafateli <[email protected]>\nCo-authored-by: Elastic
Machine
<[email protected]>","sha":"74c31fbc862a1e26871f46802d0f9e9869c3d296"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Drew Tate <[email protected]>
clintandrewhall pushed a commit to clintandrewhall/kibana that referenced this pull request Mar 20, 2025
## Summary

Part of elastic#195418

Gives `EVAL` autocomplete logic its own home 🏡


### Expression suggestions function

This PR also introduces a semi-generic function for generating
suggestions within an expression. This is so that the logic can be
shared between `EVAL` and `WHERE`. It also gets us closer to supporting
filtering in `STATS` (elastic#195363).

To make this happen, I took stock of where we have differences in our
expression suggestions between `WHERE` and `EVAL`. In some cases, the
differences seemed important. In other cases, I felt ok removing them.

#### EVAL

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe and comma after complete column names (`column/` or
`column /`)| get rid of it because an expression consisting of just a
single column name is essentially useless in `EVAL` |
| Doesn't suggest fields after an assignment | get rid of it. why act
any different than an expression not assigned an alias? |
| Suggests assignment operator after new column name (`newColumn /`) |
keep it |
| Suggests assignment snippet for empty expression | keep it |
| Suggests time literal completions after literal number in assignment
(`newColumn = 1 /`) | remove it. it doesn't feel that useful and
removing it makes it easier to have a generic expression suggestions
function. It will still be around in functions and operators (e.g. `1
day + 2 /`). |
| Supports multiple expressions | keep it |

#### WHERE

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe after complete boolean expression (`foo AND bar /`) |
keep it, but outside of the expression suggestion function |
| Suggests boolean operators to make a boolean expression (`timestamp >
"2002" AND doubleField /`) | keep it... maybe we're being too smart but
we can always remove it later |

### Other changes
- the suggestions for `CASE(foo != /)` used to differ based on the
trigger kind. This seemed inadvertent so I removed the difference.
- we now add spaces after fields that are inserted in expressions. E.g.
`WHERE foo + <insert field><space>`. I'm not sure if this is best or
not...


### 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

### Identify risks

- [ ] As with any refactor, there's a possibility this will introduce a
regression in the behavior of commands. However, all automated tests are
passing and I have tested the behavior manually and can detect no
regression.

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
## Summary

Part of elastic#195418

Gives `EVAL` autocomplete logic its own home 🏡


### Expression suggestions function

This PR also introduces a semi-generic function for generating
suggestions within an expression. This is so that the logic can be
shared between `EVAL` and `WHERE`. It also gets us closer to supporting
filtering in `STATS` (elastic#195363).

To make this happen, I took stock of where we have differences in our
expression suggestions between `WHERE` and `EVAL`. In some cases, the
differences seemed important. In other cases, I felt ok removing them.

#### EVAL

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe and comma after complete column names (`column/` or
`column /`)| get rid of it because an expression consisting of just a
single column name is essentially useless in `EVAL` |
| Doesn't suggest fields after an assignment | get rid of it. why act
any different than an expression not assigned an alias? |
| Suggests assignment operator after new column name (`newColumn /`) |
keep it |
| Suggests assignment snippet for empty expression | keep it |
| Suggests time literal completions after literal number in assignment
(`newColumn = 1 /`) | remove it. it doesn't feel that useful and
removing it makes it easier to have a generic expression suggestions
function. It will still be around in functions and operators (e.g. `1
day + 2 /`). |
| Supports multiple expressions | keep it |

#### WHERE

| Behavior | Plan |

|--------------------------------------------------------------------------|------|
| Suggests pipe after complete boolean expression (`foo AND bar /`) |
keep it, but outside of the expression suggestion function |
| Suggests boolean operators to make a boolean expression (`timestamp >
"2002" AND doubleField /`) | keep it... maybe we're being too smart but
we can always remove it later |

### Other changes
- the suggestions for `CASE(foo != /)` used to differ based on the
trigger kind. This seemed inadvertent so I removed the difference.
- we now add spaces after fields that are inserted in expressions. E.g.
`WHERE foo + <insert field><space>`. I'm not sure if this is best or
not...


### 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

### Identify risks

- [ ] As with any refactor, there's a possibility this will introduce a
regression in the behavior of commands. However, all automated tests are
passing and I have tested the behavior manually and can detect no
regression.

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
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:skip Skip the PR/issue when compiling release notes Team:ESQL ES|QL related features in Kibana v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants