MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / parseGroupingExpressionList

Method parseGroupingExpressionList

pkg/sql/parser/grouping.go:27–63  ·  view source on GitHub ↗

used by ROLLUP and CUBE. Returns error if the list is empty.

(keyword string)

Source from the content-addressed store, hash-verified

25
26// used by ROLLUP and CUBE. Returns error if the list is empty.
27func (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

Callers 2

parseRollupMethod · 0.95
parseCubeMethod · 0.95

Calls 5

isTypeMethod · 0.95
expectedErrorMethod · 0.95
advanceMethod · 0.95
currentLocationMethod · 0.95
parseExpressionMethod · 0.95

Tested by

no test coverage detected