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

Method skipClickHouseClauseExpr

pkg/sql/parser/ddl.go:735–774  ·  view source on GitHub ↗

skipClickHouseClauseExpr consumes the expression following a ClickHouse CREATE TABLE trailing clause (ORDER BY, PARTITION BY, PRIMARY KEY, SAMPLE BY). We do not currently model these clauses on the AST; this just walks the tokens until the start of the next clause, EOF, or ';'. Supports both parenth

()

Source from the content-addressed store, hash-verified

733// tokens until the start of the next clause, EOF, or ';'. Supports both
734// parenthesised lists and bare expressions.
735func (p *Parser) skipClickHouseClauseExpr() error {
736 if p.isType(models.TokenTypeLParen) {
737 // Balanced paren block.
738 depth := 0
739 for {
740 switch p.currentToken.Token.Type {
741 case models.TokenTypeEOF:
742 return p.expectedError(") to close clause expression")
743 case models.TokenTypeLParen:
744 depth++
745 p.advance()
746 case models.TokenTypeRParen:
747 depth--
748 p.advance()
749 if depth == 0 {
750 return nil
751 }
752 default:
753 p.advance()
754 }
755 }
756 }
757
758 // Bare expression: consume until next clause/EOF/;.
759 for {
760 t := p.currentToken.Token.Type
761 if t == models.TokenTypeEOF || t == models.TokenTypeSemicolon {
762 return nil
763 }
764 // Stop at next CH trailing-clause keyword.
765 if t == models.TokenTypeOrder || t == models.TokenTypePrimary {
766 return nil
767 }
768 val := strings.ToUpper(p.currentToken.Token.Value)
769 if val == "PARTITION" || val == "SAMPLE" || val == "SETTINGS" || val == "TTL" {
770 return nil
771 }
772 p.advance()
773 }
774}

Callers 1

parseCreateTableMethod · 0.95

Calls 3

isTypeMethod · 0.95
expectedErrorMethod · 0.95
advanceMethod · 0.95

Tested by

no test coverage detected