MCPcopy Create free account
hub / github.com/AfterShip/clickhouse-sql-parser / tryParseTTLPolicy

Method tryParseTTLPolicy

parser/parser_table.go:1139–1189  ·  view source on GitHub ↗
(pos Pos)

Source from the content-addressed store, hash-verified

1137}
1138
1139func (p *Parser) tryParseTTLPolicy(pos Pos) (*TTLPolicy, error) {
1140 var rule *TTLPolicyRule
1141 switch {
1142 case p.tryConsumeKeywords(KeywordTo):
1143 if p.tryConsumeKeywords(KeywordDisk) {
1144 value, err := p.parseString(p.Pos())
1145 if err != nil {
1146 return nil, err
1147 }
1148 rule = &TTLPolicyRule{RulePos: pos, ToDisk: value}
1149 } else if p.tryConsumeKeywords(KeywordVolume) {
1150 value, err := p.parseString(p.Pos())
1151 if err != nil {
1152 return nil, err
1153 }
1154 rule = &TTLPolicyRule{RulePos: pos, ToVolume: value}
1155 } else {
1156 return nil, fmt.Errorf("unexpected token: %q, expected DISK or VOLUME", p.lastTokenKind())
1157 }
1158 case p.matchKeyword(KeywordDelete), p.matchKeyword(KeywordRecompress):
1159 token := p.last()
1160 _ = p.lexer.consumeToken()
1161 action := &TTLPolicyRuleAction{
1162 ActionPos: token.Pos,
1163 ActionEnd: token.End,
1164 Action: token.ToString(),
1165 }
1166 codec, err := p.tryParseCompressionCodecs(p.Pos())
1167 if err != nil {
1168 return nil, err
1169 }
1170 action.Codec = codec
1171 rule = &TTLPolicyRule{RulePos: pos, Action: action}
1172 default:
1173 return nil, nil // nolint
1174 }
1175 policy := &TTLPolicy{Item: rule}
1176
1177 where, err := p.tryParseWhereClause(p.Pos())
1178 if err != nil {
1179 return nil, err
1180 }
1181 policy.Where = where
1182
1183 groupBy, err := p.tryParseGroupByClause(p.Pos())
1184 if err != nil {
1185 return nil, err
1186 }
1187 policy.GroupBy = groupBy
1188 return policy, nil
1189}
1190
1191func (p *Parser) parseTTLExpr(pos Pos) (*TTLExpr, error) {
1192 columnExpr, err := p.parseExpr(pos)

Callers 1

parseTTLExprMethod · 0.95

Calls 11

tryConsumeKeywordsMethod · 0.95
parseStringMethod · 0.95
PosMethod · 0.95
lastTokenKindMethod · 0.95
matchKeywordMethod · 0.95
lastMethod · 0.95
tryParseWhereClauseMethod · 0.95
tryParseGroupByClauseMethod · 0.95
consumeTokenMethod · 0.80
ToStringMethod · 0.80

Tested by

no test coverage detected