Created test case input for Dressipi.

Summary:
Add vertex stream operator. Implement ,  query.

Support first batch of queries for testDB. Improve record stream handler. Query engine now supports multiline queries patterns in file comments.

Second and third batch of tests complete. Add functionality to print_record_stream.

Include 4th batch.

Crete a shared function for properties output.

Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D60
This commit is contained in:
Dominik Gleich 2017-02-23 14:19:52 +01:00
parent ede318c2dd
commit 8220808f56
19 changed files with 594 additions and 100 deletions

View File

@ -1 +1,86 @@
CREATE (n {garment_id: 1234, garment_category_id: 1}) RETURN n;
CREATE (g:garment {garment_id: 1234, garment_category_id: 1, conceals: 30}) RETURN g
MATCH(g:garment {garment_id: 1234}) SET g:AA RETURN g
MATCH(g:garment {garment_id: 1234}) SET g:BB RETURN g
MATCH(g:garment {garment_id: 1234}) SET g:EE RETURN g
CREATE (g:garment {garment_id: 2345, garment_category_id: 6, reveals: 10}) RETURN g
MATCH(g:garment {garment_id: 2345}) SET g:CC RETURN g
MATCH(g:garment {garment_id: 2345}) SET g:DD RETURN g
CREATE (g:garment {garment_id: 3456, garment_category_id: 8}) RETURN g
MATCH(g:garment {garment_id: 3456}) SET g:CC RETURN g
MATCH(g:garment {garment_id: 3456}) SET g:DD RETURN g
CREATE (g:garment {garment_id: 4567, garment_category_id: 15}) RETURN g
MATCH(g:garment {garment_id: 4567}) SET g:AA RETURN g
MATCH(g:garment {garment_id: 4567}) SET g:BB RETURN g
MATCH(g:garment {garment_id: 4567}) SET g:DD RETURN g
CREATE (g:garment {garment_id: 5678, garment_category_id: 19}) RETURN g
MATCH(g:garment {garment_id: 5678}) SET g:BB RETURN g
MATCH(g:garment {garment_id: 5678}) SET g:CC RETURN g
MATCH(g:garment {garment_id: 5678}) SET g:EE RETURN g
CREATE (g:garment {garment_id: 6789, garment_category_id: 3}) RETURN g
MATCH(g:garment {garment_id: 6789}) SET g:AA RETURN g
MATCH(g:garment {garment_id: 6789}) SET g:DD RETURN g
MATCH(g:garment {garment_id: 6789}) SET g:EE RETURN g
CREATE (g:garment {garment_id: 7890, garment_category_id: 25}) RETURN g
MATCH(g:garment {garment_id: 7890}) SET g:AA RETURN g
MATCH(g:garment {garment_id: 7890}) SET g:BB RETURN g
MATCH(g:garment {garment_id: 7890}) SET g:CC RETURN g
MATCH(g:garment {garment_id: 7890}) SET g:EE RETURN g
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}),(g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 6789}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 5678}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 3456}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 1234}),(g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 4567}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 6789}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 5678}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 3456}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 2345}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 5678}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 6789}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 7890}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
MATCH (g1:garment {garment_id: 3456}), (g2:garment {garment_id: 4567}) CREATE (g1)-[r:default_outfit]->(g2) RETURN r
CREATE (p:profile {profile_id: 111, partner_id: 55, reveals: 30}) RETURN p
CREATE (p:profile {profile_id: 112, partner_id: 55}) RETURN p
CREATE (p:profile {profile_id: 112, partner_id: 77, conceals: 10}) RETURN p
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 1234}) CREATE (p)-[s:score]->(g) SET s.score=1500 RETURN s
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 2345}) CREATE (p)-[s:score]->(g) SET s.score=1200 RETURN s
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 3456}) CREATE (p)-[s:score]->(g) SET s.score=1000 RETURN s
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 4567}) CREATE (p)-[s:score]->(g) SET s.score=1000 RETURN s
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 6789}) CREATE (p)-[s:score]->(g) SET s.score=1500 RETURN s
MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment {garment_id: 7890}) CREATE (p)-[s:score]->(g) SET s.score=1800 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 55}), (g:garment {garment_id: 1234}) CREATE (p)-[s:score]->(g) SET s.score=2000 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 55}), (g:garment {garment_id: 4567}) CREATE (p)-[s:score]->(g) SET s.score=1500 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 55}), (g:garment {garment_id: 5678}) CREATE (p)-[s:score]->(g) SET s.score=1000 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 55}), (g:garment {garment_id: 6789}) CREATE (p)-[s:score]->(g) SET s.score=1600 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 55}), (g:garment {garment_id: 7890}) CREATE (p)-[s:score]->(g) SET s.score=1900 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 1234}) CREATE (p)-[s:score]->(g) SET s.score=1500 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 2345}) CREATE (p)-[s:score]->(g) SET s.score=1300 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 3456}) CREATE (p)-[s:score]->(g) SET s.score=1300 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 5678}) CREATE (p)-[s:score]->(g) SET s.score=1200 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 6789}) CREATE (p)-[s:score]->(g) SET s.score=1700 RETURN s
MATCH (p:profile {profile_id: 112, partner_id: 77}), (g:garment {garment_id: 7890}) CREATE (p)-[s:score]->(g) SET s.score=1900 RETURN s

