String-Only Suggestions for Like and RLike Operators#244903
String-Only Suggestions for Like and RLike Operators#244903bartoval merged 5 commits intoelastic:mainfrom
Conversation
|
Pinging @elastic/kibana-esql (Team:ESQL) |
ae81022 to
35ec825
Compare
stratoula
left a comment
There was a problem hiding this comment.
Very nice enhancement, left some comments to improve the suggestions!
|
|
||
| /** Returns true if we should suggest opening a list for the right operand */ | ||
| export function shouldSuggestOpenListForOperand(operand: any): boolean { | ||
| export const LIKE_OPERATOR_REGEX = /\b(not\s+)?(r?like)\s*$/i; |
There was a problem hiding this comment.
I know that we had it like that but isn't it dangerous to check for the operands with regex in the entire queryString? As we are looking into it in this PR, does it makes sense to check here if we can use AST to detect the operands instead of regexes?
There was a problem hiding this comment.
Regexes are used to handle unknown cases when these 3 operators are incomplete. However, they are only used to route between "partials" and "non-partials." Afterwards, I either use the ast node if it exists or create a synthetic one.
| Operator | Outside Function | Inside ANY Function | Regex Necessary? |
|---|---|---|---|
| IS NULL | Parser ✅ | Parser ❌ (unknown) | ✅ Yes (for nested) |
| IS NOT NULL | Parser ✅ | Parser ❌ (unknown) | ✅ Yes (for nested) |
| IN | Parser ✅ | Parser ❌ (unknown) | ✅ Yes (for nested) |
| NOT IN | Parser ✅ | Parser ❌ (unknown) | ✅ Yes (for nested) |
| LIKE/RLIKE | Parser ❌ | Parser ❌ (unknown) | ✅ Yes (always) |
| return IS_NULL_OPERATOR_REGEX.test(innerText); | ||
| } | ||
|
|
||
| export function isOperandMissing(operand: any): boolean { |
...ckages/shared/kbn-esql-ast/src/definitions/utils/autocomplete/expressions/operators/utils.ts
Outdated
Show resolved
Hide resolved
| // RLIKE: regular expression pattern | ||
| const { snippet, label, detail } = isRlike | ||
| ? { snippet: '"${0:.*}"', label: 'regex', detail: 'Regular expression pattern' } | ||
| : { snippet: '"${0:%}"', label: 'pattern', detail: 'Use % for any chars, _ for single char' }; |
There was a problem hiding this comment.
@florent-leborgne can you help here with the text too? We want to instruct users to use a pattern for like.
% (Percent)
Matches any sequence of zero or more characters. The most common wildcard for general substring matching.
_ (Underscore)
Matches any single character. Useful for fixed-length patterns or finding variations.
There was a problem hiding this comment.
Same as above instead of having one suggestion we can have 2, one for _ and one for percent explaining what they do.
| // LIKE: wildcard pattern (% = any chars, _ = single char) | ||
| // RLIKE: regular expression pattern | ||
| const { snippet, label, detail } = isRlike | ||
| ? { snippet: '"${0:.*}"', label: 'regex', detail: 'Regular expression pattern' } |
There was a problem hiding this comment.
@florent-leborgne can you help here with the text? We want to instruct users to use a pattern for rlike.
Some core features
.* (Any String)
Matches any sequence of zero or more characters.
. (Any Single Char)
Matches any single character.
^ and $ (Anchors)
Force the match to the start (^) or end ($) of the string, which improves performance.
There was a problem hiding this comment.
Another thing we can do for both like and rlike is to have more than one suggestion.
So here:
.* --> Match any sequence of zero or more characters
. --> Match any single character
^ --> ...
$ --> ...
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Page load bundle
History
cc @bartoval |
## Summary The` (Not)Like `and `(Not)RLike` operators should suggest only Text, because they perform pattern matching. Their suggestion logic can follow the same approach used for `Rerank `and `Completion`. Currently they suggest a bit of everything. https://github.com/user-attachments/assets/6049ff9a-9c4a-43bb-9291-75b4b7635a4f
## Summary The` (Not)Like `and `(Not)RLike` operators should suggest only Text, because they perform pattern matching. Their suggestion logic can follow the same approach used for `Rerank `and `Completion`. Currently they suggest a bit of everything. https://github.com/user-attachments/assets/6049ff9a-9c4a-43bb-9291-75b4b7635a4f
Summary
The
(Not)Likeand(Not)RLikeoperators should suggest only Text, because they perform pattern matching. Their suggestion logic can follow the same approach used forRerankandCompletion.Currently they suggest a bit of everything.
like.mp4