Skip to content
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

Merged
merged 64 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
5e42f97
:sparkles: Initial draft of esql ast
dej611 Sep 11, 2023
cc01d6d
:sparkles: Merge errors from client and server
dej611 Sep 12, 2023
62e1ecc
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Sep 13, 2023
a44b130
:construction: AST WIP
dej611 Sep 18, 2023
2c02a9f
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Sep 18, 2023
4d7b2bb
:sparkles: Add client side ESQL validation
dej611 Sep 21, 2023
8caf186
:label: Refactor error logic to leverage types
dej611 Sep 21, 2023
c3ecc29
:fire: Remove unused types
dej611 Sep 21, 2023
26d104c
Merge branch 'main' into feature/esql-to-ast
dej611 Sep 21, 2023
1eece8a
:fire: Remove unused commands
dej611 Sep 21, 2023
4a7d221
:fire: Remove type
dej611 Sep 21, 2023
64f57c5
:sparkles: Plug autocomplete to the new system
dej611 Sep 22, 2023
db10a70
:sparkles: Include syntax errors within the regular editor flow
dej611 Oct 2, 2023
3d03335
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 2, 2023
5d0f732
:sparkles: Improve validation
dej611 Oct 10, 2023
4ef449c
:sparkles: Tested all combinations
dej611 Oct 11, 2023
257bcab
:wrench: Tweak namespace
dej611 Oct 11, 2023
e966cc4
:bug: Fix type and load ast handler at runtime
dej611 Oct 11, 2023
a7b5b2a
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 12, 2023
fac6743
:bug: Fix test for mv_expand
dej611 Oct 12, 2023
6ba78ce
:sparkles: Autocomplete ast-based with initial tests
dej611 Oct 13, 2023
185e60d
:label: Fix types
dej611 Oct 13, 2023
cc14363
:fire: Remove unused provider
dej611 Oct 16, 2023
56dd04c
:label: Reduce non-type imports
dej611 Oct 16, 2023
7671dc0
:sparkles: Add treeshake
dej611 Oct 16, 2023
a6cf75c
:label: Fix type
dej611 Oct 16, 2023
5bca6f2
:bug: Fix check issues
dej611 Oct 16, 2023
d992e5f
:bug: Fix typo
dej611 Oct 16, 2023
7ba9dc0
:white_check_mark: Add more tests
dej611 Oct 16, 2023
aaa0ca6
:bug: Fix query handling
dej611 Oct 16, 2023
7027a87
:sparkles: Fix enrich test cases
dej611 Oct 16, 2023
e060019
:sparkles: Add basic hover
dej611 Oct 16, 2023
6785a8d
:bug: Fix validation for show and stats
dej611 Oct 16, 2023
d5fddae
:bug: Fix suggestions for stats + add hover
dej611 Oct 16, 2023
b3e0297
:bug: Fix tests
dej611 Oct 16, 2023
4cf08cc
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 16, 2023
6f2b10a
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 17, 2023
2fde17f
:recycle: Refactor ast code
dej611 Oct 17, 2023
af3500b
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 17, 2023
449e835
:bug: Fix missing import
dej611 Oct 17, 2023
669cbd7
Merge branch 'feature/esql-to-ast' of https://github.com/dej611/kiban…
dej611 Oct 17, 2023
5153857
:bug: Fix import
dej611 Oct 17, 2023
c5b3471
:bug: Last import fix
dej611 Oct 17, 2023
cbe3be6
:bug: Fix duplicate id
dej611 Oct 17, 2023
b9f99e5
:bug: Fix typo
dej611 Oct 17, 2023
4957f47
:fire: Remove unused translations
dej611 Oct 17, 2023
67dba6e
:rotating_light: Fix linting issues
dej611 Oct 17, 2023
d4b3425
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 17, 2023
b33396a
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 17, 2023
06095eb
:white_check_mark: Fix tests
dej611 Oct 17, 2023
7ba2ebc
:fire: Remove treeshake flag for now
dej611 Oct 17, 2023
fcc42cb
Merge branch 'feature/esql-to-ast' of https://github.com/dej611/kiban…
dej611 Oct 17, 2023
b30f77b
:recycle: Refactor import
dej611 Oct 17, 2023
a9380e2
Merge branch 'main' into feature/esql-to-ast
dej611 Oct 18, 2023
4219638
:fire: Shrink more code
dej611 Oct 18, 2023
c0927d9
Merge branch 'feature/esql-to-ast' of https://github.com/dej611/kiban…
dej611 Oct 18, 2023
8ec2226
:bug: Fix fuzzy match on indices
dej611 Oct 18, 2023
9acd436
:bug: Fix debounce and warning UI bugs
dej611 Oct 18, 2023
d7c4b75
Merge remote-tracking branch 'upstream/main' into feature/esql-to-ast
dej611 Oct 18, 2023
121a6df
:recycle: Shuffle a bit bundles to have more async
dej611 Oct 18, 2023
c293b55
:recycle: Shuffle the architecture to restore previous chunk organiza…
dej611 Oct 19, 2023
a573197
:bug: Fix tests
dej611 Oct 19, 2023
4e4222b
:mute: Mute the test for now
dej611 Oct 23, 2023
5f5c9d2
Merge branch 'feature/esql-validation' into feature/esql-to-ast
dej611 Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kbn-monaco/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { monaco } from './src/monaco_imports';
export { XJsonLang } from './src/xjson';
export { SQLLang } from './src/sql';
export { ESQL_LANG_ID, ESQL_THEME_ID, ESQLLang } from './src/esql';
export type { ESQLCustomAutocompleteCallbacks } from './src/esql';
export type { ESQLCallbacks } from './src/esql';

