| 246 | } |
| 247 | |
| 248 | void ModelParser::ParseUpdateModel(Tokenizer& tokenizer, std::unique_ptr<QueryStatement>& statement) { |
| 249 | auto token = tokenizer.NextToken(); |
| 250 | auto value = duckdb::StringUtil::Upper(token.value); |
| 251 | if (token.type != TokenType::KEYWORD || value != "MODEL") { |
| 252 | throw std::runtime_error("Expected 'MODEL' after 'UPDATE'."); |
| 253 | } |
| 254 | |
| 255 | token = tokenizer.NextToken(); |
| 256 | if (token.type == TokenType::STRING_LITERAL) { |
| 257 | auto model_name = token.value; |
| 258 | token = tokenizer.NextToken(); |
| 259 | if (token.type != TokenType::KEYWORD || duckdb::StringUtil::Upper(token.value) != "TO") { |
| 260 | throw std::runtime_error("Expected 'TO' after model name."); |
| 261 | } |
| 262 | |
| 263 | token = tokenizer.NextToken(); |
| 264 | value = duckdb::StringUtil::Upper(token.value); |
| 265 | if (token.type != TokenType::KEYWORD || (value != "GLOBAL" && value != "LOCAL")) { |
| 266 | throw std::runtime_error("Expected 'GLOBAL' or 'LOCAL' after 'TO'."); |
| 267 | } |
| 268 | auto catalog = value == "GLOBAL" ? "flock_storage." : ""; |
| 269 | |
| 270 | token = tokenizer.NextToken(); |
| 271 | if (token.type == TokenType::END_OF_FILE || token.type == TokenType::SYMBOL || token.value == ";") { |
| 272 | auto update_statement = std::make_unique<UpdateModelScopeStatement>(); |
| 273 | update_statement->model_name = model_name; |
| 274 | update_statement->catalog = catalog; |
| 275 | statement = std::move(update_statement); |
| 276 | } else { |
| 277 | throw std::runtime_error( |
| 278 | "Unexpected characters after the closing parenthesis. Only a semicolon is allowed."); |
| 279 | } |
| 280 | |
| 281 | } else { |
| 282 | if (token.type != TokenType::PARENTHESIS || token.value != "(") { |
| 283 | throw std::runtime_error("Expected opening parenthesis '(' after 'MODEL'."); |
| 284 | } |
| 285 | |
| 286 | token = tokenizer.NextToken(); |
| 287 | if (token.type != TokenType::STRING_LITERAL || token.value.empty()) { |
| 288 | throw std::runtime_error("Expected non-empty string literal for model name."); |
| 289 | } |
| 290 | auto model_name = token.value; |
| 291 | |
| 292 | token = tokenizer.NextToken(); |
| 293 | if (token.type != TokenType::SYMBOL || token.value != ",") { |
| 294 | throw std::runtime_error("Expected comma ',' after model name."); |
| 295 | } |
| 296 | |
| 297 | token = tokenizer.NextToken(); |
| 298 | if (token.type != TokenType::STRING_LITERAL || token.value.empty()) { |
| 299 | throw std::runtime_error("Expected non-empty string literal for model."); |
| 300 | } |
| 301 | auto new_model = token.value; |
| 302 | |
| 303 | token = tokenizer.NextToken(); |
| 304 | if (token.type != TokenType::SYMBOL || token.value != ",") { |
| 305 | throw std::runtime_error("Expected comma ',' after model."); |
nothing calls this directly
no test coverage detected