fixed query hashes

This commit is contained in:
Dominik Tomičević 2016-03-20 08:56:13 +01:00
parent 923bbbeb18
commit 3654aeff86
7 changed files with 108 additions and 91 deletions

View File

@ -10,6 +10,14 @@
#include "threading/task.hpp"
#include "storage/model/properties/all.hpp"
std::vector<std::string> queries {
"CREATE (n:Item{id:1}) RETURN n",
"MATCH (n:Item{id:1}),(m:Item{id:1}) CREATE (n)-[r:test]->(m) RETURN r",
"MATCH (n:Item{id:1}) SET n.prop = 7 RETURN n",
"MATCH (n:Item{id:1}) RETURN n",
"MATCH (n:Item{id:1})-[r]->(m) RETURN count(r)"
};
#pragma url /transaction/commit
class Demo : public Resource<Demo, POST>
{
@ -21,77 +29,96 @@ public:
Resource(task, db),
stripper(make_query_stripper(TK_INT, TK_FLOAT, TK_STR, TK_BOOL))
{
query_f[7130961997552177283] = [db](const code_args_t& args) {
std::vector<uint64_t> hashes;
for(auto& query : queries)
{
auto strip = stripper.strip(query);
auto hash = fnv(strip.query);
hashes.push_back(hash);
}
query_f[hashes[0]] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto vertex_accessor = db->graph.vertices.insert(t);
vertex_accessor.property(
"id", args[0]
);
t.commit();
return "EXECUTED: CREATE (n{id:X}) RETURN n";
};
query_f[11198568396549106428ull] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id = args[0]->as<Int32>();
auto vertex_accessor = db->graph.vertices.find(t, id.value);
t.commit();
return "EXECUTED: MATCH (n{id:X}) RETURN n";
};
query_f[11637140396624918705ull] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id = args[0]->as<Int32>();
auto vertex_accessor = db->graph.vertices.find(t, id.value);
if (!vertex_accessor) {
t.commit();
return "FAIL TO FIND NODE";
}
vertex_accessor.property(
"prop", args[1]
);
t.commit();
return "EXECUTED: MATCH (n{id:X}) SET n.prop=Y RETURN n";
};
query_f[784140140862470291ull] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id1 = args[0]->as<Int32>();
auto v1 = db->graph.vertices.find(t, id1.value);
if (!v1) {
t.commit();
return "FAIL TO FIND NODE";
}
auto id2 = args[1]->as<Int32>();
auto v2 = db->graph.vertices.find(t, id2.value);
if (!v2) {
t.commit();
return "FAIL TO FIND NODE";
}
auto edge_accessor = db->graph.edges.insert(t);
return t.commit(), "AAA";
v1.vlist->access(t).update()->data.out.add(edge_accessor.vlist);
v2.vlist->access(t).update()->data.in.add(edge_accessor.vlist);
edge_accessor.from(v1.vlist);
edge_accessor.to(v2.vlist);
edge_accessor.edge_type(EdgeType("test"));
auto v = db->graph.vertices.insert(t);
v.property("id", args[0]);
t.commit();
return "EXECUTED: EDGE CREATED";
return std::to_string(v.property("id").as<Int32>().value);
};
query_f[16940444920835972350ull] = [db](const code_args_t& args) {
query_f[hashes[1]] = [db](const code_args_t& args) {
return std::string("ALO");
auto& t = db->tx_engine.begin();
auto v1 = db->graph.vertices.find(t, args[0]->as<Int32>().value);
if(!v1)
return t.commit(), std::string("not found");
auto v2 = db->graph.vertices.find(t, args[1]->as<Int32>().value);
if(!v2)
return t.commit(), std::string("not found");
auto e = db->graph.edges.insert(t);
v1.vlist->access(t).update()->data.out.add(e.vlist);
v2.vlist->access(t).update()->data.in.add(e.vlist);
e.from(v1.vlist);
e.to(v2.vlist);
e.edge_type(EdgeType("test"));
t.commit();
return e.edge_type();
};
query_f[hashes[2]] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id = args[0]->as<Int32>();
auto v = db->graph.vertices.find(t, id.value);
if (!v)
return t.commit(), std::string("not found");
v.property("prop", args[1]);
t.commit();
return "EXECUTED: QUERY: MATCH (n{id:X})-[r]->(m) RETURN count(r)";
return std::to_string(v.property("id").as<Int32>().value);
};
query_f[hashes[3]] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id = args[0]->as<Int32>();
auto v = db->graph.vertices.find(t, id.value);
t.commit();
if(!v)
return std::string("not found");
return std::to_string(v.property("id").as<Int32>().value);
};
query_f[hashes[4]] = [db](const code_args_t& args) {
auto& t = db->tx_engine.begin();
auto id = args[0]->as<Int32>();
auto v = db->graph.vertices.find(t, id.value);
t.commit();
if(!v)
return std::string("not found");
return std::to_string(v.out_degree());
};
}
int x{0};
@ -99,7 +126,6 @@ public:
void post(sp::Request& req, sp::Response& res)
{
task->run([this, &req]() {
//return res.send(http::Status::Ok, "alo");
auto query = req.json["statements"][0]["statement"].GetString();
auto strip = stripper.strip(query);
auto hash = fnv(strip.query);
@ -111,6 +137,7 @@ public:
std::cout << "Unrecognized query '"
<< query << "' with hash "
<< hash << "." << std::endl;
return std::string("Unrecognized Query");
}

View File

@ -24,23 +24,14 @@ int main(int argc, char* argv[])
auto connections = std::stoi(argv[3]);
auto duration = std::stod(argv[4]);
// memgraph
std::vector<std::string> queries {
"CREATE (n{id:@}) RETURN n",
"MATCH (n{id:#}),(m{id:#}) CREATE (n)-[r:test]->(m) RETURN r",
"MATCH (n{id:#}) SET n.prop = ^ RETURN n",
"MATCH (n{id:#}) RETURN n",
"MATCH (n{id:#})-[r]->(m) RETURN count(r)"
};
// neo4j
/* std::vector<std::string> queries { */
/* "CREATE (n:Item{id:@}) RETURN n", */
/* "MATCH (n:Item{id:#}),(m:Item{id:#}) CREATE (n)-[r:test]->(m) RETURN r", */
/* "MATCH (n:Item{id:#}) SET n.prop = ^ RETURN n", */
/* "MATCH (n:Item{id:#}) RETURN n", */
/* "MATCH (n:Item{id:#})-[r]->(m) RETURN count(r)" */
/* }; */
std::vector<std::string> queries {
"CREATE (n:Item{id:@}) RETURN n",
"MATCH (n:Item{id:#}),(m:Item{id:#}) CREATE (n)-[r:test]->(m) RETURN r",
"MATCH (n:Item{id:#}) SET n.prop = # RETURN n",
"MATCH (n:Item{id:#}) RETURN n",
"MATCH (n:Item{id:#})-[r]->(m) RETURN count(r)"
};
auto threads = queries.size();

View File

@ -15,15 +15,10 @@ public:
std::string operator()(Rg&& gen, size_t len)
{
auto str = std::string();
str.reserve(len + 4);
str.push_back('\\');
str.push_back('"');
while(str.size() < len)
str.push_back(charset[rnd(std::forward<Rg>(gen))]);
str.push_back('\\');
str.push_back('"');
return str;
}

View File

@ -41,7 +41,6 @@ public:
/* std::cout << "------------------- RESPONSE ------------------" << std::endl; */
/* std::cout << std::string(buf.ptr, buf.len) << std::endl; */
/* std::cout << "-----------------------------------------------" << std::endl; */
/* std::cout << std::endl; */
requests++;
send(stream.socket);
@ -52,10 +51,6 @@ public:
// cypherize and send the request
//socket.write(cypher(queries[idx]));
auto req = cypher(query);
/* std::cout << "-------------------- REQUEST ------------------" << std::endl; */
/* std::cout << req << std::endl; */
socket.write(req);
}

View File

@ -26,18 +26,18 @@ class QueryStripper
public:
QueryStripper(Ts&&... strip_types) :
lexer(std::make_unique<CypherLexer>()),
strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)) {}
strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)),
lexer(std::make_unique<CypherLexer>()) {}
QueryStripper(QueryStripper& other) = delete;
QueryStripper(QueryStripper&& other) :
QueryStripper(QueryStripper&& other) :
strip_types(std::move(other.strip_types)),
lexer(std::move(other.lexer)) {}
auto strip(const std::string& query)
{
// TODO write this more optimal (resplace string
// TODO write this more optimal (resplace string
// concatenation with something smarter)
// TODO: in place substring replacement

View File

@ -30,6 +30,10 @@ bool rapidjson_middleware(sp::Request& req, sp::Response& res)
// return the error message to the client
auto error_str = rapidjson::GetParseError_En(req.json.GetParseError());
std::string parse_error = "JSON parse error: " + std::string(error_str);
std::cout << "'" << req.body << "'" << std::endl;
std::cout << parse_error << std::endl;
res.send(http::Status::BadRequest, parse_error);
// stop further execution

View File

@ -15,6 +15,11 @@ public:
this->record->data.edge_type = type;
}
const std::string& edge_type() const
{
return this->record->data.edge_type;
}
void from(VertexRecord* vertex_record)
{
this->record->data.from = vertex_record;