-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ES|QL] Making the Expression Suggestor More Semantically Intelligent #241081
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6cc83a3
improve suggest for expression policies
bartoval 7c1e048
filter precision as constantonly
bartoval c7916ef
improve roles
bartoval cb6092c
update from feedbacks
bartoval b09f794
Merge branch 'main' into improve_suggestions
bartoval 9d9cebb
Merge branch 'main' into improve_suggestions
bartoval File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,19 @@ import { | |
| expectSuggestions, | ||
| getFieldNamesByType, | ||
| getFunctionSignaturesByReturnType, | ||
| getOperatorSuggestions, | ||
| } from '../../../__tests__/autocomplete'; | ||
| import type { ICommandCallbacks } from '../../types'; | ||
| import { ESQL_COMMON_NUMERIC_TYPES } from '../../../definitions/types'; | ||
| import { timeUnitsToSuggest } from '../../../definitions/constants'; | ||
| import { | ||
| logicalOperators, | ||
| arithmeticOperators, | ||
| comparisonFunctions, | ||
| patternMatchOperators, | ||
| inOperators, | ||
| nullCheckOperators, | ||
| } from '../../../definitions/all_operators'; | ||
|
|
||
| const roundParameterTypes = ['double', 'integer', 'long', 'unsigned_long'] as const; | ||
|
|
||
|
|
@@ -177,7 +186,9 @@ describe('EVAL Autocomplete', () => { | |
| ); | ||
| await evalExpectSuggestions( | ||
| 'from index | EVAL keywordField not ', | ||
| ['LIKE $0', 'RLIKE $0', 'IN $0'], | ||
| getOperatorSuggestions( | ||
| [...inOperators, ...patternMatchOperators].filter((op) => !op.name.startsWith('not ')) | ||
| ), | ||
| mockCallbacks | ||
| ); | ||
|
|
||
|
|
@@ -223,10 +234,7 @@ describe('EVAL Autocomplete', () => { | |
| { operators: true, skipAssign: true }, | ||
| ['double', 'long'] | ||
| ), | ||
| 'IN $0', | ||
| 'IS NOT NULL', | ||
| 'IS NULL', | ||
| 'NOT IN $0', | ||
| ...getOperatorSuggestions([...inOperators, ...nullCheckOperators]), | ||
| ], | ||
| mockCallbacks | ||
| ); | ||
|
|
@@ -250,34 +258,8 @@ describe('EVAL Autocomplete', () => { | |
| (mockCallbacks.getByType as jest.Mock).mockResolvedValue( | ||
| expectedDoubleIntegerFields.map((name) => ({ label: name, text: name })) | ||
| ); | ||
| await evalExpectSuggestions( | ||
| 'from a | eval a=round(doubleField, ', | ||
| [ | ||
| ...expectedDoubleIntegerFields, | ||
| ...getFunctionSignaturesByReturnType( | ||
| Location.EVAL, | ||
| ['integer', 'long'], | ||
| { scalar: true }, | ||
| undefined, | ||
| ['round'] | ||
| ), | ||
| ], | ||
| mockCallbacks | ||
| ); | ||
| await evalExpectSuggestions( | ||
| 'from a | eval round(doubleField, ', | ||
| [ | ||
| ...expectedDoubleIntegerFields, | ||
| ...getFunctionSignaturesByReturnType( | ||
| Location.EVAL, | ||
| ['integer', 'long'], | ||
| { scalar: true }, | ||
| undefined, | ||
| ['round'] | ||
| ), | ||
| ], | ||
| mockCallbacks | ||
| ); | ||
| await evalExpectSuggestions('from a | eval a=round(doubleField, ', [], mockCallbacks); | ||
| await evalExpectSuggestions('from a | eval round(doubleField, ', [], mockCallbacks); | ||
| const expectedAny = getFieldNamesByType('any'); | ||
| (mockCallbacks.getByType as jest.Mock).mockResolvedValue( | ||
| expectedAny.map((name) => ({ label: name, text: name })) | ||
|
|
@@ -506,32 +488,34 @@ describe('EVAL Autocomplete', () => { | |
|
|
||
| test('suggests operators after initial column based on type', async () => { | ||
| // case( field ) suggests all appropriate operators for that field type | ||
| // Note: CASE is expression-heavy, comma is not automatically suggested after fields | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| await evalExpectSuggestions('from a | eval case( textField ', [ | ||
| ...getFunctionSignaturesByReturnType( | ||
| Location.EVAL, | ||
| 'any', | ||
| { operators: true, skipAssign: true, agg: false, scalar: false }, | ||
| ['text'] | ||
| ), | ||
| ...getOperatorSuggestions([ | ||
| ...patternMatchOperators, | ||
| ...inOperators, | ||
| ...nullCheckOperators, | ||
| ]), | ||
| ]); | ||
|
|
||
| await evalExpectSuggestions('from a | eval case( doubleField ', [ | ||
| ...getFunctionSignaturesByReturnType( | ||
| Location.EVAL, | ||
| 'any', | ||
| { operators: true, skipAssign: true, agg: false, scalar: false }, | ||
| ['double'] | ||
| ), | ||
| ...getOperatorSuggestions([ | ||
| ...comparisonFunctions, | ||
| // Exclude unary-only operators (negation) - autocomplete doesn't suggest them | ||
| ...arithmeticOperators.filter( | ||
| (op) => !op.signatures.every((sig) => sig.params.length === 1) | ||
| ), | ||
| ...inOperators, | ||
| ...nullCheckOperators, | ||
| ]), | ||
| ]); | ||
|
|
||
| await evalExpectSuggestions('from a | eval case( booleanField ', [ | ||
| ...getFunctionSignaturesByReturnType( | ||
| Location.EVAL, | ||
| 'any', | ||
| { operators: true, skipAssign: true, agg: false, scalar: false }, | ||
| ['boolean'] | ||
| ...getOperatorSuggestions( | ||
| comparisonFunctions.filter(({ name }) => name === '==' || name === '!=') | ||
| ), | ||
| ',', | ||
| ...getOperatorSuggestions([...logicalOperators, ...inOperators, ...nullCheckOperators]), | ||
| 'NOT', | ||
| ]); | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice