@@ -440,8 +440,8 @@ public static function parse(Parser $parser, TokensList $list, array $options =
440440 $ ret ->unknown [] = $ token ;
441441 } elseif ($ state === 3 ) {
442442 if ($ partitionState === 0 ) {
443- $ list ->idx ++; // Ignore the current token
444- $ nextToken = $ list ->getNext ();
443+ $ list ->idx ++; // Ignore the current token
444+ $ nextToken = $ list ->getNext ();
445445 if (
446446 ($ token ->type === Token::TYPE_KEYWORD )
447447 && (($ token ->keyword === 'PARTITION BY ' )
@@ -460,12 +460,27 @@ public static function parse(Parser $parser, TokensList $list, array $options =
460460
461461 ++$ list ->idx ; // to index the idx by one, because the last getPrevious returned and decreased it.
462462 } elseif ($ partitionState === 1 ) {
463+ // Fetch the next token in a way the current index is reset to manage whitespaces in "field".
464+ $ currIdx = $ list ->idx ;
465+ ++$ list ->idx ;
466+ $ nextToken = $ list ->getNext ();
467+ $ list ->idx = $ currIdx ;
463468 // Building the expression used for partitioning.
464469 if (empty ($ ret ->field )) {
465470 $ ret ->field = '' ;
466471 }
467472
468- $ ret ->field .= $ token ->type === Token::TYPE_WHITESPACE ? ' ' : $ token ->token ;
473+ if (
474+ $ token ->type === Token::TYPE_OPERATOR
475+ && $ token ->value === '( '
476+ && $ nextToken
477+ && $ nextToken ->keyword === 'PARTITION '
478+ ) {
479+ $ partitionState = 2 ;
480+ --$ list ->idx ; // Current idx is on "(". We need a step back for ArrayObj::parse incoming.
481+ } else {
482+ $ ret ->field .= $ token ->type === Token::TYPE_WHITESPACE ? ' ' : $ token ->token ;
483+ }
469484 } elseif ($ partitionState === 2 ) {
470485 $ ret ->partitions = ArrayObj::parse (
471486 $ parser ,
0 commit comments