@@ -294,7 +294,13 @@ impl Parser {
294
294
} else {
295
295
vec ! [ ]
296
296
} ;
297
- let window_frame = self . parse_window_frame ( ) ?;
297
+ let window_frame = if !self . consume_token ( & Token :: RParen ) {
298
+ let window_frame = self . parse_window_frame ( ) ?;
299
+ self . expect_token ( & Token :: RParen ) ?;
300
+ Some ( window_frame)
301
+ } else {
302
+ None
303
+ } ;
298
304
299
305
Some ( WindowSpec {
300
306
partition_by,
@@ -313,35 +319,24 @@ impl Parser {
313
319
} ) )
314
320
}
315
321
316
- pub fn parse_window_frame ( & mut self ) -> Result < Option < WindowFrame > , ParserError > {
317
- let window_frame = match self . peek_token ( ) {
318
- Some ( Token :: Word ( w) ) => {
319
- let units = w. keyword . parse :: < WindowFrameUnits > ( ) ?;
320
- self . next_token ( ) ;
321
- if self . parse_keyword ( "BETWEEN" ) {
322
- let start_bound = self . parse_window_frame_bound ( ) ?;
323
- self . expect_keyword ( "AND" ) ?;
324
- let end_bound = Some ( self . parse_window_frame_bound ( ) ?) ;
325
- Some ( WindowFrame {
326
- units,
327
- start_bound,
328
- end_bound,
329
- } )
330
- } else {
331
- let start_bound = self . parse_window_frame_bound ( ) ?;
332
- let end_bound = None ;
333
- Some ( WindowFrame {
334
- units,
335
- start_bound,
336
- end_bound,
337
- } )
338
- }
339
- }
340
- Some ( Token :: RParen ) => None ,
341
- unexpected => return self . expected ( "'ROWS', 'RANGE', 'GROUPS', or ')'" , unexpected) ,
322
+ pub fn parse_window_frame ( & mut self ) -> Result < WindowFrame , ParserError > {
323
+ let units = match self . next_token ( ) {
324
+ Some ( Token :: Word ( w) ) => w. keyword . parse :: < WindowFrameUnits > ( ) ?,
325
+ unexpected => return self . expected ( "ROWS, RANGE, GROUPS" , unexpected) ,
342
326
} ;
343
- self . expect_token ( & Token :: RParen ) ?;
344
- Ok ( window_frame)
327
+ let ( start_bound, end_bound) = if self . parse_keyword ( "BETWEEN" ) {
328
+ let start_bound = self . parse_window_frame_bound ( ) ?;
329
+ self . expect_keyword ( "AND" ) ?;
330
+ let end_bound = Some ( self . parse_window_frame_bound ( ) ?) ;
331
+ ( start_bound, end_bound)
332
+ } else {
333
+ ( self . parse_window_frame_bound ( ) ?, None )
334
+ } ;
335
+ Ok ( WindowFrame {
336
+ units,
337
+ start_bound,
338
+ end_bound,
339
+ } )
345
340
}
346
341
347
342
/// "CURRENT ROW" | ( (<positive number> | "UNBOUNDED") ("PRECEDING" | FOLLOWING) )
0 commit comments