From a321e3622e7c48a4e7a793280e47289d84481823 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Fri, 28 Apr 2023 16:04:22 +0530 Subject: [PATCH] Add test for a bug which returned null values for nested fields. --- test/collection_nested_fields_test.cpp | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp index 9693e08d..e50cf0e2 100644 --- a/test/collection_nested_fields_test.cpp +++ b/test/collection_nested_fields_test.cpp @@ -2406,6 +2406,33 @@ TEST_F(CollectionNestedFieldsTest, FieldsWithDotsButNotNested) { results["hits"][0]["highlight"]["name.first"]["snippet"].get()); } +TEST_F(CollectionNestedFieldsTest, NullValuesWithExplicitSchema) { + nlohmann::json schema = R"({ + "name": "coll1", + "enable_nested_fields": true, + "fields": [ + {"name": "name", "type": "object"}, + {"name": "name.first", "type": "string"}, + {"name": "name.last", "type": "string", "optional": true} + ] + })"_json; + + auto op = collectionManager.create_collection(schema); + ASSERT_TRUE(op.ok()); + Collection* coll1 = op.get(); + + auto doc1 = R"({ + "name": {"last": null, "first": "Jack"} + })"_json; + + auto add_op = coll1->add(doc1.dump(), CREATE); + ASSERT_TRUE(add_op.ok()); + + auto results = coll1->search("jack", {"name.first"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(1, results["found"].get()); + ASSERT_EQ(2, results["hits"][0]["document"].size()); // id, name +} + TEST_F(CollectionNestedFieldsTest, UpdateNestedDocument) { nlohmann::json schema = R"({ "name": "coll1",