@@ -157,19 +157,27 @@ valuesRowDefinition
157157// Select statements
158158
159159queryStatement
160- :
160+ : (
161+ selectClause | selectStatement
162+ ) orderByCaluse? limitClause
161163 ;
162164
163165selectStatement
164- : SELECT setQuantifier?
165- (ASTERISK_SIGN | projectItemDefinition (COMMA projectItemDefinition)*)
166- FROM tableExpression
166+ : selectClause fromClause whereClause? groupByClause? havingClause?
167+ ;
168+
169+ selectClause
170+ : SELECT setQuantifier? (ASTERISK_SIGN | projectItemDefinition (COMMA projectItemDefinition)*)
167171 ;
168172
169173projectItemDefinition
170174 : expression (AS ? uid)? | uid ' .' ' *'
171175 ;
172176
177+ fromClause
178+ : FROM tableExpression
179+ ;
180+
173181tableExpression
174182 : tableReference (COMMA tableReference)*
175183 ;
@@ -182,6 +190,39 @@ tablePrimary
182190 : TABLE ? uid
183191 ;
184192
193+ whereClause
194+ : WHERE booleanExpression
195+ ;
196+
197+ groupByClause
198+ : GROUP BY groupItemDefinition (COMMA groupItemDefinition)*
199+ ;
200+
201+ groupItemDefinition
202+ : expression
203+ | LR_BRACKET RR_BRACKET
204+ | LR_BRACKET expression (COMMA expression)* RR_BRACKET
205+ | CUBE LR_BRACKET expression (COMMA expression)* RR_BRACKET
206+ | ROLLUP LR_BRACKET expression (COMMA expression)* RR_BRACKET
207+ | GROUPING SETS LR_BRACKET groupItemDefinition (COMMA groupItemDefinition)* RR_BRACKET
208+ ;
209+
210+ havingClause
211+ : HAVING booleanExpression
212+ ;
213+
214+ orderByCaluse
215+ : ORDER BY orderItemDefition (COMMA orderItemDefition)*
216+ ;
217+
218+ orderItemDefition
219+ : expression (ASC | DESC )
220+ ;
221+
222+ limitClause
223+ : LIMIT (ALL | limit=expression)
224+ ;
225+
185226// expression
186227
187228expression
@@ -227,7 +268,7 @@ primaryExpression
227268 | FIRST ' (' expression (IGNORE NULLS )? ' )' #first
228269 | LAST ' (' expression (IGNORE NULLS )? ' )' #last
229270 | POSITION ' (' substr=valueExpression IN str=valueExpression ' )' #position
230- | constant #constantDefault
271+ // | constant #constantDefault
231272 | ASTERISK #star
232273 // | qualifiedName '.' ASTERISK #star
233274 // | '(' namedExpression (',' namedExpression)+ ')' #rowConstructor
@@ -236,8 +277,8 @@ primaryExpression
236277 // (FILTER '(' WHERE where=booleanExpression ')')? (OVER windowSpec)? #functionCall
237278 // | identifier '->' expression #lambda
238279 // | '(' identifier (',' identifier)+ ')' '->' expression #lambda
239- | value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET #subscript
240- // | identifier #columnReference
280+ // | value=primaryExpression LS_BRACKET index=valueExpression RS_BRACKET #subscript
281+ | identifier #columnReference
241282 // | base=primaryExpression '.' fieldName=identifier #dereference
242283 | ' (' expression ' )' #parenthesizedExpression
243284 // | EXTRACT '(' field=identifier FROM source=valueExpression ')' #extract
@@ -685,9 +726,6 @@ RR_BRACKET: ')';
685726COMMA : ' ,' ;
686727SEMICOLON : ' ;' ;
687728AT_SIGN : ' @' ;
688- ZERO_DECIMAL : ' 0' ;
689- ONE_DECIMAL : ' 1' ;
690- TWO_DECIMAL : ' 2' ;
691729SINGLE_QUOTE_SYMB : ' \' ' ;
692730DOUBLE_QUOTE_SYMB : ' "' ;
693731REVERSE_QUOTE_SYMB : ' `' ;
0 commit comments