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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Drop values must be at the top for drop+add use case.
Kishore Nallanc2856b02b555
diff --git a/src/collection.cpp b/src/collection.cppindex 6e5d4cb4..b4cae9b3 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -2843,6 +2843,12 @@ Option<bool> Collection::validate_alter_payload(nlohmann::json& schema_changes,// we will first do a pass at basic validations and pick out fields to be deletedstd::set<std::string> delete_field_names;+ // ensure that drop values are at the top: required for drop+add use case+ std::sort(schema_changes["fields"].begin(), schema_changes["fields"].end(),+ [](nlohmann::json& a, nlohmann::json& b) {+ return a.contains("drop") > b.contains("drop");+ });+for(const auto& kv: schema_changes["fields"].items()) {if (!kv.value().is_object()) {return Option<bool>(400, err_msg);diff --git a/test/collection_schema_change_test.cpp b/test/collection_schema_change_test.cppindex f5426cbe..00fcc526 100644--- a/test/collection_schema_change_test.cpp+++ b/test/collection_schema_change_test.cpp@@ -983,3 +983,45 @@ TEST_F(CollectionSchemaChangeTest, ChangeFromStringStarToAutoField) {ASSERT_EQ(2, coll1->get_fields().size());ASSERT_EQ(1, coll1->get_dynamic_fields().size());}++TEST_F(CollectionSchemaChangeTest, ChangeFromGeoToIntField) {+ nlohmann::json req_json = R"({+ "name": "coll1",+ "fields": [+ {"name": "loc", "type": "geopoint"}+ ]+ })"_json;++ auto coll1_op = collectionManager.create_collection(req_json);+ ASSERT_TRUE(coll1_op.ok());++ auto coll1 = coll1_op.get();++ nlohmann::json doc;+ doc["id"] = "0";+ doc["loc"] = {1, 2};++ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ // try to alter to a bad type (int32)++ auto schema_changes = R"({+ "fields": [+ {"name": "loc", "type": "int32"},+ {"name": "loc", "drop": true}+ ]+ })"_json;++ auto alter_op = coll1->alter(schema_changes);+ ASSERT_FALSE(alter_op.ok());++ schema_changes = R"({+ "fields": [+ {"name": "loc", "drop": true},+ {"name": "loc", "type": "int32"}+ ]+ })"_json;++ alter_op = coll1->alter(schema_changes);+ ASSERT_FALSE(alter_op.ok());+}