export * from './src/painless';
/* eslint-disable-next-line @kbn/eslint/module_migration */
Expand Down
244 changes: 50 additions & 194 deletions packages/kbn-monaco/src/esql/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

lexer grammar esql_lexer;
options { }

DISSECT : D I S S E C T -> pushMode(EXPRESSION);
GROK : G R O K -> pushMode(EXPRESSION);
DROP : D R O P -> pushMode(SOURCE_IDENTIFIERS);
ENRICH : E N R I C H -> pushMode(SOURCE_IDENTIFIERS);
EVAL : E V A L -> pushMode(EXPRESSION);
EXPLAIN : E X P L A I N -> pushMode(EXPLAIN_MODE);
FROM : F R O M -> pushMode(SOURCE_IDENTIFIERS);
GROK : G R O K -> pushMode(EXPRESSION);
KEEP : K E E P -> pushMode(SOURCE_IDENTIFIERS);
LIMIT : L I M I T -> pushMode(EXPRESSION);
MV_EXPAND : M V UNDERSCORE E X P A N D -> pushMode(SOURCE_IDENTIFIERS);
PROJECT : P R O J E C T -> pushMode(SOURCE_IDENTIFIERS);
RENAME : R E N A M E -> pushMode(SOURCE_IDENTIFIERS);
ROW : R O W -> pushMode(EXPRESSION);
SHOW : S H O W -> pushMode(EXPRESSION);
SORT : S O R T -> pushMode(EXPRESSION);
STATS : S T A T S -> pushMode(EXPRESSION);
WHERE : W H E R E -> pushMode(EXPRESSION);
SORT : S O R T -> pushMode(EXPRESSION);
MV_EXPAND : M V UNDERSCORE E X P A N D -> pushMode(EXPRESSION);
LIMIT : L I M I T -> pushMode(EXPRESSION);
PROJECT : P R O J E C T -> pushMode(EXPRESSION);
DROP : D R O P -> pushMode(EXPRESSION);
RENAME : R E N A M E -> pushMode(EXPRESSION);
SHOW : S H O W -> pushMode(EXPRESSION);
ENRICH : E N R I C H -> pushMode(ENRICH_IDENTIFIERS);
KEEP : K E E P -> pushMode(EXPRESSION);
UNKNOWN_CMD : ~[ \r\n\t[\]/]+ -> pushMode(EXPRESSION);

