| 136 | } |
| 137 | |
| 138 | void ModelParser::ParseCreateModel(Tokenizer& tokenizer, std::unique_ptr<QueryStatement>& statement) { |
| 139 | auto token = tokenizer.NextToken(); |
| 140 | auto value = duckdb::StringUtil::Upper(token.value); |
| 141 | |
| 142 | std::string catalog; |
| 143 | if (token.type == TokenType::KEYWORD && (value == "GLOBAL" || value == "LOCAL")) { |
| 144 | if (value == "GLOBAL") { |
| 145 | catalog = "flock_storage."; |
| 146 | } |
| 147 | token = tokenizer.NextToken(); |
| 148 | value = duckdb::StringUtil::Upper(token.value); |
| 149 | } |
| 150 | |
| 151 | if (token.type != TokenType::KEYWORD || value != "MODEL") { |
| 152 | throw std::runtime_error("Expected 'MODEL' after 'CREATE'."); |
| 153 | } |
| 154 | |
| 155 | token = tokenizer.NextToken(); |
| 156 | if (token.type != TokenType::PARENTHESIS || token.value != "(") { |
| 157 | throw std::runtime_error("Expected opening parenthesis '(' after 'MODEL'."); |
| 158 | } |
| 159 | |
| 160 | token = tokenizer.NextToken(); |
| 161 | if (token.type != TokenType::STRING_LITERAL || token.value.empty()) { |
| 162 | throw std::runtime_error("Expected non-empty string literal for model name."); |
| 163 | } |
| 164 | auto model_name = token.value; |
| 165 | |
| 166 | token = tokenizer.NextToken(); |
| 167 | if (token.type != TokenType::SYMBOL || token.value != ",") { |
| 168 | throw std::runtime_error("Expected comma ',' after model name."); |
| 169 | } |
| 170 | |
| 171 | token = tokenizer.NextToken(); |
| 172 | if (token.type != TokenType::STRING_LITERAL || token.value.empty()) { |
| 173 | throw std::runtime_error("Expected non-empty string literal for model."); |
| 174 | } |
| 175 | auto model = token.value; |
| 176 | |
| 177 | token = tokenizer.NextToken(); |
| 178 | if (token.type != TokenType::SYMBOL || token.value != ",") { |
| 179 | throw std::runtime_error("Expected comma ',' after model."); |
| 180 | } |
| 181 | |
| 182 | token = tokenizer.NextToken(); |
| 183 | if (token.type != TokenType::STRING_LITERAL || token.value.empty()) { |
| 184 | throw std::runtime_error("Expected non-empty string literal for provider_name."); |
| 185 | } |
| 186 | std::string provider_name = token.value; |
| 187 | |
| 188 | token = tokenizer.NextToken(); |
| 189 | nlohmann::json model_args = nlohmann::json::object(); |
| 190 | // The JSON argument is optional. If present, extract supported model arguments. |
| 191 | if (token.type == TokenType::SYMBOL || token.value == ",") { |
| 192 | token = tokenizer.NextToken(); |
| 193 | try { |
| 194 | nlohmann::json input_args = nlohmann::json::parse(token.value); |
| 195 | for (auto it = input_args.begin(); it != input_args.end(); ++it) { |
nothing calls this directly
no test coverage detected