Skip to content

Commit

Permalink
Cleaned up some cruft, tweaked index creation methods, added small un…
Browse files Browse the repository at this point in the history
…it test for idx creation
  • Loading branch information
ifadams committed Sep 30, 2024
1 parent 156744d commit 2a7ed7b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
28 changes: 1 addition & 27 deletions src/DescriptorsCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Json::Value>(cmd, "properties");
props[VDMS_DESC_SET_NAME_PROP] = cmd["name"].asString();
props[VDMS_DESC_SET_DIM_PROP] = cmd["dimensions"].asInt();
Expand Down Expand Up @@ -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
Expand All @@ -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<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
// link_to_set, k_node_constraints, results, false);

query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
Json::nullValue, k_node_constraints, results, false);
}
// TODO END MODS

/*query.QueryNode(get_value<int>(cmd, "_ref", -1), VDMS_DESC_TAG,
link_to_set, node_constraints, results, false);*/

} catch (VCL::Exception e) {
print_exception(e);
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand All @@ -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"<<set_values<<std::endl;
findDesc = set_values;
// TODO END MODS
// findDesc = json_responses[1];

if (findDesc["status"] != 0 || !findDesc.isMember("entities")) {

Expand Down
4 changes: 3 additions & 1 deletion src/PMGDQueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ void PMGDQueryHandler::print_node_idx_stats(char *tag_name, char *prop_id) {
}
}

void PMGDQueryHandler::build_node_int_index(char *node_class, char *prop_name) {
int PMGDQueryHandler::build_node_int_index(char *node_class, char *prop_name) {

try {
Transaction tx(*_db, Transaction::ReadWrite);
Expand All @@ -1050,7 +1050,9 @@ void PMGDQueryHandler::build_node_int_index(char *node_class, char *prop_name) {
printf("Warning: Failed to create new integer index-%s %s", node_class,
prop_name);
print_exception(e);
return -1;
}
return 0;
}

void delete_by_value(std::list<AutoDeleteNode *> *queue, void *p_delete_node) {
Expand Down
2 changes: 1 addition & 1 deletion src/PMGDQueryHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
38 changes: 38 additions & 0 deletions tests/unit_tests/pmgd_queries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<protobufs::Command *> 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", "[email protected]", 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();
Expand Down

0 comments on commit 2a7ed7b

Please sign in to comment.