used by ROLLUP and CUBE. Returns error if the list is empty.
(keyword string)
| 25 | |
| 26 | // used by ROLLUP and CUBE. Returns error if the list is empty. |
| 27 | func (p *Parser) parseGroupingExpressionList(keyword string) ([]ast.Expression, error) { |
| 28 | if !p.isType(models.TokenTypeLParen) { |
| 29 | return nil, p.expectedError("( after " + keyword) |
| 30 | } |
| 31 | p.advance() // Consume ( |
| 32 | |
| 33 | // Check for empty list - not allowed for ROLLUP/CUBE |
| 34 | if p.isType(models.TokenTypeRParen) { |
| 35 | return nil, goerrors.InvalidSyntaxError( |
| 36 | keyword+" requires at least one expression", |
| 37 | p.currentLocation(), |
| 38 | "", |
| 39 | ) |
| 40 | } |
| 41 | |
| 42 | // Parse comma-separated expressions |
| 43 | expressions := make([]ast.Expression, 0) |
| 44 | for { |
| 45 | expr, err := p.parseExpression() |
| 46 | if err != nil { |
| 47 | return nil, err |
| 48 | } |
| 49 | expressions = append(expressions, expr) |
| 50 | |
| 51 | // Check for comma (more expressions) or closing paren |
| 52 | if p.isType(models.TokenTypeRParen) { |
| 53 | break |
| 54 | } |
| 55 | if !p.isType(models.TokenTypeComma) { |
| 56 | return nil, p.expectedError(", or ) in " + keyword) |
| 57 | } |
| 58 | p.advance() // Consume comma |
| 59 | } |
| 60 | p.advance() // Consume ) |
| 61 | |
| 62 | return expressions, nil |
| 63 | } |
| 64 | |
| 65 | // parseRollup parses ROLLUP(col1, col2, ...) in GROUP BY clause |
| 66 | // ROLLUP generates hierarchical grouping sets from right to left |
no test coverage detected