View File

@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (p:profile {profile_id: 112, partner_id: 55, conceals: 10})
// RETURN p
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
auto v = db_accessor.insert_vertex();
v.PropsSet(db_accessor.property("profile_id"), args.at(0));
v.PropsSet(db_accessor.property("partner_id"), args.at(1));
v.PropsSet(db_accessor.property("conceals"), args.at(2));
v.add_label(db_accessor.label("profile"));
stream.write_field("p");
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -2,8 +2,8 @@
#include <string>
#include "query/plan_interface.hpp"
#include "query/util.hpp"
#include "storage/model/properties/all.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
@ -13,24 +13,16 @@ using std::endl;
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
DbAccessor t(db);
auto profile_id = t.vertex_property_key("profile_id", args[0].key.flags());
auto partner_id = t.vertex_property_key("partner_id", args[1].key.flags());
auto va = t.vertex_insert();
va.set(profile_id, std::move(args[0]));
va.set(partner_id, std::move(args[1]));
auto &profile = t.label_find_or_create("profile");
va.add_label(profile);
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
auto v = db_accessor.insert_vertex();
v.PropsSet(db_accessor.property("profile_id"), args.at(0));
v.PropsSet(db_accessor.property("partner_id"), args.at(1));
v.add_label(db_accessor.label("profile"));
stream.write_field("p");
stream.write_vertex_record(va);
stream.write_meta("w");
return t.commit();
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}

View File

@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (p:profile {profile_id: 112, partner_id: 55, reveals: 30})
// RETURN p
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
auto v = db_accessor.insert_vertex();
v.PropsSet(db_accessor.property("profile_id"), args.at(0));
v.PropsSet(db_accessor.property("partner_id"), args.at(1));
v.PropsSet(db_accessor.property("reveals"), args.at(2));
v.add_label(db_accessor.label("profile"));
stream.write_field("p");
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -2,18 +2,27 @@
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (n {garment_id: 1234, garment_category_id: 1}) RETURN n;
// Query: CREATE (g:garment {garment_id: 1234, garment_category_id:1}) RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return true;
auto v = db_accessor.insert_vertex();
v.add_label(db_accessor.label("garment"));
v.PropsSet(db_accessor.property("garment_id"), args.at(0));
v.PropsSet(db_accessor.property("garment_category_id"), args.at(1));
stream.write_field("g");
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}

View File

