-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] add validation for VALUES
and MV_SORT
#179874
Conversation
Pinging @elastic/kibana-esql (Team:ESQL) |
VALUES
and MV_SORT
@stratoula I think this is ready for review |
* we can't check the return value of a function to see if it | ||
* matches one of the options prior to runtime. | ||
*/ | ||
literalOptions?: string[]; |
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.
can we call it values
to align with the CommandDefinition
thing?
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.
Could you clarify a bit? I'm thinking options better describes what this is. "value" implies what the user actually chooses, whereas "options" says to me a set of values they are allowed to choose.
Shouldn't we have here the parser and lexer changes too? 🤔 |
@stratoula those were taken care of in #179850 |
Gotcha! Thanx, I will review tomorrow! |
/ci |
packages/kbn-esql-validation-autocomplete/src/definitions/functions.ts
Outdated
Show resolved
Hide resolved
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.
It fails on a duplicate i18n keyword but it works fine so I am approving to unblock!
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.
I've left few comments on code to revisit.
They're on my radar @dej611 :) |
…into add-values-definition
@elasticmachine merge upstream |
Good catch... this was working but it looks like I broke it. The tests are yelling about it too :D |
…into add-values-definition
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.
Autocomplete works great. @dej611 can you check code wise and if you are ok let's merge
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.
The structure seems better now. I would ask for a minor tweak as in code comments.
packages/kbn-esql-ast/src/types.ts
Outdated
export interface ESQLNumberLiteral extends ESQLAstBaseItem { | ||
type: 'literal'; | ||
literalType: 'number'; | ||
value: number; | ||
} | ||
|
||
export interface ESQLBooleanLiteral extends ESQLAstBaseItem { | ||
type: 'literal'; | ||
literalType: 'boolean'; | ||
value: string; | ||
} | ||
|
||
export interface ESQLNullLiteral extends ESQLAstBaseItem { | ||
type: 'literal'; | ||
literalType: 'null'; | ||
value: string; | ||
} | ||
|
||
export interface ESQLStringLiteral extends ESQLAstBaseItem { |
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.
I'm not against to exporting for internal usage (which I think should be marked) rather for public one.
As long as they are not publicly exported I'm ok.
@@ -165,6 +165,16 @@ export const buildConstantsDefinitions = ( | |||
sortText: 'A', | |||
})); | |||
|
|||
export const buildValueDefinitions = (values: string[]): SuggestionRawDefinition[] => |
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.
As a follow up of this PR I would probably reuse this for chrono_literals
and time_literals
as well
actualArg.literalType === 'string' && | ||
argDef.literalOptions && | ||
!argDef.literalOptions | ||
.map((option) => option.toLowerCase()) | ||
.includes(unwrapStringLiteralQuotes(actualArg.value).toLowerCase()) |
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.
I would probably make this go into the omniscent isEqualType
as:
// currently only supporting literalOptions with string literals
actualArg.literalType === 'string' &&
argDef.literalOptions &&
!isEqualType(actualArg, argDef, references, parentCommand)
then the isEqualType
signature will change as:
export function isEqualType(
item: ESQLSingleAstItem,
argDef: SignatureArgType | FunctionArg,
references: ReferenceMaps,
parentCommand?: string,
nameHit?: string
) {
const argType = 'innerType' in argDef && argDef.innerType ? argDef.innerType : argDef.type;
if (argType === 'any') {
return true;
}
if (item.type === 'literal') {
return compareLiteralType(
argType,
item,
'literalOptions' in argDef ? argDef.literalOptions : undefined
);
}
...
and the compareLiteralType
function becomes:
function compareLiteralType(argTypes: string, item: ESQLLiteral, possibleOptions?: string[]) {
if (item.literalType !== 'string') {
return argTypes === item.literalType;
}
if (argTypes === 'chrono_literal') {
return chronoLiterals.some(({ name }) => name === item.text);
}
if (possibleOptions) {
return possibleOptions.includes(unwrapStringLiteralQuotes(item.text.toLowerCase()));
}
return argTypes === item.literalType;
}
(I think the assumption that the literalOptions
are already lower case can be made).
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.
I started down this path but I'm not sure isEqualType
is the best fit. We want a different message if the type is correct but it doesn't match one of the literalOptions
. All isEqualType
returns is true
or false
.
If I were to incorporate this check into isEqualType
, I would end up reporting that the type is incorrect when, in fact, it just doesn't match one of the supported options.
@dej611 I've addressed your comments. Can you take another look? |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
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.
Approve to unblock.
Can you create a follow up PR with more tests over mv_sort
with capitalized asc
and desc
args?
…into add-values-definition
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: |
I'll take it! |
Summary
Adds validation support for VALUES and MV_SORT.
Validation
Autocomplete
Checklist