Serialize sequence id.

This commit is contained in:
Harpreet Sangar 2023-01-19 11:25:43 +05:30
parent eef346b29f
commit 0acd2c06c3
2 changed files with 21 additions and 5 deletions

View File

@ -469,7 +469,8 @@ Option<uint32_t> Index::validate_index_in_memory(nlohmann::json& document, uint3
"Multiple documents having" + match + "found in the collection `" + tokens[0] + "`.");
}
document[a_field.name + "_sequence_id"] = collection->get_seq_id_collection_prefix() + std::to_string(*(documents[0].second));
document[a_field.name + "_sequence_id"] = collection->get_seq_id_collection_prefix() + "_" +
StringUtils::serialize_uint32_t(*(documents[0].second));
delete [] documents[0].second;
}

View File

@ -255,13 +255,28 @@ TEST_F(CollectionJoinTest, IndexReferenceField) {
}
ASSERT_TRUE(add_op.ok());
}
collectionManager.drop_collection("Customers");
customers_schema_json =
R"({
"name": "Customers",
"fields": [
{"name": "customer_id", "type": "string"},
{"name": "customer_name", "type": "string"},
{"name": "product_price", "type": "float"},
{"name": "product_id", "type": "string", "reference": "Products.product_id"}
]
})"_json;
collection_create_op = collectionManager.create_collection(customers_schema_json);
ASSERT_TRUE(collection_create_op.ok());
add_op = customer_collection->add(customer_json.dump());
ASSERT_TRUE(add_op.ok());
ASSERT_EQ(customer_collection->get("0").get().count("product_id_sequence_id"), 1);
auto result = customer_collection->search("*", {"customer_id"}, "", {}, {}, {0}).get();
ASSERT_EQ(result["hits"][0]["document"].count("product_id"), 1);
// ASSERT_EQ(result["hits"][0]["document"].count("product_id_sequence_id"), 0);
nlohmann::json document;
auto get_op = customer_collection->get_document_from_store(customer_collection->get("0").get()["product_id_sequence_id"].get<std::string>(), document);
ASSERT_TRUE(get_op.ok());
ASSERT_EQ(document.count("product_id"), 1);
ASSERT_EQ(document["product_id"], "product_a");
collectionManager.drop_collection("Customers");
collectionManager.drop_collection("Products");