Persist reference field property.

This commit is contained in:
Harpreet Sangar 2023-01-16 19:21:17 +05:30 committed by ozanarmagan
parent f4eb8716fc
commit c25d69ea85
5 changed files with 32 additions and 5 deletions

View File

@ -310,6 +310,10 @@ struct field {
field_val[fields::vec_dist] = field.vec_dist == ip ? "ip" : "cosine";
}
if (!field.reference.empty()) {
field_val[fields::reference] = field.reference;
}
fields_json.push_back(field_val);
if(!field.has_valid_type()) {

View File

@ -175,6 +175,10 @@ nlohmann::json Collection::get_summary_json() const {
field_json[fields::num_dim] = coll_field.num_dim;
}
if (!coll_field.reference.empty()) {
field_json[fields::reference] = coll_field.reference;
}
fields_arr.push_back(field_json);
}

View File

@ -54,6 +54,10 @@ Collection* CollectionManager::init_collection(const nlohmann::json & collection
field_obj[fields::num_dim] = 0;
}
if (field_obj.count(fields::reference) == 0) {
field_obj[fields::reference] = "";
}
vector_distance_type_t vec_dist_type = vector_distance_type_t::cosine;
if(field_obj.count(fields::vec_dist) != 0) {
@ -66,7 +70,7 @@ Collection* CollectionManager::init_collection(const nlohmann::json & collection
field f(field_obj[fields::name], field_obj[fields::type], field_obj[fields::facet],
field_obj[fields::optional], field_obj[fields::index], field_obj[fields::locale],
-1, field_obj[fields::infix], field_obj[fields::nested], field_obj[fields::nested_array],
field_obj[fields::num_dim], vec_dist_type);
field_obj[fields::num_dim], vec_dist_type, field_obj[fields::reference]);
// value of `sort` depends on field type
if(field_obj.count(fields::sort) == 0) {

View File

@ -568,7 +568,7 @@ Option<bool> field::json_field_to_field(bool enable_nested_fields, nlohmann::jso
return Option<bool>(400, "Field `.*` must be an index field.");
}
if (field_json.count(fields::reference) != 0) {
if (!field_json[fields::reference].get<std::string>().empty()) {
return Option<bool>(400, "Field `.*` cannot be a reference field.");
}
@ -669,7 +669,7 @@ Option<bool> field::json_field_to_field(bool enable_nested_fields, nlohmann::jso
bool is_obj = field_json[fields::type] == field_types::OBJECT || field_json[fields::type] == field_types::OBJECT_ARRAY;
bool is_regexp_name = field_json[fields::name].get<std::string>().find(".*") != std::string::npos;
if (is_regexp_name && field_json.count(fields::reference) != 0) {
if (is_regexp_name && !field_json[fields::reference].get<std::string>().empty()) {
return Option<bool>(400, "Wildcard field cannot have a reference.");
}

View File

@ -36,7 +36,8 @@ protected:
{"name": "not_stored", "type": "string", "optional": true, "index": false},
{"name": "points", "type": "int32"},
{"name": "person", "type": "object", "optional": true},
{"name": "vec", "type": "float[]", "num_dim": 128, "optional": true}
{"name": "vec", "type": "float[]", "num_dim": 128, "optional": true},
{"name": "product_id", "type": "string", "reference": "Products.product_id"}
],
"default_sorting_field": "points",
"symbols_to_index":["+"],
@ -44,7 +45,9 @@ protected:
})"_json;
sort_fields = { sort_by("points", "DESC") };
collection1 = collectionManager.create_collection(schema).get();
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
collection1 = op.get();
}
virtual void SetUp() {
@ -210,6 +213,18 @@ TEST_F(CollectionManagerTest, CollectionCreation) {
"sort":false,
"type":"float[]",
"vec_dist":"cosine"
},
{
"facet":false,
"index":true,
"infix":false,
"locale":"",
"name":"product_id",
"nested":false,
"optional":false,
"sort":false,
"type":"string",
"reference":"Products.product_id"
}
],
"id":0,