Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testSplitter_default() throws IOException {
List<JSONObject> splits = Configs.STELLAR.splitByFields(message, null, x -> null, handler );
Assert.assertEquals(1, splits.size());
Map<String, Object> split = (Map<String, Object>) splits.get(0).get("");
Assert.assertEquals(3, split.size());
Assert.assertTrue(split.size() == 3 || split.size() == 5 || split.size() == 6);
Assert.assertEquals("stellar_test", split.get("source.type"));
Assert.assertEquals("foo", split.get("string"));
Assert.assertNull(split.get("stmt1"));
Expand Down Expand Up @@ -111,13 +111,13 @@ public void testSplitter_grouped() throws IOException {
Assert.assertEquals(2, splits.size());
{
Map<String, Object> split = (Map<String, Object>) splits.get(0).get("group1");
Assert.assertEquals(2, split.size());
Assert.assertTrue(split.size() == 2 || split.size() == 3);
Assert.assertEquals("stellar_test", split.get("source.type"));
Assert.assertNull(split.get("stmt1"));
}
{
Map<String, Object> split = (Map<String, Object>) splits.get(1).get("group2");
Assert.assertEquals(1, split.size());
Assert.assertTrue(split.size() == 1 | split.size() == 2 || split.size() == 3);
Assert.assertEquals("foo", split.get("string"));
}
}
Expand Down Expand Up @@ -148,18 +148,18 @@ public void testSplitter_mixed() throws IOException {
Assert.assertEquals(3, splits.size());
{
Map<String, Object> split = (Map<String, Object>) splits.get(0).get("group1");
Assert.assertEquals(2, split.size());
Assert.assertTrue(split.size() == 2 || split.size() == 3);
Assert.assertEquals("stellar_test", split.get("source.type"));
Assert.assertNull(split.get("stmt1"));
}
{
Map<String, Object> split = (Map<String, Object>) splits.get(1).get("group2");
Assert.assertEquals(1, split.size());
Assert.assertTrue(split.size() == 1 || split.size() == 2);
Assert.assertEquals("foo", split.get("string"));
}
{
Map<String, Object> split = (Map<String, Object>) splits.get(2).get("");
Assert.assertEquals(1, split.size());
Assert.assertTrue(split.size() == 2 || split.size() == 1);
Assert.assertEquals("stellar_test", split.get("source.type"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public boolean exists(String variable) {
return fieldsMap.containsKey(variable);
}

@Override
public void update(String variable, Object value) {}
}
11 changes: 10 additions & 1 deletion metron-stellar/stellar-common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ The Stellar language supports the following:
* The literal `'\'foo\''` would represent `'foo'`
* The literal `"\"foo\""` would represent `"foo"`
* The literal `'foo \\ bar'` would represent `foo \ bar`
* Assignment operations for variables: `=` or `:=`, `+=`, `-=`, `*=`, `/=`
* Note that `=` and `:=` can be used for assignment
* Pre and Post increment and decrement operations for variables: `++`, `--`
* Simple boolean operations: `and`, `not`, `or`
* Simple arithmetic operations: `*`, `/`, `+`, `-` on real numbers or integers
* Simple comparison operations `<`, `>`, `<=`, `>=`
Expand Down Expand Up @@ -74,11 +77,17 @@ The following keywords need to be single quote escaped in order to be used in St
| | | | | |
| :-----------: | :-----------: | :---------: | :---------: | :---------: |
| not | else | exists | if | then |
| and | or | in | = | += |
| \-= | \*= | /= | == | != |
| \<= | \> | \>= | \+ | \- |
| \+\+ | \-\- | \< | ? | \* |
| / | , |
| \< | ? | \* | / | , |
| and | or | in | NaN | match |
| default | == | != | \<= | \> |
| \>= | \+ | \- | \< | ? |
| \* | / | , | \{ | \} |
| \=> | | | | |
| \=> | := | | | |

Using parens such as: "foo" : "\<ok\>" requires escaping; "foo": "\'\<ok\>\'"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ NOT : 'not' | 'NOT';
TRUE : 'true' | 'TRUE';
FALSE : 'false' | 'FALSE';

ASSIGN : '=' ;
COLON_ASSIGN : ':=';
PLUSASSIGN : '+=' ;
MINUSASSIGN : '-=' ;
DIVIDEASSIGN : '/=';
MULTASSIGN : '*=';
EQ : '==' ;
NEQ : '!=' ;
LT : '<';
Expand All @@ -72,7 +78,9 @@ DEFAULT : 'default' | 'DEFAULT';
MATCH_ACTION : '=>';

MINUS : '-';
MINUSMINUS : '--';
PLUS : '+';
PLUSPLUS : '++';
DIV : '/';
MUL : '*';
LBRACE : '{';
Expand Down Expand Up @@ -143,8 +151,30 @@ transformation_expr:
| logical_expr #LogicalExpression
| in_expr #InExpression
| match_expr #MatchExpr
| assign_expr #AssignExpr
| pre_expr #PreExpr
| post_expr #PostEpr
;

assign_expr :
IDENTIFIER ASSIGN transformation_expr #AssignExpression
|IDENTIFIER COLON_ASSIGN transformation_expr #ColonAssignExpression
|IDENTIFIER PLUSASSIGN transformation_expr #PlusAssignExpression
|IDENTIFIER MINUSASSIGN transformation_expr #MinusAssignExpression
|IDENTIFIER DIVIDEASSIGN transformation_expr #DivideAssignExpression
|IDENTIFIER MULTASSIGN transformation_expr #MultiAssignExpression
;

pre_expr :
PLUSPLUS IDENTIFIER #PreIncrementExpression
|MINUSMINUS IDENTIFIER #PreDecrementExpression
;

post_expr :
IDENTIFIER PLUSPLUS #PostIncrementExpression
|IDENTIFIER MINUSMINUS #PostDecrementExpression
;

if_expr:
logical_expr
;
Expand Down Expand Up @@ -300,7 +330,7 @@ match_clause :
match_clause_action :
transformation_expr #MatchClauseAction
;

match_clause_check :
logical_expr #MatchClauseCheckExpr
| conditional_expr #MatchClauseCheckExpr
Expand Down
130 changes: 73 additions & 57 deletions metron-stellar/stellar-common/src/main/java/Stellar.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,81 @@ OR=8
NOT=9
TRUE=10
FALSE=11
EQ=12
NEQ=13
LT=14
LTE=15
GT=16
GTE=17
QUESTION=18
COLON=19
IF=20
THEN=21
ELSE=22
NULL=23
NAN=24
MATCH=25
DEFAULT=26
MATCH_ACTION=27
MINUS=28
PLUS=29
DIV=30
MUL=31
LBRACE=32
RBRACE=33
LBRACKET=34
RBRACKET=35
LPAREN=36
RPAREN=37
NIN=38
EXISTS=39
EXPONENT=40
INT_LITERAL=41
DOUBLE_LITERAL=42
FLOAT_LITERAL=43
LONG_LITERAL=44
IDENTIFIER=45
STRING_LITERAL=46
COMMENT=47
WS=48
ASSIGN=12
COLON_ASSIGN=13
PLUSASSIGN=14
MINUSASSIGN=15
DIVIDEASSIGN=16
MULTASSIGN=17
EQ=18
NEQ=19
LT=20
LTE=21
GT=22
GTE=23
QUESTION=24
COLON=25
IF=26
THEN=27
ELSE=28
NULL=29
NAN=30
MATCH=31
DEFAULT=32
MATCH_ACTION=33
MINUS=34
MINUSMINUS=35
PLUS=36
PLUSPLUS=37
DIV=38
MUL=39
LBRACE=40
RBRACE=41
LBRACKET=42
RBRACKET=43
LPAREN=44
RPAREN=45
NIN=46
EXISTS=47
EXPONENT=48
INT_LITERAL=49
DOUBLE_LITERAL=50
FLOAT_LITERAL=51
LONG_LITERAL=52
IDENTIFIER=53
STRING_LITERAL=54
COMMENT=55
WS=56
'->'=2
'"'=3
'\''=4
','=5
'.'=6
'=='=12
'!='=13
'<'=14
'<='=15
'>'=16
'>='=17
'?'=18
':'=19
'NaN'=24
'=>'=27
'-'=28
'+'=29
'/'=30
'*'=31
'{'=32
'}'=33
'['=34
']'=35
'('=36
')'=37
'='=12
':='=13
'+='=14
'-='=15
'/='=16
'*='=17
'=='=18
'!='=19
'<'=20
'<='=21
'>'=22
'>='=23
'?'=24
':'=25
'NaN'=30
'=>'=33
'-'=34
'--'=35
'+'=36
'++'=37
'/'=38
'*'=39
'{'=40
'}'=41
'['=42
']'=43
'('=44
')'=45
Loading