private Expression readWindowSpecification ( int tokenT , Expression aggExpr ) { SortAndSlice sortAndSlice = null ; readThis ( Tokens . OPENBRACKET ) ; List < Expression > partitionByList = new ArrayList <> ( ) ; if ( token . tokenType == Tokens . PARTITION ) { read ( ) ; readThis ( Tokens . BY ) ; while ( true ) { Expression partitionExpr = XreadValueExpression ( ) ; partitionByList . add ( partitionExpr ) ; if ( token . tokenType == Tokens . COMMA ) { read ( ) ; continue ; } break ; } } if ( token . tokenType == Tokens . ORDER ) { // order by clause read ( ) ; readThis ( Tokens . BY ) ; sortAndSlice = XreadOrderBy ( ) ; } readThis ( Tokens . CLOSEBRACKET ) ; // We don't really care about aggExpr any more. It has the // aggregate expression as a non-windowed expression. We do // care about its parameters and whether it's specified as // unique though. assert ( aggExpr == null || aggExpr instanceof ExpressionAggregate ) ; Expression nodes [ ] ; boolean isDistinct ; if ( aggExpr != null ) { ExpressionAggregate winAggExpr = ( ExpressionAggregate ) aggExpr ; nodes = winAggExpr . nodes ; isDistinct = winAggExpr . isDistinctAggregate ; } else { nodes = Expression . emptyExpressionArray ; isDistinct = false ; } ExpressionWindowed windowedExpr = new ExpressionWindowed ( tokenT , nodes , isDistinct , sortAndSlice , partitionByList ) ; return windowedExpr ; }
This is a minimal parsing of the Window Specification . We only use partition by and order by lists . There is a lot of complexity in the full SQL specification which we don t parse at all .