Children of unindexed object field should not be part of schema.

This commit is contained in:
Kishore Nallan 2023-09-24 15:58:24 +05:30
parent 30f21d6d7d
commit 2ef1b42d2d
2 changed files with 28 additions and 0 deletions

View File

@ -549,6 +549,10 @@ Option<bool> field::flatten_doc(nlohmann::json& document,
std::unordered_map<std::string, field> flattened_fields_map;
for(auto& nested_field: nested_fields) {
if(!nested_field.index) {
continue;
}
std::vector<std::string> field_parts;
StringUtils::split(nested_field.name, field_parts, ".");

View File

@ -1487,6 +1487,30 @@ TEST_F(CollectionNestedFieldsTest, ExplicitSchemaForNestedArrayTypeValidation) {
"Hint: field inside an array of objects must be an array type as well.", add_op.error());
}
TEST_F(CollectionNestedFieldsTest, UnindexedNestedFieldShouldNotClutterSchema) {
nlohmann::json schema = R"({
"name": "coll1",
"enable_nested_fields": true,
"fields": [
{"name": "block", "type": "object", "optional": true, "index": false}
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll1 = op.get();
auto doc1 = R"({
"block": {"text": "Hello world."}
})"_json;
auto add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
// child fields should not become part of schema
ASSERT_EQ(1, coll1->get_fields().size());
}
TEST_F(CollectionNestedFieldsTest, SortByNestedField) {
nlohmann::json schema = R"({
"name": "coll1",