-
Notifications
You must be signed in to change notification settings - Fork 2
/
DSL-syntax.txt
115 lines (72 loc) · 2.57 KB
/
DSL-syntax.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
prog ::= pipeline+ ;
pipeline ::= ID schema ('|' transformation)* ';' ;
schema ::= '(' (column_list) ')' ;
column_list ::= field_def (',' field_def)* ;
field_def ::= ID ('as' TYPES)? ;
transformation ::= where_tran
| top_tran
| project_tran
| project_rename_tran
| project_remove_tran
| project_keep_tran
| explode_tran
| lookup_tran
| join_tran
| take_tran
| ignore_error_tran
| summarize_tran
;
where_tran ::= 'where' expr ;
top_tran ::= 'top' number 'by' expr sort_dir? nulls_pos? ;
project_tran ::= 'project' ID '=' expr (',' ID '=' expr)* ;
project_rename_tran ::= 'project-rename' ID '=' ID (',' ID '=' ID)* ;
project_remove_tran ::= 'project-remove' ID (',' ID)* ;
project_keep_tran ::= 'project-keep' ID (',' ID)* ;
explode_tran ::= ('mv-expand' | 'explode') ID ('as' TYPES)? ;
lookup_tran ::= 'lookup' rename_with_type (',' rename_with_type)* 'from' ID 'on' expr ;
join_tran ::= 'join' 'kind' '=' ('left-inner'|'left-outer') rename_with_type (',' rename_with_type)* 'from' ID 'on' expr ;
take_tran ::= 'take' number ;
ignore_error_tran ::= 'ignore-error' ;
summarize_tran ::= 'summarize' agg_function '(' expr_list ')' (',' agg_function '(' expr_list ')')* ('by' column_name ('=' expr) (',' column_name ('=' expr))*)?
agg_function ::= ID
column_name ::= ID
sort_dir ::= 'asc' | 'desc' ;
nulls_pos ::= 'nulls' ('first' | 'last') ;
rename_with_type ::= (ID '=')? ID ('as' TYPES)? ;
expr ::= unary_expr
| expr 'is' 'null'
| expr 'is' 'not' 'null'
| expr ('*'|'/'|'%'|'and') expr
| expr ('+'|'-'|'or') expr
| expr ('>'|'<'|'>='|'<='|'!='|'<>') expr
| expr '[' expr ']'
| case_expr
| function
| dot_member
| number
| str
| bool
| '(' expr ')'
;
case_expr ::= 'case' when_then (when_then)* else_then 'end' ;
when_then ::= 'when' expr 'then' expr ;
else_then ::= 'else' expr ;
unary_expr ::= ('not' | '+' | '-') expr ;
expr_list ::= expr (',' expr)* ;
function ::= ID '(' expr_list? ')' ;
dot_member ::= ID ('.' ID)* ;
number ::= (FLOAT | DEC | HEX | BIN | CONSTANTS) ;
str ::= STRING_LIT ;
bool ::= BOOL_LIT ;
CONSTANTS ::= 'PI' | 'E' ;
STRING_LIT ::= '"' (~('"' | '\\' | '\r' | '\n') | ('\\' ('"' | '\\' | 'r' | 'n' | 't')))* '"' ;
BOOL_LIT ::= 'true' | 'false' ;
ID ::= [a-zA-Z][a-zA-Z0-9_]* ;
TYPES ::= 'int' | 'long' | 'float' | 'double' | 'string' | 'datetime' | 'array' | 'object' | 'dynamic' ;
FLOAT ::= DIGIT+ '.' DIGIT*
| '.' DIGIT+
;
DEC ::= DIGIT+;
WS ::= [ \t\r\n]+ -> skip ; // toss out whitespace
DIGIT ::= [0-9] ;
LINE_COMMENT ::= '#' ~[\r\n]* ;