LINE_COMMENT
: '//' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
Expand All @@ -36,12 +37,7 @@ MULTILINE_COMMENT
WS
: [ \r\n\t]+ -> channel(HIDDEN)
;
mode EXPLAIN_MODE;
EXPLAIN_OPENING_BRACKET : '[' -> type(OPENING_BRACKET), pushMode(DEFAULT_MODE);
EXPLAIN_PIPE : '|' -> type(PIPE), popMode;
EXPLAIN_WS : WS -> channel(HIDDEN);
EXPLAIN_LINE_COMMENT : LINE_COMMENT -> channel(HIDDEN);
EXPLAIN_MULTILINE_COMMENT : MULTILINE_COMMENT -> channel(HIDDEN);

mode EXPRESSION;

PIPE : '|' -> popMode;
Expand Down Expand Up @@ -82,169 +78,60 @@ DECIMAL_LITERAL
| DOT DIGIT+ EXPONENT
;

BY : 'by';

DATE_LITERAL
: 'year'
| 'month'
| 'day'
| 'second'
| 'minute'
| 'hour'
| 'week'
| 'millisecond'
| 'years'
| 'months'
| 'days'
| 'seconds'
| 'minutes'
| 'hours'
| 'weeks'
| 'milliseconds'
;
BY : B Y;

AND : 'and';
AND : A N D;
ASC : A S C;
ASSIGN : '=';
COMMA : ',';
DESC : D E S C;
DOT : '.';
FALSE : F A L S E;
FIRST : F I R S T;
LAST : L A S T;
LP : '(';
OPENING_BRACKET : '[' -> pushMode(EXPRESSION), pushMode(EXPRESSION);
CLOSING_BRACKET : ']' -> popMode, popMode;
NOT : N O T;
LIKE: L I K E;
RLIKE: R L I K E;
IN: I N;
IS: I S;
AS: A S;
LIKE: L I K E;
NOT : N O T;
NULL : N U L L;
OR : 'or';
NULLS : N U L L S;
OR : O R;
PARAM: '?';
RLIKE: R L I K E;
RP : ')';
TRUE : T R U E;
INFO : I N F O;
FUNCTIONS : F U N C T I O N S;
UNDERSCORE: '_';
INFO : 'info';
FUNCTIONS : 'functions';

BOOLEAN_VALUE
: 'true'
| 'false'
;

COMPARISON_OPERATOR
: '=='
|'!='
| '<'
| '<='
| '>'
| '>='
;

EQ : '==';
NEQ : '!=';
LT : '<';
LTE : '<=';
GT : '>';
GTE : '>=';

PLUS : '+';
MINUS : '-';
ASTERISK : '*';
SLASH : '/';
PERCENT : '%';
TEN: '10';

ORDERING
: 'asc'
| 'desc'
;

NULLS_ORDERING: 'nulls';
NULLS_ORDERING_DIRECTION
: 'first'
| 'last'
;

MATH_FUNCTION
: R O U N D
| A B S
| P O W
| L O G TEN
| P I
| T A U
| E
| S U B S T R I N G
| T R I M
| C O N C A T
| C O A L E S C E
| G R E A T E S T
| L E F T
| N O W
| R I G H T
| S T A R T S UNDERSCORE W I T H
| D A T E UNDERSCORE F O R M A T
| D A T E UNDERSCORE T R U N C
| D A T E UNDERSCORE P A R S E
| A U T O UNDERSCORE B U C K E T
| D A T E UNDERSCORE E X T R A C T
| I S UNDERSCORE F I N I T E
| I S UNDERSCORE I N F I N I T E
| C A S E
| L E N G T H
| M V UNDERSCORE M A X
| M V UNDERSCORE M I N
| M V UNDERSCORE A V G
| M V UNDERSCORE S U M
| M V UNDERSCORE C O U N T
| M V UNDERSCORE C O N C A T
| M V UNDERSCORE J O I N
| M V UNDERSCORE M E D I A N
| M V UNDERSCORE D E D U P E
| M E T A D A T A
| S P L I T
| T O UNDERSCORE S T R I N G
| T O UNDERSCORE S T R
| T O UNDERSCORE B O O L
| T O UNDERSCORE B O O L E A N
| T O UNDERSCORE D A T E T I M E
| T O UNDERSCORE D T
| T O UNDERSCORE D B L
| T O UNDERSCORE D O U B L E
| T O UNDERSCORE D E G R E E S
| T O UNDERSCORE I N T
| T O UNDERSCORE I N T E G E R
| T O UNDERSCORE I P
| T O UNDERSCORE L O N G
| T O UNDERSCORE R A D I A N S
| T O UNDERSCORE V E R S I O N
| T O UNDERSCORE U N S I G N E D UNDERSCORE L O N G
;