@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (g:garment {garment_id: 1234, garment_category_id:
// 1,conceals:30}) RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
auto v = db_accessor.insert_vertex();
v.add_label(db_accessor.label("garment"));
v.PropsSet(db_accessor.property("garment_id"), args.at(0));
v.PropsSet(db_accessor.property("garment_category_id"), args.at(1));
v.PropsSet(db_accessor.property("conceals"), args.at(2));
stream.write_field("g");
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,35 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (g:garment {garment_id: 1234, garment_category_id:
// 1,reveals:30}) RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
auto v = db_accessor.insert_vertex();
v.add_label(db_accessor.label("garment"));
v.PropsSet(db_accessor.property("garment_id"), args.at(0));
v.PropsSet(db_accessor.property("garment_category_id"), args.at(1));
v.PropsSet(db_accessor.property("reveals"), args.at(2));
stream.write_field("g");
stream.write_vertex_record(v);
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -1,42 +0,0 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "query/util.hpp"
#include "storage/model/properties/all.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: CREATE (g:garment {garment_id: 1236, garment_category_id: 1}) RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
DbAccessor t(db);
auto garment_id = t.vertex_property_key("garment_id", args[0].key.flags());
auto garment_category_id =
t.vertex_property_key("garment_category_id", args[1].key.flags());
auto va = t.vertex_insert();
va.set(garment_id, std::move(args[0]));
va.set(garment_category_id, std::move(args[1]));
auto &garment = t.label_find_or_create("garment");
va.add_label(garment);
stream.write_field("g");
stream.write_vertex_record(va);
stream.write_meta("w");
return t.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,56 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g1:garment {garment_id: 1234}), (g2:garment {garment_id: 4567})
// CREATE (g1)-[r:default_outfit]->(g2) RETURN r
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
stream.write_field("r");
std::vector<VertexAccessor> g1_set, g2_set;
for (auto g1 : db_accessor.vertices()) {
if (g1.has_label(db_accessor.label("garment"))) {
auto prop = g1.PropsAt(db_accessor.property("garment_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(0);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
g1_set.push_back(g1);
}
}
for (auto g2 : db_accessor.vertices()) {
if (g2.has_label(db_accessor.label("garment"))) {
auto prop = g2.PropsAt(db_accessor.property("garment_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(1);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
g2_set.push_back(g2);
}
}
for (auto g1 : g1_set)
for (auto g2 : g2_set) {
EdgeAccessor e = db_accessor.insert_edge(
g1, g2, db_accessor.edge_type("default_outfit"));
stream.write_edge_record(e);
}
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
#include "match_garment_set_label_general_return.hpp"
#include "query/plan_interface.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g:garment {garment_id: 1234}) SET g:AA RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return run_general_query(db_accessor, args, stream, "AA");
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
#include "match_garment_set_label_general_return.hpp"
#include "query/plan_interface.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g:garment {garment_id: 1234}) SET g:BB RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return run_general_query(db_accessor, args, stream, "BB");
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
#include "match_garment_set_label_general_return.hpp"
#include "query/plan_interface.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g:garment {garment_id: 1234}) SET g:CC RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return run_general_query(db_accessor, args, stream, "CC");
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
#include "match_garment_set_label_general_return.hpp"
#include "query/plan_interface.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g:garment {garment_id: 1234}) SET g:DD RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return run_general_query(db_accessor, args, stream, "DD");
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
#include "match_garment_set_label_general_return.hpp"
#include "query/plan_interface.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (g:garment {garment_id: 1234}) SET g:EE RETURN g
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
return run_general_query(db_accessor, args, stream, "EE");
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -0,0 +1,32 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// General query type: MATCH (g:garment {garment_id: 1234}) SET g:'GENERAL'
// RETURN g
bool run_general_query(GraphDbAccessor &db_accessor,
const TypedValueStore<> &args, Stream &stream,
const std::string &general_label) {
stream.write_field("g");
for (auto vertex : db_accessor.vertices()) {
if (vertex.has_label(db_accessor.label("garment"))) {
auto prop = vertex.PropsAt(db_accessor.property("garment_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(0);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
vertex.add_label(db_accessor.label(general_label));
stream.write_vertex_record(vertex);
}
}
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}

View File

@ -2,8 +2,8 @@
#include <string>
#include "query/plan_interface.hpp"
#include "query/util.hpp"
#include "storage/model/properties/all.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
@ -13,37 +13,29 @@ using std::endl;
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
DbAccessor t(db);
indices_t indices = {{"garment_id", 0}};
auto properties = query_properties(indices, args);
auto &label = t.label_find_or_create("garment");
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
stream.write_field("labels(g)");
label.index()
.for_range(t)
.properties_filter(t, properties)
.for_all([&](auto va) -> void {
va.stream_repr(std::cout);
auto &ff_label = t.label_find_or_create("FF");
va.add_label(ff_label);
auto &labels = va.labels();
stream.write_record();
stream.write_list_header(1);
stream.write_list_header(labels.size());
for (auto &label : labels) {
stream.write(label.get().str());
}
stream.chunk();
});
for (auto vertex : db_accessor.vertices()) {
if (vertex.has_label(db_accessor.label("garment"))) {
auto prop = vertex.PropsAt(db_accessor.property("garment_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(0);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
vertex.add_label(db_accessor.label("FF"));
auto &labels = vertex.labels();
stream.write_record();
stream.write_list_header(1);
stream.write_list_header(labels.size());
for (const GraphDb::Label &label : labels) {
stream.write(label);
}
stream.chunk();
}
}
stream.write_meta("rw");
return t.commit();
return db_accessor.transaction_.commit();
}
~CPUPlan() {}

View File

@ -0,0 +1,62 @@
#include <iostream>
#include <string>
#include "query/plan_interface.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
// Query: MATCH (p:profile {profile_id: 111, partner_id: 55}), (g:garment
// {garment_id: 1234}) CREATE (p)-[s:score]->(g) SET s.score=1500 RETURN s
class CPUPlan : public PlanInterface<Stream> {
public:
bool run(GraphDbAccessor &db_accessor, const TypedValueStore<> &args,
Stream &stream) {
stream.write_field("r");
std::vector<VertexAccessor> g1_set, g2_set;
for (auto g1 : db_accessor.vertices()) {
if (g1.has_label(db_accessor.label("profile"))) {
auto prop = g1.PropsAt(db_accessor.property("profile_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(0);
if (cmp.type_ != TypedValue::Type::Bool) continue;
auto prop2 = g1.PropsAt(db_accessor.property("partner_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp2 = prop == args.at(1);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
g1_set.push_back(g1);
}
}
for (auto g2 : db_accessor.vertices()) {
if (g2.has_label(db_accessor.label("garment"))) {
auto prop = g2.PropsAt(db_accessor.property("garment_id"));
if (prop.type_ == TypedValue::Type::Null) continue;
auto cmp = prop == args.at(2);
if (cmp.type_ != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
g2_set.push_back(g2);
}
}
for (auto g1 : g1_set)
for (auto g2 : g2_set) {
EdgeAccessor e =
db_accessor.insert_edge(g1, g2, db_accessor.edge_type("score"));
e.PropsSet(db_accessor.property("score"), args.at(3));
stream.write_edge_record(e);
}
stream.write_meta("rw");
return db_accessor.transaction_.commit();
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }

View File

@ -82,18 +82,26 @@ auto LoadQueryPlans(Logger &log, QueryEngineT &engine,
auto plan_paths = LoadFilePaths(path, "cpp");
// query mark will be used to extract queries from files (because we want
// to be independent to a query hash)
auto query_mark = std::string("// Query: ");
auto comment = std::string("// ");
auto query_mark = comment + std::string("Query: ");
for (auto &plan_path : plan_paths) {
auto lines = read_lines(plan_path);
// find the line with a query in order
// be able to place it in the dynamic libs container (base on query
// hash)
for (auto &line : lines) {
for (int i = 0; i < (int)lines.size(); ++i) {
// find query in the line
auto &line = lines[i];
auto pos = line.find(query_mark);
// if query doesn't exist pass
if (pos == std::string::npos) continue;
auto query = trim(line.substr(pos + query_mark.size()));
while (i + 1 < (int)lines.size() &&
lines[i + 1].find(comment) != std::string::npos) {
query += trim(
lines[i + 1].substr(lines[i + 1].find(comment) + comment.length()));
++i;
}
// load/compile implementations only for the queries which are
// contained in queries_file
// it doesn't make sense to compile something which won't be runned

View File

@ -5,6 +5,37 @@
#include <string>
#include <vector>
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
void write_properties(std::ostream &os, const GraphDbAccessor &access,
const TypedValueStore<GraphDb::Property> &properties) {
if (properties.size() > 0) {
os << "{";
for (auto x : properties) {
os << access.property_name(x.first) << ": " << x.second << ",";
}
os << "}\n";
}
}
std::ostream &operator<<(std::ostream &os, const VertexAccessor &vertex) {
if (vertex.labels().size() > 0) {
for (GraphDb::Label label : vertex.labels()) {
os << vertex.db_accessor().property_name(label) << ", ";
}
os << "\n";
}
write_properties(os, vertex.db_accessor(), vertex.Properties());
return os;
}
std::ostream &operator<<(std::ostream &os, const EdgeAccessor &edge) {
os << "Edge: " << edge.db_accessor().edge_type_name(edge.edge_type()) << "\n";
write_properties(os, edge.db_accessor(), edge.Properties());
return os;
}
class PrintRecordStream {
private:
std::ostream &stream;
@ -32,16 +63,20 @@ class PrintRecordStream {
stream << "Field: " << field << '\n';
}
void write(const TypedValue &value) { stream << value; }
void write_list_header(size_t size) { stream << "List: " << size << '\n'; }
void write_record() { stream << "Record\n"; }
void write_vertex_record(const VertexAccessor &vertex) { stream << vertex; }
void write_edge_record(const EdgeAccessor &edge) { stream << edge; }
void write_meta(const std::string &type) {
stream << "Meta: " << type << std::endl;
}
void write_failure(const std::map<std::string, std::string> &data) {
}
void write_failure(const std::map<std::string, std::string> &data) {}
void write_count(const size_t count) { }
void write_count(const size_t count) {}
void chunk() { stream << "CHUNK\n"; }
};