Skip to content

Commit

Permalink
[ES|QL] Add date math syntax and autocomplete support (elastic#166058)
Browse files Browse the repository at this point in the history
## Summary

This PR adds support for date math in ES|QL providing an improved
autocompleting feature for the `EVAL` command:

* ✨ auto close brackets in monaco


![esql_date_math_support_autoclose](https://github.com/elastic/kibana/assets/924948/657a52e5-20ce-46e6-a138-b1f58184db27)


* ✨ support date math syntax
* ✨ improve EVAL autocomplete in various ways
* provide date duration suggestions with single unit after math
operations
* provide date duration suggestions if quantifier has been declared
already
* provide math signs based on context ( if `EVAL` is in duration mode
just `+`, `-`, otherwise all 4)
* provide math commands based on context (if `EVAL` is in duration mode
only functions who return a date, otherwise all of them)
* provide date duration suggestions only when `EVAL` is in duration mode
* provide date duration suggestions as first argument for date supported
functions
  * extended grammar to support also plural versions of duration units


![esql_date_math_support](https://github.com/elastic/kibana/assets/924948/7bf48265-1c47-45ac-a345-2dd320c8e431)


### 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]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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
  • Loading branch information
dej611 authored Sep 11, 2023
1 parent 93ba71c commit 2b10197
Show file tree
Hide file tree
Showing 14 changed files with 1,669 additions and 1,203 deletions.
10 changes: 10 additions & 0 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ DATE_LITERAL
| 'second'
| 'minute'
| 'hour'
| 'week'
| 'millisecond'
| 'years'
| 'months'
| 'days'
| 'seconds'
| 'minutes'
| 'hours'
| 'weeks'
| 'milliseconds'
;

AND : 'and';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-monaco/src/esql/antlr/esql_lexer.interp

Large diffs are not rendered by default.

973 changes: 503 additions & 470 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.ts

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion packages/kbn-monaco/src/esql/antlr/esql_parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ mathEvalFn
: mathFunctionIdentifier LP (mathFunctionExpressionArgument (COMMA mathFunctionExpressionArgument)*)? RP
;

dateExpression
: quantifier=number DATE_LITERAL
;

operatorExpression
: primaryExpression
| mathFn
Expand All @@ -110,6 +114,7 @@ operatorExpression
primaryExpression
: constant
| qualifiedName
| dateExpression
| LP booleanExpression RP
| identifier LP (booleanExpression (COMMA booleanExpression)*)? RP
;
Expand Down Expand Up @@ -173,7 +178,7 @@ mathFunctionExpressionArgument
| string
| number
| operatorExpression
| number (DATE_LITERAL)
| dateExpression
| comparison
;

Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-monaco/src/esql/antlr/esql_parser.interp

Large diffs are not rendered by default.

Loading

0 comments on commit 2b10197

Please sign in to comment.