Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix bug in geopoint array alter drop.

Kishore Nallan4c562fa6c8bf
diff --git a/src/index.cpp b/src/index.cpp
index 6cf559f0..fb2ea3fe 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -6137,7 +6137,7 @@ void Index::refresh_schemas(const std::vector<field>& new_fields, const std::vec
if(!del_field.is_single_geopoint()) {
spp::sparse_hash_map<uint32_t, int64_t*>* geo_array_map = geo_array_index[del_field.name];
for(auto& kv: *geo_array_map) {
- delete kv.second;
+ delete [] kv.second;
}
delete geo_array_map;
geo_array_index.erase(del_field.name);
diff --git a/test/collection_schema_change_test.cpp b/test/collection_schema_change_test.cpp
index 61f53e7a..7bc6f32c 100644
--- a/test/collection_schema_change_test.cpp
+++ b/test/collection_schema_change_test.cpp
@@ -1088,6 +1088,37 @@ TEST_F(CollectionSchemaChangeTest, IndexFalseToTrue) {
ASSERT_EQ(1, res_op.get()["facet_counts"].size());
}
+TEST_F(CollectionSchemaChangeTest, DropGeoPointArrayField) {
+ // when a value is `null` initially, and is altered, subsequent updates should not fail
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "fields": [
+ {"name": "geoloc", "type": "geopoint[]"}
+ ]
+ })"_json;
+
+ auto coll_create_op = collectionManager.create_collection(schema);
+ ASSERT_TRUE(coll_create_op.ok());
+ Collection* coll1 = coll_create_op.get();
+
+ nlohmann::json doc = R"({
+ "geoloc": [[10, 20]]
+ })"_json;
+
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ auto schema_changes = R"({
+ "fields": [
+ {"name": "geoloc", "drop": true},
+ {"name": "_geoloc", "type": "geopoint[]", "optional": true}
+ ]
+ })"_json;
+
+ auto alter_op = coll1->alter(schema_changes);
+ ASSERT_TRUE(alter_op.ok());
+}
+
TEST_F(CollectionSchemaChangeTest, AddingFieldWithExistingNullValue) {
// when a value is `null` initially, and is altered, subsequent updates should not fail
nlohmann::json schema = R"({