Skip to content

Commit 6ff0e41

Browse files
authored
EQL: backport updates to 7.x (#51940)
1 parent 3be70f6 commit 6ff0e41

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4071
-1664
lines changed

x-pack/plugin/eql/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
testCompile project(':test:framework')
2828
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
2929
testCompile project(path: xpackModule('security'), configuration: 'testArtifacts')
30+
testCompile project(path: xpackModule('ql'), configuration: 'testArtifacts')
3031
testCompile project(path: ':modules:reindex', configuration: 'runtime')
3132
testCompile project(path: ':modules:parent-join', configuration: 'runtime')
3233
testCompile project(path: ':modules:analysis-common', configuration: 'runtime')

x-pack/plugin/eql/src/main/antlr/EqlBase.g4

Lines changed: 80 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
grammar EqlBase;
88

9-
tokens {
10-
DELIMITER
11-
}
129

1310
singleStatement
1411
: statement EOF
@@ -19,45 +16,54 @@ singleExpression
1916
;
2017

2118
statement
22-
: query (PIPE pipe)*
19+
: query pipe*
2320
;
24-
21+
2522
query
2623
: sequence
2724
| join
28-
| condition
25+
| eventQuery
26+
;
27+
28+
sequenceParams
29+
: WITH (MAXSPAN EQ timeUnit)
2930
;
30-
31+
3132
sequence
32-
: SEQUENCE (by=joinKeys)? (span)?
33-
match+
34-
(UNTIL match)?
33+
: SEQUENCE (by=joinKeys sequenceParams? | sequenceParams by=joinKeys?)?
34+
sequenceTerm sequenceTerm+
35+
(UNTIL sequenceTerm)?
3536
;
3637

3738
join
3839
: JOIN (by=joinKeys)?
39-
match+
40-
(UNTIL match)?
40+
joinTerm joinTerm+
41+
(UNTIL joinTerm)?
4142
;
4243

4344
pipe
44-
: kind=IDENTIFIER (booleanExpression (COMMA booleanExpression)*)?
45+
: PIPE kind=IDENTIFIER (booleanExpression (COMMA booleanExpression)*)?
4546
;
4647

48+
4749
joinKeys
48-
: BY qualifiedNames
49-
;
50-
51-
span
52-
: WITH MAXSPAN EQ DIGIT_IDENTIFIER
50+
: BY expression (COMMA expression)*
5351
;
5452

55-
match
56-
: LB condition RB (by=joinKeys)?
53+
joinTerm
54+
: subquery (by=joinKeys)?
55+
;
56+
57+
sequenceTerm
58+
: subquery (FORK (EQ booleanValue)?)? (by=joinKeys)?
59+
;
60+
61+
subquery
62+
: LB eventQuery RB
5763
;
5864

59-
condition
60-
: event=qualifiedName WHERE expression
65+
eventQuery
66+
: event=identifier WHERE expression
6167
;
6268

6369
expression
@@ -66,34 +72,28 @@ expression
6672

6773
booleanExpression
6874
: NOT booleanExpression #logicalNot
69-
| predicated #booleanDefault
75+
| relationship=IDENTIFIER OF subquery #processCheck
76+
| valueExpression #booleanDefault
7077
| left=booleanExpression operator=AND right=booleanExpression #logicalBinary
7178
| left=booleanExpression operator=OR right=booleanExpression #logicalBinary
7279
;
7380

74-
// workaround for:
75-
// https://github.com/antlr/antlr4/issues/780
76-
// https://github.com/antlr/antlr4/issues/781
77-
predicated
78-
: valueExpression predicate?
79-
;
80-
81-
// dedicated calls for each branch are not used to reuse the NOT handling across them
82-
// instead the property kind is used for differentiation
83-
predicate
84-
: NOT? kind=BETWEEN lower=valueExpression AND upper=valueExpression
85-
| NOT? kind=IN LP valueExpression (COMMA valueExpression)* RP
86-
| NOT? kind=IN LP query RP
87-
;
8881

8982
valueExpression
90-
: primaryExpression #valueExpressionDefault
83+
: primaryExpression predicate? #valueExpressionDefault
9184
| operator=(MINUS | PLUS) valueExpression #arithmeticUnary
9285
| left=valueExpression operator=(ASTERISK | SLASH | PERCENT) right=valueExpression #arithmeticBinary
9386
| left=valueExpression operator=(PLUS | MINUS) right=valueExpression #arithmeticBinary
9487
| left=valueExpression comparisonOperator right=valueExpression #comparison
9588
;
9689

90+
// workaround for
91+
// https://github.com/antlr/antlr4/issues/780
92+
// https://github.com/antlr/antlr4/issues/781
93+
predicate
94+
: NOT? kind=IN LP expression (COMMA expression)* RP
95+
;
96+
9797
primaryExpression
9898
: constant #constantDefault
9999
| functionExpression #function
@@ -102,14 +102,14 @@ primaryExpression
102102
;
103103

104104
functionExpression
105-
: identifier LP (expression (COMMA expression)*)? RP
105+
: name=IDENTIFIER LP (expression (COMMA expression)*)? RP
106106
;
107107

108108
constant
109109
: NULL #nullLiteral
110110
| number #numericLiteral
111111
| booleanValue #booleanLiteral
112-
| STRING+ #stringLiteral
112+
| string #stringLiteral
113113
;
114114

115115
comparisonOperator
@@ -120,26 +120,17 @@ booleanValue
120120
: TRUE | FALSE
121121
;
122122

123-
qualifiedNames
124-
: qualifiedName (COMMA qualifiedName)*
125-
;
126-
127123
qualifiedName
128-
: (identifier DOT)* identifier
124+
: identifier (DOT identifier | LB INTEGER_VALUE+ RB)*
129125
;
130126

131127
identifier
132-
: quoteIdentifier
133-
| unquoteIdentifier
128+
: IDENTIFIER
129+
| ESCAPED_IDENTIFIER
134130
;
135131

136-
quoteIdentifier
137-
: QUOTED_IDENTIFIER #quotedIdentifier
138-
;
139-
140-
unquoteIdentifier
141-
: IDENTIFIER #unquotedIdentifier
142-
| DIGIT_IDENTIFIER #digitIdentifier
132+
timeUnit
133+
: number unit=IDENTIFIER?
143134
;
144135

145136
number
@@ -151,31 +142,26 @@ string
151142
: STRING
152143
;
153144

154-
AND: 'AND';
155-
ANY: 'ANY';
156-
ASC: 'ASC';
157-
BETWEEN: 'BETWEEN';
158-
BY: 'BY';
159-
CHILD: 'CHILD';
160-
DESCENDANT: 'DESCENDANT';
161-
EVENT: 'EVENT';
162-
FALSE: 'FALSE';
163-
IN: 'IN';
164-
JOIN: 'JOIN';
165-
MAXSPAN: 'MAXSPAN';
166-
NOT: 'NOT';
167-
NULL: 'NULL';
168-
OF: 'OF';
169-
OR: 'OR';
170-
SEQUENCE: 'SEQUENCE';
171-
TRUE: 'TRUE';
172-
UNTIL: 'UNTIL';
173-
WHERE: 'WHERE';
174-
WITH: 'WITH';
145+
AND: 'and';
146+
BY: 'by';
147+
FALSE: 'false';
148+
FORK: 'fork';
149+
IN: 'in';
150+
JOIN: 'join';
151+
MAXSPAN: 'maxspan';
152+
NOT: 'not';
153+
NULL: 'null';
154+
OF: 'of';
155+
OR: 'or';
156+
SEQUENCE: 'sequence';
157+
TRUE: 'true';
158+
UNTIL: 'until';
159+
WHERE: 'where';
160+
WITH: 'with';
175161

176162
// Operators
177163
EQ : '=' | '==';
178-
NEQ : '<>' | '!=';
164+
NEQ : '!=';
179165
LT : '<';
180166
LTE : '<=';
181167
GT : '>';
@@ -194,9 +180,16 @@ LP: '(';
194180
RP: ')';
195181
PIPE: '|';
196182

183+
184+
ESCAPED_IDENTIFIER
185+
: '`' (~'`')* '`'
186+
;
187+
197188
STRING
198-
: '\'' ( ~'\'')* '\''
199-
| '"' ( ~'"' )* '"'
189+
: '\'' ('\\' [btnfr"'\\] | ~[\r\n'\\])* '\''
190+
| '"' ('\\' [btnfr"'\\] | ~[\r\n"\\])* '"'
191+
| '?"' ('\\"' |~["\r\n])* '"'
192+
| '?\'' ('\\\'' |~['\r\n])* '\''
200193
;
201194
202195
INTEGER_VALUE
@@ -210,31 +203,24 @@ DECIMAL_VALUE
210203
| DOT DIGIT+ EXPONENT
211204
;
212205
206+
// make @timestamp not require escaping, since @ has no other meaning
213207
IDENTIFIER
214-
: (LETTER | '_') (LETTER | DIGIT | '_' | '@' )*
215-
;
216-
217-
DIGIT_IDENTIFIER
218-
: DIGIT (LETTER | DIGIT | '_' | '@')+
208+
: (LETTER | '_' | '@') (LETTER | DIGIT | '_')*
219209
;
220210
221-
QUOTED_IDENTIFIER
222-
: '"' ( ~'"' | '""' )* '"'
223-
;
224-
225211
fragment EXPONENT
226-
: 'E' [+-]? DIGIT+
212+
: [Ee] [+-]? DIGIT+
227213
;
228214
229215
fragment DIGIT
230216
: [0-9]
231217
;
232218
233219
fragment LETTER
234-
: [A-Z]
220+
: [A-Za-z]
235221
;
236222
237-
SIMPLE_COMMENT
223+
LINE_COMMENT
238224
: '//' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN)
239225
;
240226
@@ -246,9 +232,12 @@ WS
246232
: [ \r\n\t]+ -> channel(HIDDEN)
247233
;
248234
235+
249236
// Catch-all for anything we can't recognize.
250237
// We use this to be able to ignore and recover all the text
251238
// when splitting statements with DelimiterLexer
239+
/*
252240
UNRECOGNIZED
253241
: .
254-
;
242+
;
243+
*/

x-pack/plugin/eql/src/main/antlr/EqlBase.tokens

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)