-
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] Use custom AST for suggestion, validation, etc... #166185
[ES|QL] Use custom AST for suggestion, validation, etc... #166185
Conversation
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.
Some notes from me (I haven't checked the code yet)
- For some reason I get a 0 warning icon
This works ok in main ( I should see 1 warning and also the warning on the editor footer but I don't)
- I see the error for unknown index but is wrong (I have multiple logstash indices and I want to use the wildcard)
- I think this is important, I want to see the list of aggregations here.
- Here also
If we want to work on autocomplete on a follow up PR can we merge this in a feature branch instead and not main. I feel that the regressions in autocomplete are important and we should not merge them in main.
- Seems the validation hasn't run properly here
- Here I expect var1 to be in the list of suggestions as it is on stats
Thanks for your quick feedback @stratoula . Will reply inline here about validation and UI issues, will defer the autocomplete ones for a later PR:
Can reproduce as well, fixed with 9acd436
This is a bug as I was not validating fuzzy strings for indices. Added the check and a unit test for it with 8ec2226
Can reproduce as well, fixed with 9acd436 |
It seems that this PR is actually reducing the bundlesize of the Enabling detailed stats on the
While on
so After looking at the shared-bundle-src detailed view maybe I get what's going on here: [ibazel] Asset Size Chunks Chunk Names
[ibazel] a1cef3d530e1adb0f52b2f62994a2aca.ttf 69.3 KiB [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.0.js 1.37 MiB 0 [emitted] [big]
+ [ibazel] kbn-ui-shared-deps-src.chunk.0.js 466 KiB 0 [emitted] [big]
- [ibazel] kbn-ui-shared-deps-src.chunk.0.js.map 1.42 MiB 0 [emitted] [dev]
+ [ibazel] kbn-ui-shared-deps-src.chunk.0.js.map 438 KiB 0 [emitted] [dev]
- [ibazel] kbn-ui-shared-deps-src.chunk.1.js 466 KiB 1 [emitted] [big]
+ [ibazel] kbn-ui-shared-deps-src.chunk.1.js 14.6 KiB 1 [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.1.js.map 438 KiB 1 [emitted] [dev]
+ [ibazel] kbn-ui-shared-deps-src.chunk.1.js.map 14.2 KiB 1 [emitted] [dev]
- [ibazel] kbn-ui-shared-deps-src.chunk.2.js 14.6 KiB 2 [emitted]
+ [ibazel] kbn-ui-shared-deps-src.chunk.2.js 4.94 KiB 2 [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.2.js.map 14.2 KiB 2 [emitted] [dev]
+ [ibazel] kbn-ui-shared-deps-src.chunk.2.js.map 4.35 KiB 2 [emitted] [dev]
- [ibazel] kbn-ui-shared-deps-src.chunk.3.js 1.33 KiB 3 [emitted]
+ [ibazel] kbn-ui-shared-deps-src.chunk.3.js 7.61 KiB 3 [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.3.js.map 124 bytes 3 [emitted] [dev]
+ [ibazel] kbn-ui-shared-deps-src.chunk.3.js.map 7.87 KiB 3 [emitted] [dev]
- [ibazel] kbn-ui-shared-deps-src.chunk.4.js 4.94 KiB 4 [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.4.js.map 4.35 KiB 4 [emitted] [dev]
- [ibazel] kbn-ui-shared-deps-src.chunk.5.js 7.61 KiB 5 [emitted]
- [ibazel] kbn-ui-shared-deps-src.chunk.5.js.map 7.87 KiB 5 [emitted] [dev]
[ibazel] kbn-ui-shared-deps-src.css 92.2 KiB kbn-ui-shared-deps-src [emitted] kbn-ui-shared-deps-src
[ibazel] kbn-ui-shared-deps-src.css.map 120 KiB kbn-ui-shared-deps-src [emitted] [dev] kbn-ui-shared-deps-src
- [ibazel] kbn-ui-shared-deps-src.js 7.47 MiB kbn-ui-shared-deps-src [emitted] [big] kbn-ui-shared-deps-src
+ [ibazel] kbn-ui-shared-deps-src.js 8.97 MiB kbn-ui-shared-deps-src [emitted] [big] kbn-ui-shared-deps-src
- [ibazel] kbn-ui-shared-deps-src.js.map 6.5 MiB kbn-ui-shared-deps-src [emitted] [dev] kbn-ui-shared-deps-src
+ [ibazel] kbn-ui-shared-deps-src.js.map 8.01 MiB kbn-ui-shared-deps-src [emitted] [dev] kbn-ui-shared-deps-src Apparently part of the The good news is that overall this PR adds a whopping 12.8 Kb overall to the shared bundle. |
Managed to solve the bundle issue and will report here some things I found during the investigation which might be useful if somebody is facing the same problem with the shared bundle:
const symbolsLookup: Record<number, string> = Object.entries(esql_parser)
.filter(([k, v]) => typeof v === 'number' && !/RULE_/.test(k) && k.toUpperCase() === k)
.reduce((memo, [k, v]: [string, number]) => {
memo[v] = k;
return memo;
}, {} as Record<number, string>); The problem here was that the compiler didn't know what to keep and what to drop as the code was iterating thru everything there. The code was needed to map rule numbers to their string equivalent, but luckily there's a static property to use which makes the tree-shake work performantly: esql_parser.VOCABULARY.getSymbolicName(<tokenId>);
|
As discussed offline with @stratoula this PR now targets the new feature branch Once this PR will get reviewed (validation & hover) and merged into the new feature branch the following follow ups will be pursued:
|
💚 Build SucceededMetrics [docs]Public APIs missing comments
Async chunks
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
@@ -223,7 +223,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { | |||
}); | |||
}); | |||
|
|||
describe('ES|QL mode', () => { | |||
// @TODO: fix this in a follow up |
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 didn't realize this was going into a feature branch at first and was surprised to see these tests skipped, but assuming they'll be addressed and unskipped before making it to main
, this LGTM 👍
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.
Davis correct, we found some performance problems so this is not going to be merged. Also autocomplete doesnt work as expected. But as this is a big PR already we want to move this into a feature branch and then continue with the investigation and the development
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 discussed with Marco this is not ready to be merged and this is why we decided to create a feature branch instead. Specifically:
- autocomplete needs some refinement
- We should see what we are going to about making the client side validation performant. Currently we are hitting ES every 250ms and also we add another api call to Discover initialization
As a first step the code looks ok to me so I am approving the merge to the feature branch
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 think it would be great if you'd make your team the owner of kbn-monaco/src/esql :D
## Summary Fixes #166242 , #166876, #166173 , part of #166092, #166084 List of tasks: * [x] AST work ( #166185 ) * [x] Basic validate work ( #166185 ) * [x] Hover feature ( #166185 ) * [x] Initial autocomplete work with new AST ( #166185 ) * Complete validation feature for MVP * [x] wildcards support ( #170014 ) * [x] remote index validation support ( #171996 ) * [x] wildcard support as `count` argument ( #172054 ) * [x] Aggressive caching for field queries: * cache as much as possible the `FROM` queries - possible clear the cache every 10/15 minutes? * do not fire a query when code == submitted code * cache as much as possible the custom `FROM` built from `ENRICH` policies - same clear policy as above * [x] Add unsupported fields warning messages * [x] Notify usage of `project` command with deprecation `warning` * Complete autocomplete work ( #171664 ) * [x] `stats` * [x] `where` * [x] `eval` * `math syntax` * [x] Aggressive cache for fields queries? ( #171866 ) * [x] Fix when cursor is not at the end position ( #172060 ) * [x] Revisit copy messages * Label Kibana-only messages * [x] Extend hover feature ( #171940 ) * [x] Disable editor query highlight for warnings ( #171968 ) * Fix editor highlight with new grammar * [x] on multi-line ( #172080 ) * [x] for functions ( #172287 ) ## Release notes Enhance ES|QL query editing experience with client side validation. Enhance ES|QL suggestions experience with more in context suggestions leveraging field and variable types. Show meta informations on ES|QL query hover on policy names. Show function signature on ES|QL query hover on function text. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [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 - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co> Co-authored-by: Abdon Pijpelink <abdon.pijpelink@elastic.co>
Summary
Fixes #166242
This is a PR to use an higher level AST instead of the raw ParserTree to compute all Monaco features for ES|QL.
Grammar
This PR drops the existing grammar in favour of the ES one, which a tiny tweak in order to support any case for the query.
I think we could fully adopt the ES grammar without tweaks once this issue is resolved in the antlr4ts dependency.
The adoption of the ES grammar helped also to resolve #166173 .
AST generator
The AST is a subset of the ESQL grammar parser tree, which is easier to navigate.
Tests will be provided to the tool in order to test that the tool can translate even the craziest query string.
Note that this is not preventing the query to be submitted to ES: even if a validation case fails here or the AST fails to translate part of the expression ES will always have the last word about error and warnings, which will be promptly notified to the user.
Commands coverage:
ROW
ROW a=1
ROW a=1, b=1
FROM
FROM a
FROM a, b
FROM a [METADATA ...]
FROM a, b [METADATA ...]
METADATA
won't have indentifiers yetSHOW
INFO
FUNCTIONS
EVAL
EVAL a = b + 1
EVAL a = fnA( ... ) + fnB( ... )
EVAL b + 1
EVAL fnA( ... ) + fnB( ... )
STATS
STATS a = fn(b) + fn(c)
STATS a = fn(b) + fn(c) BY group
STATS a = fn(b) + fn(c) BY groupA, groupB
STATS fn(b) + fn(c)
STATS fn(b) + fn(c) BY groupA
STATS fn(b) + fn(c) BY groupA, groupB
WHERE
LIMIT
KEEP
PROJECT
DROP
RENAME
.RENAME a as b
RENAME
a + 1 / 5as
myField`DISSECT
GROK
ENRICH
MV_EXPAND
SORT
Collect all user defined variables
eval a = ...
)eval a + 1
)Validation
With this new approach it would be possible to catch most of warnings and errors while typing, preventing users to submit invalid queries to ES.
Note that here the validation function can detect multiple errors and warnings at once, while ES only returns one error at the time - improving the current sub-optimal editing experience provided.
Tasks
Autocomplete
Using the same provider here to provide better contextual suggestions.
First example giving better suggestions (filtered field based on types and functions based on returned type):
Hover
Basic hover information about used functions:
Things not covered in this PR
SHOW FUNCTIONS
at language bootstrapvalidate
function an independent module?Unknown <entity> [...]
messages)autocomplete
on par with the current state inmain
Validation cases not covered yet
... | eval var = 1 year
=> ❌ it should report an error... | eval 1 + [1, 2, 3]
=>-
,*
,/
,%
... | stats a = avg(field) | keep b
=> ❌b
should be reported as unknown... | keep a | eval b
=> ❌b
should be reported as unknown... | rename a as b, d as c, c as b
=> ❌c
should be reported as unknown... | enrich policy on fieldFromEnrich
=> ❌fieldFromEnrich
is not reported as unknown... | eval a = round(b), b = round(a)
=> ❌b
should be reported an unknownfrom ... [metadata <list of meta fields>
=> ❌meta fields
won't be validated as there's currently no available API to get themHover
Advanced usage of hover feature.
Signature
TBD