During import return_id should work for failures.

This commit is contained in:
Kishore Nallan 2024-08-15 22:56:55 +05:30
parent 02ed6a471b
commit bf8cc0b91e
2 changed files with 11 additions and 1 deletions

View File

@ -897,6 +897,9 @@ void Collection::batch_index(std::vector<index_record>& index_records, std::vect
res["embedding_error"] = index_record.embedding_res;
}
res["code"] = index_record.indexed.code();
if (return_id && index_record.doc.contains("id")) {
res["id"] = index_record.doc["id"];
}
}
json_out[index_record.position] = res.dump(-1, ' ', false,

View File

@ -1192,7 +1192,9 @@ TEST_F(CollectionTest, ImportDocumentsUpsert) {
R"({"id": "5", "points": 60, "cast":["Logan Lerman","Alexandra Daddario"],"starring":"Ron Perlman","starring_facet":"Ron Perlman","title":"Percy Jackson: Sea of Monsters"})",
R"({"id": "24", "starring": "John", "cast": ["John Kim"], "points": 11})"}; // missing fields
import_response = coll_mul_fields->add_many(more_records, document, UPSERT);
bool return_id = true;
import_response = coll_mul_fields->add_many(more_records, document, UPSERT, "",
DIRTY_VALUES::COERCE_OR_REJECT, false, return_id);
ASSERT_FALSE(import_response["success"].get<bool>());
ASSERT_EQ(2, import_response["num_imported"].get<int>());
@ -1203,6 +1205,11 @@ TEST_F(CollectionTest, ImportDocumentsUpsert) {
ASSERT_STREQ("Field `points` has been declared as a default sorting field, but is not found in the document.", import_results[1]["error"].get<std::string>().c_str());
ASSERT_STREQ("Field `title` has been declared in the schema, but is not found in the document.", import_results[3]["error"].get<std::string>().c_str());
ASSERT_EQ("1", import_results[0]["id"].get<std::string>());
ASSERT_EQ("90", import_results[1]["id"].get<std::string>());
ASSERT_EQ("5", import_results[2]["id"].get<std::string>());
ASSERT_EQ("24", import_results[3]["id"].get<std::string>());
// try to duplicate records without upsert option
more_records = {R"({"id": "1", "title": "Wake up, Harry"})",