UNARY_FUNCTION
: A V G
| M I N
| M A X
| S U M
| C O U N T
| C O U N T UNDERSCORE D I S T I N C T
| P E R C E N T I L E
| M E D I A N
| M E D I A N UNDERSCORE A B S O L U T E UNDERSCORE D E V I A T I O N
| A C O S
| A S I N
| A T A N
| A T A N '2'
| C E I L
| C O S
| C O S H
| F L O O R
| L T R I M
| S I N
| S I N H
| S Q R T
| T A N
| T A N H
;
// Brackets are funny. We can happen upon a CLOSING_BRACKET in two ways - one
// way is to start in an explain command which then shifts us to expression
// mode. Thus, the two popModes on CLOSING_BRACKET. The other way could as
// the start of a multivalued field constant. To line up with the double pop
// the explain mode needs, we double push when we see that.
OPENING_BRACKET : '[' -> pushMode(EXPRESSION), pushMode(EXPRESSION);
CLOSING_BRACKET : ']' -> popMode, popMode;

WHERE_FUNCTIONS
: C I D R UNDERSCORE M A T C H
;

UNQUOTED_IDENTIFIER
: LETTER (LETTER | DIGIT | '_' | ASTERISK)*
: LETTER (LETTER | DIGIT | '_')*
// only allow @ at beginning of identifier to keep the option to allow @ as infix operator in the future
// also, single `_` and `@` characters are not valid identifiers
| ('_' | '@') (LETTER | DIGIT | '_' | ASTERISK)+
| ('_' | '@') (LETTER | DIGIT | '_')+
;

QUOTED_IDENTIFIER
Expand All @@ -264,14 +151,18 @@ EXPR_WS
;



mode SOURCE_IDENTIFIERS;

SRC_PIPE : '|' -> type(PIPE), popMode;
SRC_OPENING_BRACKET : '[' -> type(OPENING_BRACKET), pushMode(SOURCE_IDENTIFIERS), pushMode(SOURCE_IDENTIFIERS);
SRC_CLOSING_BRACKET : ']' -> popMode, popMode, type(CLOSING_BRACKET);
SRC_COMMA : ',' -> type(COMMA);
SRC_ASSIGN : '=' -> type(ASSIGN);
AS : A S;
METADATA: M E T A D A T A;
ON : O N;
WITH : W I T H;

SRC_UNQUOTED_IDENTIFIER
: SRC_UNQUOTED_IDENTIFIER_PART+
Expand All @@ -298,41 +189,6 @@ SRC_WS
: WS -> channel(HIDDEN)
;

mode ENRICH_IDENTIFIERS;

ON : O N;
WITH : W I T H;

ENR_PIPE : '|' -> type(PIPE), popMode;
ENR_CLOSING_BRACKET : ']' -> popMode, popMode, type(CLOSING_BRACKET);
ENR_COMMA : ',' -> type(COMMA);
ENR_ASSIGN : '=' -> type(ASSIGN);

ENR_UNQUOTED_IDENTIFIER
: ENR_UNQUOTED_IDENTIFIER_PART+
;

fragment ENR_UNQUOTED_IDENTIFIER_PART
: ~[=`|,[\]/ \t\r\n]+
| '/' ~[*/] // allow single / but not followed by another / or * which would start a comment
;

ENR_QUOTED_IDENTIFIER
: QUOTED_IDENTIFIER
;

ENR_LINE_COMMENT
: LINE_COMMENT -> channel(HIDDEN)
;

ENR_MULTILINE_COMMENT
: MULTILINE_COMMENT -> channel(HIDDEN)
;

ENR_WS
: WS -> channel(HIDDEN)
;

fragment A : [aA]; // match either an 'a' or 'A'
fragment B : [bB];
fragment C : [cC];
Expand Down
Loading
Loading