parsePartitionByClause parses PARTITION BY RANGE/LIST/HASH (columns)
()
| 430 | |
| 431 | // parsePartitionByClause parses PARTITION BY RANGE/LIST/HASH (columns) |
| 432 | func (p *Parser) parsePartitionByClause() (*ast.PartitionBy, error) { |
| 433 | partitionBy := &ast.PartitionBy{} |
| 434 | |
| 435 | // Parse partition type |
| 436 | if p.isType(models.TokenTypeRange) { |
| 437 | partitionBy.Type = "RANGE" |
| 438 | p.advance() |
| 439 | } else if p.isTokenMatch("LIST") { |
| 440 | partitionBy.Type = "LIST" |
| 441 | p.advance() |
| 442 | } else if p.isTokenMatch("HASH") { |
| 443 | partitionBy.Type = "HASH" |
| 444 | p.advance() |
| 445 | } else { |
| 446 | return nil, p.expectedError("RANGE, LIST, or HASH") |
| 447 | } |
| 448 | |
| 449 | // Expect opening parenthesis |
| 450 | if !p.isType(models.TokenTypeLParen) { |
| 451 | return nil, p.expectedError("(") |
| 452 | } |
| 453 | p.advance() // Consume ( |
| 454 | |
| 455 | // Parse column list |
| 456 | for { |
| 457 | if !p.isIdentifier() { |
| 458 | return nil, p.expectedError("column name") |
| 459 | } |
| 460 | partitionBy.Columns = append(partitionBy.Columns, p.currentToken.Token.Value) |
| 461 | p.advance() |
| 462 | |
| 463 | if p.isType(models.TokenTypeComma) { |
| 464 | p.advance() // Consume comma |
| 465 | continue |
| 466 | } |
| 467 | break |
| 468 | } |
| 469 | |
| 470 | // Expect closing parenthesis |
| 471 | if !p.isType(models.TokenTypeRParen) { |
| 472 | return nil, p.expectedError(")") |
| 473 | } |
| 474 | p.advance() // Consume ) |
| 475 | |
| 476 | return partitionBy, nil |
| 477 | } |
| 478 | |
| 479 | // parsePartitionDefinition parses a single partition definition |
| 480 | func (p *Parser) parsePartitionDefinition() (*ast.PartitionDefinition, error) { |
no test coverage detected