Add assert for .flat

This commit is contained in:
ozanarmagan 2023-09-24 14:33:24 +03:00
parent eaef5cb8c6
commit 88f53c7f32
2 changed files with 13 additions and 6 deletions

View File

@ -53,9 +53,9 @@ Option<uint32_t> validator_t::coerce_element(const field& a_field, nlohmann::jso
}
} else if(a_field.is_array()) {
if(!doc_ele.is_array()) {
bool is_embedding_field = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
bool is_auto_embedding = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
if((a_field.optional && (dirty_values == DIRTY_VALUES::DROP ||
dirty_values == DIRTY_VALUES::COERCE_OR_DROP)) || is_embedding_field) {
dirty_values == DIRTY_VALUES::COERCE_OR_DROP)) || is_auto_embedding) {
document.erase(field_name);
return Option<uint32_t>(200);
} else {
@ -631,9 +631,9 @@ Option<uint32_t> validator_t::validate_index_in_memory(nlohmann::json& document,
continue;
}
bool is_embedding_field = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
bool is_auto_embedding = a_field.type == field_types::FLOAT_ARRAY && a_field.embed.count(fields::from) > 0;
if(document.count(field_name) == 0 && !is_embedding_field) {
if(document.count(field_name) == 0 && !is_auto_embedding) {
return Option<>(400, "Field `" + field_name + "` has been declared in the schema, "
"but is not found in the document.");
}

View File

@ -1799,8 +1799,10 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
nlohmann::json schema = R"({
"name": "objects",
"fields": [
{"name": "title", "type": "string"}
]
{"name": "title", "type": "string"},
{"name": "nested", "type": "object"}
],
"enable_nested_fields": true
})"_json;
TextEmbedderManager::set_model_dir("/tmp/typesense_test/models");
@ -1811,6 +1813,8 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
nlohmann::json doc;
doc["title"] = "hello";
doc["nested"] = nlohmann::json::object();
doc["nested"]["hello"] = "world";
auto add_op = coll->add(doc.dump());
ASSERT_TRUE(add_op.ok());
@ -1828,4 +1832,7 @@ TEST_F(CollectionSchemaChangeTest, EmbeddingFieldAlterUpdateOldDocs) {
ASSERT_EQ(1, search_res.get()["found"].get<size_t>());
ASSERT_EQ(384, search_res.get()["hits"][0]["document"]["embedding"].get<std::vector<float>>().size());
ASSERT_EQ(1, search_res.get()["hits"][0]["document"]["nested"].size());
ASSERT_EQ(0, search_res.get()["hits"][0]["document"].count(".flat"));
ASSERT_EQ(0, search_res.get()["hits"][0]["document"].count("nested.hello"));
}