From 2a7ed7b157c87e538515aaa568152663f2f5516a Mon Sep 17 00:00:00 2001 From: Ian Adams Date: Mon, 30 Sep 2024 09:05:39 -0700 Subject: [PATCH] Cleaned up some cruft, tweaked index creation methods, added small unit test for idx creation --- src/DescriptorsCommand.cc | 28 +---------------------- src/PMGDQueryHandler.cc | 4 +++- src/PMGDQueryHandler.h | 2 +- tests/unit_tests/pmgd_queries.cc | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/DescriptorsCommand.cc b/src/DescriptorsCommand.cc index 5d3a89d9..fea90303 100644 --- a/src/DescriptorsCommand.cc +++ b/src/DescriptorsCommand.cc @@ -223,17 +223,6 @@ int AddDescriptorSet::construct_protobuf(PMGDQuery &query, std::string set_name = cmd["name"].asString(); std::string desc_set_path = _storage_sets + "/" + set_name; - /*std::string check_existence; - int temp_dim; - - check_existence = get_set_path(query, set_name, temp_dim); - //if a set already exists, barf and return - if (!check_existence.empty()) { - error["info"] = "Set " + set_name + " already exists!"; - error["status"] = RSCommand::Error; - return -1; - }*/ - Json::Value props = get_value(cmd, "properties"); props[VDMS_DESC_SET_NAME_PROP] = cmd["name"].asString(); props[VDMS_DESC_SET_DIM_PROP] = cmd["dimensions"].asInt(); @@ -963,7 +952,6 @@ int FindDescriptor::construct_protobuf(PMGDQuery &query, Json::Value node_constraints = constraints; cp_result["ids_array"] = ids_array; for (int i = 0; i < ids.size(); ++i) { - printf("IDS!\n"); Json::Value k_node_constraints; // Theoretically this makes a deep copy @@ -982,17 +970,10 @@ int FindDescriptor::construct_protobuf(PMGDQuery &query, k_node_constraints[desc_id_prop_name] = jsonArray; results["limit"] = 1; - // TODO UPDATE TO IGNORE LINK TO SET - // query.QueryNode(get_value(cmd, "_ref", -1), VDMS_DESC_TAG, - // link_to_set, k_node_constraints, results, false); query.QueryNode(get_value(cmd, "_ref", -1), VDMS_DESC_TAG, Json::nullValue, k_node_constraints, results, false); } - // TODO END MODS - - /*query.QueryNode(get_value(cmd, "_ref", -1), VDMS_DESC_TAG, - link_to_set, node_constraints, results, false);*/ } catch (VCL::Exception e) { print_exception(e); @@ -1171,9 +1152,6 @@ Json::Value FindDescriptor::construct_responses( } // Case (3) else { - // TODO POSSIBLE REMOVE - // assert(json_responses.size() == 2); - // Get Set info. const Json::Value &set_response = json_responses[0]; @@ -1228,7 +1206,7 @@ Json::Value FindDescriptor::construct_responses( IDDistancePair *pair = _cache_map[cache_obj_id]; ids = &(pair->first); distances = &(pair->second); - // TODO BEGIN MODS + Json::Value combined_tx_constraints; Json::Value set_values; Json::Value ent_values; @@ -1248,12 +1226,8 @@ Json::Value FindDescriptor::construct_responses( set_values["status"] = 0; set_values["returned"] = json_responses.size() - 1; set_values["entities"] = ent_values; - // combined_tx_constraints.append(set_values); - // std::cout<<"modified pmgd output"< *queue, void *p_delete_node) { diff --git a/src/PMGDQueryHandler.h b/src/PMGDQueryHandler.h index 4c8d512b..fab24bcb 100644 --- a/src/PMGDQueryHandler.h +++ b/src/PMGDQueryHandler.h @@ -164,7 +164,7 @@ class PMGDQueryHandler { bool resultdeletion = false, bool autodelete_init = false); void cleanup_files(); - void build_node_int_index(char *node_class, char *prop_name); + int build_node_int_index(char *node_class, char *prop_name); void print_node_idx_stats(char *tag_name, char *prop_id); }; diff --git a/tests/unit_tests/pmgd_queries.cc b/tests/unit_tests/pmgd_queries.cc index 7ef8b4ae..cd00dbdc 100644 --- a/tests/unit_tests/pmgd_queries.cc +++ b/tests/unit_tests/pmgd_queries.cc @@ -79,6 +79,44 @@ void add_patient(protobufs::Command &cmdadd, int id, string name, int age, p->set_string_value("Random"); } +TEST(PMGDQueryHandler, addIndexTest){ + + VDMSConfig::init("unit_tests/config-pmgd-tests.json"); + PMGDQueryHandler::init(); + PMGDQueryHandler qh; + int idx_build_rc; + + vector cmds; + + idx_build_rc = qh.build_node_int_index((char * ) "Patient", (char *) "Age"); + + int txid = 1, patientid = 1, eid = 1, query_count = 0; + //Begin TX + protobufs::Command cmdtx; + cmdtx.set_cmd_id(protobufs::Command::TxBegin); + cmdtx.set_tx_id(txid); + cmds.push_back(&cmdtx); + query_count++; + + protobufs::Command cmdadd1; + cmdadd1.set_tx_id(txid); + add_patient(cmdadd1, patientid++, "Keira F.", 39, + "Sat Nov 12 17:59:24 PDT 1984", "kfa@abc.com", FEMALE); + cmds.push_back(&cmdadd1); + query_count++; + + //commit TX + protobufs::Command cmdtxcommit; + cmdtxcommit.set_cmd_id(protobufs::Command::TxCommit); + cmdtxcommit.set_tx_id(txid); + cmds.push_back(&cmdtxcommit); + + //TODO prints/RC checks + qh.print_node_idx_stats((char *)"Patient", (char *)"Age"); + ASSERT_EQ(idx_build_rc, 0); + +} + TEST(PMGDQueryHandler, addTest) { VDMSConfig::init("unit_tests/config-pmgd-tests.json"); PMGDQueryHandler::init();