Skip to content

Commit b761e53

Browse files
committed
[ES|QL] Enable the completion command as a tech preview feature (elastic#128948)
1 parent 3590a3c commit b761e53

File tree

14 files changed

+2048
-1906
lines changed

14 files changed

+2048
-1906
lines changed

docs/changelog/128948.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 128948
2+
summary: ES|QL - Add COMPLETION command as a tech preview feature
3+
area: ES|QL
4+
type: feature
5+
issues:
6+
- 124405

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ options {
5757
* they have on the UI (auto-completion, etc...)
5858
*/
5959

60+
COMPLETION : 'completion' -> pushMode(EXPRESSION_MODE);
6061
DISSECT : 'dissect' -> pushMode(EXPRESSION_MODE);
6162
DROP : 'drop' -> pushMode(PROJECT_MODE);
6263
ENRICH : 'enrich' -> pushMode(ENRICH_MODE);
@@ -86,7 +87,6 @@ CHANGE_POINT : 'change_point' -> pushMode(CHANGE_POINT_MODE);
8687
// Once the command has been stabilized, remove the DEV_ prefix and the {}? conditional and move the command to the
8788
// main section while preserving alphabetical order:
8889
// MYCOMMAND : 'mycommand' -> ...
89-
DEV_COMPLETION : {this.isDevVersion()}? 'completion' -> pushMode(EXPRESSION_MODE);
9090
DEV_INLINESTATS : {this.isDevVersion()}? 'inlinestats' -> pushMode(EXPRESSION_MODE);
9191
DEV_LOOKUP : {this.isDevVersion()}? 'lookup_🐔' -> pushMode(LOOKUP_MODE);
9292
DEV_METRICS : {this.isDevVersion()}? 'metrics' -> pushMode(METRICS_MODE);

x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.tokens

Lines changed: 38 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ processingCommand
5353
| mvExpandCommand
5454
| joinCommand
5555
| changePointCommand
56+
| completionCommand
5657
// in development
57-
| {this.isDevVersion()}? completionCommand
5858
| {this.isDevVersion()}? inlinestatsCommand
5959
| {this.isDevVersion()}? lookupCommand
6060
| {this.isDevVersion()}? rerankCommand
@@ -382,5 +382,5 @@ rerankCommand
382382
;
383383

384384
completionCommand
385-
: DEV_COMPLETION prompt=primaryExpression WITH inferenceId=identifierOrParameter (AS targetField=qualifiedName)?
385+
: COMPLETION prompt=primaryExpression WITH inferenceId=identifierOrParameter (AS targetField=qualifiedName)?
386386
;

x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.tokens

Lines changed: 38 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
lexer grammar Expression;
8+
9+
//
10+
// Expression - used by many commands
11+
//
12+
COMPLETION : 'completion' -> pushMode(EXPRESSION_MODE);
13+
DISSECT : 'dissect' -> pushMode(EXPRESSION_MODE);
14+
EVAL : 'eval' -> pushMode(EXPRESSION_MODE);
15+
GROK : 'grok' -> pushMode(EXPRESSION_MODE);
16+
LIMIT : 'limit' -> pushMode(EXPRESSION_MODE);
17+
ROW : 'row' -> pushMode(EXPRESSION_MODE);
18+
SORT : 'sort' -> pushMode(EXPRESSION_MODE);
19+
STATS : 'stats' -> pushMode(EXPRESSION_MODE);
20+
WHERE : 'where' -> pushMode(EXPRESSION_MODE);
21+
22+
DEV_INLINESTATS : {this.isDevVersion()}? 'inlinestats' -> pushMode(EXPRESSION_MODE);
23+
DEV_RERANK : {this.isDevVersion()}? 'rerank' -> pushMode(EXPRESSION_MODE);
24+
DEV_SAMPLE : {this.isDevVersion()}? 'sample' -> pushMode(EXPRESSION_MODE);
25+
26+
27+
mode EXPRESSION_MODE;
28+
29+
PIPE : '|' -> popMode;
30+
31+
fragment DIGIT
32+
: [0-9]
33+
;
34+
35+
fragment LETTER
36+
: [a-z]
37+
;
38+
39+
fragment ESCAPE_SEQUENCE
40+
: '\\' [tnr"\\]
41+
;
42+
43+
fragment UNESCAPED_CHARS
44+
: ~[\r\n"\\]
45+
;
46+
47+
fragment EXPONENT
48+
: [e] [+-]? DIGIT+
49+
;
50+
51+
fragment ASPERAND
52+
: '@'
53+
;
54+
55+
fragment BACKQUOTE
56+
: '`'
57+
;
58+
59+
fragment BACKQUOTE_BLOCK
60+
: ~'`'
61+
| '``'
62+
;
63+
64+
fragment UNDERSCORE
65+
: '_'
66+
;
67+
68+
fragment UNQUOTED_ID_BODY
69+
: (LETTER | DIGIT | UNDERSCORE)
70+
;
71+
72+
QUOTED_STRING
73+
: '"' (ESCAPE_SEQUENCE | UNESCAPED_CHARS)* '"'
74+
| '"""' (~[\r\n])*? '"""' '"'? '"'?
75+
;
76+
77+
INTEGER_LITERAL
78+
: DIGIT+
79+
;
80+
81+
DECIMAL_LITERAL
82+
: DIGIT+ DOT DIGIT*
83+
| DOT DIGIT+
84+
| DIGIT+ (DOT DIGIT*)? EXPONENT
85+
| DOT DIGIT+ EXPONENT
86+
;
87+
88+
89+
AND : 'and';
90+
AS: 'as';
91+
ASC : 'asc';
92+
ASSIGN : '=';
93+
BY : 'by';
94+
CAST_OP : '::';
95+
COLON : ':';
96+
COMMA : ',';
97+
DESC : 'desc';
98+
DOT : '.';
99+
FALSE : 'false';
100+
FIRST : 'first';
101+
IN: 'in';
102+
IS: 'is';
103+
LAST : 'last';
104+
LIKE: 'like';
105+
NOT : 'not';
106+
NULL : 'null';
107+
NULLS : 'nulls';
108+
ON: 'on';
109+
OR : 'or';
110+
PARAM: '?';
111+
RLIKE: 'rlike';
112+
TRUE : 'true';
113+
WITH: 'with';
114+
115+
EQ : '==';
116+
CIEQ : '=~';
117+
NEQ : '!=';
118+
LT : '<';
119+
LTE : '<=';
120+
GT : '>';
121+
GTE : '>=';
122+
123+
PLUS : '+';
124+
MINUS : '-';
125+
ASTERISK : '*';
126+
SLASH : '/';
127+
PERCENT : '%';
128+
129+
LEFT_BRACES : '{';
130+
RIGHT_BRACES : '}';
131+
132+
DOUBLE_PARAMS: '??';
133+
134+
NESTED_WHERE : WHERE -> type(WHERE);
135+
136+
NAMED_OR_POSITIONAL_PARAM
137+
: PARAM (LETTER | UNDERSCORE) UNQUOTED_ID_BODY*
138+
| PARAM DIGIT+
139+
;
140+
141+
NAMED_OR_POSITIONAL_DOUBLE_PARAMS
142+
: DOUBLE_PARAMS (LETTER | UNDERSCORE) UNQUOTED_ID_BODY*
143+
| DOUBLE_PARAMS DIGIT+
144+
;
145+
146+
// Brackets are funny. We can happen upon a CLOSING_BRACKET in two ways - one
147+
// way is to start in an explain command which then shifts us to expression
148+
// mode. Thus, the two popModes on CLOSING_BRACKET. The other way could as
149+
// the start of a multivalued field constant. To line up with the double pop
150+
// the explain mode needs, we double push when we see that.
151+
OPENING_BRACKET : '[' -> pushMode(EXPRESSION_MODE), pushMode(EXPRESSION_MODE);
152+
CLOSING_BRACKET : ']' -> popMode, popMode;
153+
154+
LP : '(' -> pushMode(EXPRESSION_MODE), pushMode(EXPRESSION_MODE);
155+
RP : ')' -> popMode, popMode;
156+
157+
UNQUOTED_IDENTIFIER
158+
: LETTER UNQUOTED_ID_BODY*
159+
// only allow @ at beginning of identifier to keep the option to allow @ as infix operator in the future
160+
// also, single `_` and `@` characters are not valid identifiers
161+
| (UNDERSCORE | ASPERAND) UNQUOTED_ID_BODY+
162+
;
163+
164+
fragment QUOTED_ID
165+
: BACKQUOTE BACKQUOTE_BLOCK+ BACKQUOTE
166+
;
167+
168+
QUOTED_IDENTIFIER
169+
: QUOTED_ID
170+
;
171+
172+
EXPR_LINE_COMMENT
173+
: LINE_COMMENT -> channel(HIDDEN)
174+
;
175+
176+
EXPR_MULTILINE_COMMENT
177+
: MULTILINE_COMMENT -> channel(HIDDEN)
178+
;
179+
180+
EXPR_WS
181+
: WS -> channel(HIDDEN)
182+
;

0 commit comments

Comments
 (0)