Handle dropping of optional field.

This commit is contained in:
Kishore Nallan 2022-04-30 08:37:08 +05:30
parent 9f5b6ed8de
commit 81ad4c2ba6
3 changed files with 58 additions and 0 deletions

View File

@ -4456,6 +4456,10 @@ Option<uint32_t> Index::remove(const uint32_t seq_id, const nlohmann::json & doc
if(!del_fields.empty()) {
for(auto& the_field: del_fields) {
if(!document.contains(the_field.name)) {
// could be an optional field
continue;
}
remove_field(seq_id, document, the_field.name);
}
} else {

View File

@ -1890,6 +1890,37 @@ TEST_F(CollectionFilteringTest, NumericalRangeFilter) {
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionFilteringTest, RangeFilterOnTimestamp) {
std::vector<field> fields = {field("ts", field_types::INT64, false)};
Collection* coll1 = collectionManager.create_collection(
"coll1", 1, fields, "", 0, "", {}, {"."}
).get();
nlohmann::json doc1;
doc1["id"] = "0";
doc1["ts"] = 1646092800000;
nlohmann::json doc2;
doc2["id"] = "1";
doc2["ts"] = 1648771199000;
nlohmann::json doc3;
doc3["id"] = "2";
doc3["ts"] = 1647111199000;
ASSERT_TRUE(coll1->add(doc1.dump()).ok());
ASSERT_TRUE(coll1->add(doc2.dump()).ok());
ASSERT_TRUE(coll1->add(doc3.dump()).ok());
auto results = coll1->search("*", {},"ts:[1646092800000..1648771199000]", {}, {}, {0}, 10,
1, FREQUENCY, {false}).get();
ASSERT_EQ(3, results["hits"].size());
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionFilteringTest, QueryBoolFields) {
Collection *coll_bool;

View File

@ -710,3 +710,26 @@ TEST_F(CollectionSchemaChangeTest, AddDynamicFieldMatchingMultipleFields) {
ASSERT_EQ(2, coll1->get_fields().size());
ASSERT_EQ(0, coll1->get_dynamic_fields().size());
}
TEST_F(CollectionSchemaChangeTest, DropFieldNotExistingInDocuments) {
// optional title field
std::vector<field> fields = {field("title", field_types::STRING, false, true, true, "", 1, 1),
field("points", field_types::INT32, true),};
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points", 0, "").get();
nlohmann::json doc;
doc["id"] = "0";
doc["points"] = 100;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
auto schema_changes = R"({
"fields": [
{"name": "title", "drop": true}
]
})"_json;
auto alter_op = coll1->alter(schema_changes);
ASSERT_TRUE(alter_op.ok());
}