-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[ES|QL] Fixing the suggestions in WHERE after a variable such as ?value #222312
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
Changes from all commits
91e05ba
ffc009f
179b782
db085bc
bcd0ef5
4b3070a
c983b3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |
| type ESQLSource, | ||
| type ESQLTimeInterval, | ||
| type ESQLAstCommand, | ||
| lastItem, | ||
| } from '@kbn/esql-ast'; | ||
| import { | ||
| ESQLIdentifier, | ||
|
|
@@ -820,6 +821,13 @@ export function getParamAtPosition( | |
| return params.length > position ? params[position] : minParams ? params[params.length - 1] : null; | ||
| } | ||
|
|
||
| // --- Expression types helpers --- | ||
|
|
||
| /** | ||
| * Type guard to check if the type is 'param' | ||
| */ | ||
| export const isParamExpressionType = (type: string): type is 'param' => type === 'param'; | ||
|
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. nit: what does having a function for this accomplish? As a comparable: I think most of our
Contributor
Author
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. Oh interesting thought. I like these small functions for readability. So I prefer them from 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. 👍 |
||
|
|
||
| /** | ||
| * Determines the type of the expression | ||
| */ | ||
|
|
@@ -839,7 +847,7 @@ export function getExpressionType( | |
| return getExpressionType(root[0], fields, userDefinedColumns); | ||
| } | ||
|
|
||
| if (isLiteralItem(root) && root.literalType !== 'param') { | ||
|
Contributor
Author
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. 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. |
||
| if (isLiteralItem(root)) { | ||
| return root.literalType; | ||
| } | ||
|
|
||
|
|
@@ -867,6 +875,12 @@ export function getExpressionType( | |
|
|
||
| if (isColumnItem(root) && fields && userDefinedColumns) { | ||
| const column = getColumnForASTNode(root, { fields, userDefinedColumns }); | ||
| const lastArg = lastItem(root.args); | ||
| // If the last argument is a param, we return its type (param literal type) | ||
| // This is useful for cases like `where ??field` | ||
| if (isParam(lastArg)) { | ||
| return lastArg.literalType; | ||
| } | ||
| if (!column) { | ||
| return 'unknown'; | ||
| } | ||
|
|
@@ -916,7 +930,6 @@ export function getExpressionType( | |
| if (!signaturesWithCorrectArity.length) { | ||
| return 'unknown'; | ||
| } | ||
|
|
||
| const argTypes = root.args.map((arg) => getExpressionType(arg, fields, userDefinedColumns)); | ||
|
|
||
| // When functions are passed null for any argument, they generally return null | ||
|
|
@@ -930,7 +943,8 @@ export function getExpressionType( | |
| param && | ||
| (param.type === 'any' || | ||
| param.type === argType || | ||
| (argType === 'keyword' && ['date', 'date_period'].includes(param.type))) | ||
| (argType === 'keyword' && ['date', 'date_period'].includes(param.type)) || | ||
| isParamExpressionType(argType)) | ||
| ); | ||
| }); | ||
| }); | ||
|
|
@@ -945,6 +959,8 @@ export function getExpressionType( | |
| return 'unknown'; | ||
| } | ||
|
|
||
| // --- Fields helpers --- | ||
|
|
||
| export function transformMapToESQLFields( | ||
| inputMap: Map<string, ESQLUserDefinedColumn[]> | ||
| ): ESQLFieldWithMetadata[] { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
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)