parseMergeAction parses the action in a WHEN clause
(clauseType string)
| 185 | |
| 186 | // parseMergeAction parses the action in a WHEN clause |
| 187 | func (p *Parser) parseMergeAction(clauseType string) (*ast.MergeAction, error) { |
| 188 | action := &ast.MergeAction{} |
| 189 | |
| 190 | if p.isType(models.TokenTypeUpdate) { |
| 191 | action.ActionType = "UPDATE" |
| 192 | p.advance() // Consume UPDATE |
| 193 | |
| 194 | // Parse SET |
| 195 | if !p.isType(models.TokenTypeSet) { |
| 196 | return nil, p.expectedError("SET after UPDATE") |
| 197 | } |
| 198 | p.advance() // Consume SET |
| 199 | |
| 200 | // Parse SET clauses |
| 201 | for { |
| 202 | if !p.isIdentifier() && !p.canBeAlias() { |
| 203 | return nil, p.expectedError("column name") |
| 204 | } |
| 205 | // Handle qualified column names (e.g., t.name) |
| 206 | columnName := p.currentToken.Token.Value |
| 207 | p.advance() |
| 208 | |
| 209 | // Check for qualified name (table.column) |
| 210 | if p.isType(models.TokenTypePeriod) { |
| 211 | p.advance() // Consume . |
| 212 | if !p.isIdentifier() && !p.canBeAlias() { |
| 213 | return nil, p.expectedError("column name after .") |
| 214 | } |
| 215 | columnName = fmt.Sprintf("%s.%s", columnName, p.currentToken.Token.Value) |
| 216 | p.advance() |
| 217 | } |
| 218 | |
| 219 | setClause := ast.SetClause{Column: columnName} |
| 220 | |
| 221 | if !p.isType(models.TokenTypeEq) { |
| 222 | return nil, p.expectedError("=") |
| 223 | } |
| 224 | p.advance() // Consume = |
| 225 | |
| 226 | value, err := p.parseExpression() |
| 227 | if err != nil { |
| 228 | return nil, goerrors.WrapError(goerrors.ErrCodeInvalidSyntax, "error parsing SET value", models.Location{}, "", err) |
| 229 | } |
| 230 | setClause.Value = value |
| 231 | action.SetClauses = append(action.SetClauses, setClause) |
| 232 | |
| 233 | if !p.isType(models.TokenTypeComma) { |
| 234 | break |
| 235 | } |
| 236 | p.advance() // Consume comma |
| 237 | } |
| 238 | } else if p.isType(models.TokenTypeInsert) { |
| 239 | if clauseType == "MATCHED" || clauseType == "NOT_MATCHED_BY_SOURCE" { |
| 240 | return nil, goerrors.InvalidSyntaxError(fmt.Sprintf("INSERT not allowed in WHEN %s clause", clauseType), models.Location{}, "") |
| 241 | } |
| 242 | action.ActionType = "INSERT" |
| 243 | p.advance() // Consume INSERT |
| 244 |
no test coverage detected