@@ -432,8 +432,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
432
432
$ ret ->unknown [] = $ token ;
433
433
} elseif ($ state === 3 ) {
434
434
if ($ partitionState === 0 ) {
435
- $ list ->idx ++; // Ignore the current token
436
- $ nextToken = $ list ->getNext ();
435
+ $ list ->idx ++; // Ignore the current token
436
+ $ nextToken = $ list ->getNext ();
437
437
if (
438
438
($ token ->type === Token::TYPE_KEYWORD )
439
439
&& (($ token ->keyword === 'PARTITION BY ' )
@@ -452,12 +452,27 @@ public static function parse(Parser $parser, TokensList $list, array $options =
452
452
453
453
++$ list ->idx ; // to index the idx by one, because the last getPrevious returned and decreased it.
454
454
} elseif ($ partitionState === 1 ) {
455
+ // Fetch the next token in a way the current index is reset to manage whitespaces in "field".
456
+ $ currIdx = $ list ->idx ;
457
+ ++$ list ->idx ;
458
+ $ nextToken = $ list ->getNext ();
459
+ $ list ->idx = $ currIdx ;
455
460
// Building the expression used for partitioning.
456
461
if (empty ($ ret ->field )) {
457
462
$ ret ->field = '' ;
458
463
}
459
464
460
- $ ret ->field .= $ token ->type === Token::TYPE_WHITESPACE ? ' ' : $ token ->token ;
465
+ if (
466
+ $ token ->type === Token::TYPE_OPERATOR
467
+ && $ token ->value === '( '
468
+ && $ nextToken
469
+ && $ nextToken ->keyword === 'PARTITION '
470
+ ) {
471
+ $ partitionState = 2 ;
472
+ --$ list ->idx ; // Current idx is on "(". We need a step back for ArrayObj::parse incoming.
473
+ } else {
474
+ $ ret ->field .= $ token ->type === Token::TYPE_WHITESPACE ? ' ' : $ token ->token ;
475
+ }
461
476
} elseif ($ partitionState === 2 ) {
462
477
$ ret ->partitions = ArrayObj::parse (
463
478
$ parser ,
0 commit comments