clang format has been run on all hpp and cpp files under src and tests
This commit is contained in:
@@ -16,7 +16,10 @@ using std::endl;
|
||||
|
||||
// Dressipi astar query of 4 clicks.
|
||||
|
||||
// Query: MATCH (a:garment)-[:default_outfit]-(b:garment)-[:default_outfit]-(c:garment)-[:default_outfit]-(d:garment)-[:default_outfit]-(a:garment)-[:default_outfit]-(c:garment), (b:garment)-[:default_outfit]-(d:garment) RETURN a.garment_id,b.garment_id,c.garment_id,d.garment_id
|
||||
// Query: MATCH
|
||||
// (a:garment)-[:default_outfit]-(b:garment)-[:default_outfit]-(c:garment)-[:default_outfit]-(d:garment)-[:default_outfit]-(a:garment)-[:default_outfit]-(c:garment),
|
||||
// (b:garment)-[:default_outfit]-(d:garment) RETURN
|
||||
// a.garment_id,b.garment_id,c.garment_id,d.garment_id
|
||||
|
||||
// TODO: figure out from the pattern in a query
|
||||
constexpr size_t max_depth = 3;
|
||||
@@ -24,162 +27,143 @@ constexpr size_t max_depth = 3;
|
||||
// TODO: from query LIMIT 10
|
||||
constexpr size_t limit = 10;
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node *parent = {nullptr};
|
||||
VertexPropertyType<Float> tkey;
|
||||
double cost;
|
||||
int depth = {0};
|
||||
double sum = {0.0};
|
||||
VertexAccessor vacc;
|
||||
class Node {
|
||||
public:
|
||||
Node *parent = {nullptr};
|
||||
VertexPropertyType<Float> tkey;
|
||||
double cost;
|
||||
int depth = {0};
|
||||
double sum = {0.0};
|
||||
VertexAccessor vacc;
|
||||
|
||||
Node(VertexAccessor vacc, double cost,
|
||||
VertexPropertyType<Float> const &tkey)
|
||||
: cost(cost), vacc(vacc), tkey(tkey)
|
||||
{
|
||||
}
|
||||
Node(VertexAccessor vacc, double cost, Node *parent,
|
||||
VertexPropertyType<Float> const &tkey)
|
||||
: cost(cost), vacc(vacc), parent(parent), depth(parent->depth + 1),
|
||||
tkey(tkey)
|
||||
{
|
||||
}
|
||||
Node(VertexAccessor vacc, double cost, VertexPropertyType<Float> const &tkey)
|
||||
: cost(cost), vacc(vacc), tkey(tkey) {}
|
||||
Node(VertexAccessor vacc, double cost, Node *parent,
|
||||
VertexPropertyType<Float> const &tkey)
|
||||
: cost(cost),
|
||||
vacc(vacc),
|
||||
parent(parent),
|
||||
depth(parent->depth + 1),
|
||||
tkey(tkey) {}
|
||||
|
||||
double sum_vertex_score()
|
||||
{
|
||||
auto now = this;
|
||||
double sum = 0;
|
||||
do
|
||||
{
|
||||
sum += (now->vacc.at(tkey).get())->value();
|
||||
now = now->parent;
|
||||
} while (now != nullptr);
|
||||
this->sum = sum;
|
||||
return sum;
|
||||
}
|
||||
double sum_vertex_score() {
|
||||
auto now = this;
|
||||
double sum = 0;
|
||||
do {
|
||||
sum += (now->vacc.at(tkey).get())->value();
|
||||
now = now->parent;
|
||||
} while (now != nullptr);
|
||||
this->sum = sum;
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before)
|
||||
{
|
||||
if (v.fill())
|
||||
{
|
||||
bool found;
|
||||
do
|
||||
{
|
||||
found = false;
|
||||
before = before->parent;
|
||||
if (before == nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} while (v.in_contains(before->vacc));
|
||||
}
|
||||
return false;
|
||||
bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before) {
|
||||
if (v.fill()) {
|
||||
bool found;
|
||||
do {
|
||||
found = false;
|
||||
before = before->parent;
|
||||
if (before == nullptr) {
|
||||
return true;
|
||||
}
|
||||
} while (v.in_contains(before->vacc));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
auto astar(VertexAccessor &va, DbAccessor &t, plan_args_t &, Stream &)
|
||||
{
|
||||
StackAllocator stack;
|
||||
std::vector<Node *> results;
|
||||
auto astar(VertexAccessor &va, DbAccessor &t, plan_args_t &, Stream &) {
|
||||
StackAllocator stack;
|
||||
std::vector<Node *> results;
|
||||
|
||||
// TODO: variable part (extract)
|
||||
VertexPropertyType<Float> tkey = t.vertex_property_key<Float>("score");
|
||||
// TODO: variable part (extract)
|
||||
VertexPropertyType<Float> tkey = t.vertex_property_key<Float>("score");
|
||||
|
||||
auto cmp = [](Node *left, Node *right) { return left->cost > right->cost; };
|
||||
std::priority_queue<Node *, std::vector<Node *>, decltype(cmp)> queue(cmp);
|
||||
auto cmp = [](Node *left, Node *right) { return left->cost > right->cost; };
|
||||
std::priority_queue<Node *, std::vector<Node *>, decltype(cmp)> queue(cmp);
|
||||
|
||||
Node *start = new (stack.allocate<Node>()) Node(va, 0, tkey);
|
||||
queue.push(start);
|
||||
Node *start = new (stack.allocate<Node>()) Node(va, 0, tkey);
|
||||
queue.push(start);
|
||||
|
||||
size_t count = 0;
|
||||
do
|
||||
{
|
||||
auto now = queue.top();
|
||||
queue.pop();
|
||||
size_t count = 0;
|
||||
do {
|
||||
auto now = queue.top();
|
||||
queue.pop();
|
||||
|
||||
if (now->depth >= max_depth)
|
||||
{
|
||||
now->sum_vertex_score();
|
||||
results.emplace_back(now);
|
||||
if (now->depth >= max_depth) {
|
||||
now->sum_vertex_score();
|
||||
results.emplace_back(now);
|
||||
|
||||
count++;
|
||||
count++;
|
||||
|
||||
if (count >= limit)
|
||||
{
|
||||
// the limit was reached -> STOP the execution
|
||||
break;
|
||||
}
|
||||
if (count >= limit) {
|
||||
// the limit was reached -> STOP the execution
|
||||
break;
|
||||
}
|
||||
|
||||
// if the limit wasn't reached -> POP the next vertex
|
||||
continue;
|
||||
}
|
||||
|
||||
iter::for_all(now->vacc.out(), [&](auto edge) {
|
||||
VertexAccessor va = edge.to();
|
||||
if (vertex_filter_contained(t, va, now))
|
||||
{
|
||||
auto cost = 1 - va.at(tkey).get()->value();
|
||||
Node *n = new (stack.allocate<Node>())
|
||||
Node(va, now->cost + cost, now, tkey);
|
||||
queue.push(n);
|
||||
}
|
||||
});
|
||||
} while (!queue.empty());
|
||||
|
||||
stack.free();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
void reverse_stream_ids(Node *node, Stream& stream, VertexPropertyKey key)
|
||||
{
|
||||
if (node == nullptr)
|
||||
return;
|
||||
reverse_stream_ids(node->parent, stream, key);
|
||||
stream.write(node->vacc.at(key).template as<Int64>());
|
||||
}
|
||||
|
||||
class PlanCPU : 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");
|
||||
auto garment_id_prop_key =
|
||||
t.vertex_property_key("garment_id", args[0].key.flags());
|
||||
|
||||
stream.write_fields(
|
||||
{{"a.garment_id", "b.garment_id", "c.garment_id", "d.garment_id"}});
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) {
|
||||
auto results = astar(va, t, args, stream);
|
||||
std::sort(results.begin(), results.end(),
|
||||
[](Node *a, Node *b) { return a->sum > b->sum; });
|
||||
for (auto node : results)
|
||||
{
|
||||
stream.write_record();
|
||||
stream.write_list_header(max_depth + 1);
|
||||
reverse_stream_ids(node, stream, garment_id_prop_key);
|
||||
}
|
||||
});
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("r");
|
||||
|
||||
return t.commit();
|
||||
// if the limit wasn't reached -> POP the next vertex
|
||||
continue;
|
||||
}
|
||||
|
||||
~PlanCPU() {}
|
||||
iter::for_all(now->vacc.out(), [&](auto edge) {
|
||||
VertexAccessor va = edge.to();
|
||||
if (vertex_filter_contained(t, va, now)) {
|
||||
auto cost = 1 - va.at(tkey).get()->value();
|
||||
Node *n =
|
||||
new (stack.allocate<Node>()) Node(va, now->cost + cost, now, tkey);
|
||||
queue.push(n);
|
||||
}
|
||||
});
|
||||
} while (!queue.empty());
|
||||
|
||||
stack.free();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
void reverse_stream_ids(Node *node, Stream &stream, VertexPropertyKey key) {
|
||||
if (node == nullptr) return;
|
||||
reverse_stream_ids(node->parent, stream, key);
|
||||
stream.write(node->vacc.at(key).template as<Int64>());
|
||||
}
|
||||
|
||||
class PlanCPU : 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");
|
||||
auto garment_id_prop_key =
|
||||
t.vertex_property_key("garment_id", args[0].key.flags());
|
||||
|
||||
stream.write_fields(
|
||||
{{"a.garment_id", "b.garment_id", "c.garment_id", "d.garment_id"}});
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) {
|
||||
auto results = astar(va, t, args, stream);
|
||||
std::sort(results.begin(), results.end(),
|
||||
[](Node *a, Node *b) { return a->sum > b->sum; });
|
||||
for (auto node : results) {
|
||||
stream.write_record();
|
||||
stream.write_list_header(max_depth + 1);
|
||||
reverse_stream_ids(node, stream, garment_id_prop_key);
|
||||
}
|
||||
});
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("r");
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~PlanCPU() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream> *produce() { return new PlanCPU(); }
|
||||
|
||||
@@ -1,58 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// Query: CREATE (n:ACCOUNT {id: 2322, name: "TEST", country: "Croatia", "created_at": 2352352}) RETURN n
|
||||
// Query: CREATE (n:ACCOUNT {id: 2322, name: "TEST", country: "Croatia",
|
||||
// "created_at": 2352352}) RETURN n
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto prop_id = t.vertex_property_key("id", args[0].key.flags());
|
||||
auto prop_name = t.vertex_property_key("name", args[1].key.flags());
|
||||
auto prop_country = t.vertex_property_key("country", args[2].key.flags());
|
||||
auto prop_created =
|
||||
t.vertex_property_key("created_at", args[3].key.flags());
|
||||
|
||||
auto prop_id = t.vertex_property_key("id", args[0].key.flags());
|
||||
auto prop_name = t.vertex_property_key("name", args[1].key.flags());
|
||||
auto prop_country =
|
||||
t.vertex_property_key("country", args[2].key.flags());
|
||||
auto prop_created =
|
||||
t.vertex_property_key("created_at", args[3].key.flags());
|
||||
auto &label = t.label_find_or_create("ACCOUNT");
|
||||
|
||||
auto &label = t.label_find_or_create("ACCOUNT");
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(prop_id, std::move(args[0]));
|
||||
vertex_accessor.set(prop_name, std::move(args[1]));
|
||||
vertex_accessor.set(prop_country, std::move(args[2]));
|
||||
vertex_accessor.set(prop_created, std::move(args[3]));
|
||||
vertex_accessor.add_label(label);
|
||||
|
||||
vertex_accessor.set(prop_id, std::move(args[0]));
|
||||
vertex_accessor.set(prop_name, std::move(args[1]));
|
||||
vertex_accessor.set(prop_country, std::move(args[2]));
|
||||
vertex_accessor.set(prop_created, std::move(args[3]));
|
||||
vertex_accessor.add_label(label);
|
||||
stream.write_field("p");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("p");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
@@ -12,41 +12,32 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (a {id:0}), (p {id: 1}) CREATE (a)-[r:IS]->(p) RETURN r
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
auto &edge_type = t.type_find_or_create("IS");
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto &edge_type = t.type_find_or_create("IS");
|
||||
auto v1 = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(v1)) return t.commit(), false;
|
||||
|
||||
auto v1 = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(v1)) return t.commit(), false;
|
||||
auto v2 = t.vertex_find(args[1].as<Int64>().value());
|
||||
if (!option_fill(v2)) return t.commit(), false;
|
||||
|
||||
auto v2 = t.vertex_find(args[1].as<Int64>().value());
|
||||
if (!option_fill(v2)) return t.commit(), false;
|
||||
auto edge_accessor = t.edge_insert(v1.get(), v2.get());
|
||||
|
||||
auto edge_accessor = t.edge_insert(v1.get(), v2.get());
|
||||
edge_accessor.edge_type(edge_type);
|
||||
|
||||
edge_accessor.edge_type(edge_type);
|
||||
stream.write_field("r");
|
||||
stream.write_edge_record(edge_accessor);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("r");
|
||||
stream.write_edge_record(edge_accessor);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,43 +11,31 @@ using std::endl;
|
||||
|
||||
// Query: CREATE (p:profile {profile_id: 112, partner_id: 55}) RETURN p
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
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 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 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);
|
||||
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
va.add_label(profile);
|
||||
stream.write_field("p");
|
||||
stream.write_vertex_record(va);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("p");
|
||||
stream.write_vertex_record(va);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
@@ -12,37 +12,28 @@ using std::endl;
|
||||
|
||||
// Query: CREATE (n:LABEL {name: "TEST"}) RETURN n
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto property_key = t.vertex_property_key("name", args[0].key.flags());
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
|
||||
auto property_key = t.vertex_property_key("name", args[0].key.flags());
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
@@ -12,37 +12,28 @@ using std::endl;
|
||||
|
||||
// Query: CREATE (n:OTHER {name: "cleaner_test"}) RETURN n
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto property_key = t.vertex_property_key("name", args[0].key.flags());
|
||||
auto &label = t.label_find_or_create("OTHER");
|
||||
|
||||
auto property_key = t.vertex_property_key("name", args[0].key.flags());
|
||||
auto &label = t.label_find_or_create("OTHER");
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
@@ -12,35 +12,26 @@ using std::endl;
|
||||
|
||||
// Query: CREATE (n {prop: 0}) RETURN n
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto property_key = t.vertex_property_key("prop", args[0].key.flags());
|
||||
|
||||
auto property_key = t.vertex_property_key("prop", args[0].key.flags());
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_field("n");
|
||||
stream.write_vertex_record(vertex_accessor);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,42 +11,32 @@ using std::endl;
|
||||
|
||||
// Query: CREATE (g:garment {garment_id: 1236, garment_category_id: 1}) RETURN g
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
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 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 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);
|
||||
|
||||
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");
|
||||
|
||||
stream.write_field("g");
|
||||
stream.write_vertex_record(va);
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,33 +11,23 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (n) DETACH DELETE n
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
t.edge_access().fill().for_all([&](auto e) { e.remove(); });
|
||||
t.vertex_access().fill().isolated().for_all([&](auto a) { a.remove(); });
|
||||
|
||||
t.edge_access().fill().for_all([&](auto e) { e.remove(); });
|
||||
t.vertex_access().fill().isolated().for_all(
|
||||
[&](auto a) { a.remove(); });
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,40 +11,30 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (p:garment {garment_id: 1}) DELETE g
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
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);
|
||||
|
||||
indices_t indices = {{"garment_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) { va.remove(); });
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) { va.remove(); });
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,40 +11,30 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (p:profile {profile_id: 1}) DELETE p
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
indices_t indices = {{"profile_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
|
||||
indices_t indices = {{"profile_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("profile");
|
||||
|
||||
auto &label = t.label_find_or_create("profile");
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) { va.remove(); });
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) { va.remove(); });
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,91 +1,82 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// Query: MATCH (p:profile {profile_id: 111, partner_id:55})-[s:score]-(g:garment {garment_id: 1234}) DELETE s
|
||||
// Query: MATCH (p:profile {profile_id: 111,
|
||||
// partner_id:55})-[s:score]-(g:garment {garment_id: 1234}) DELETE s
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
// TODO: decide path (which index is better)
|
||||
// 3 options p->s->g, g->s->p, g<-s->p
|
||||
// NOTE! both direections have to be chacked
|
||||
// because pattern is non directional
|
||||
// OR
|
||||
// even better, use index on label and property
|
||||
|
||||
// TODO: decide path (which index is better)
|
||||
// 3 options p->s->g, g->s->p, g<-s->p
|
||||
// NOTE! both direections have to be chacked
|
||||
// because pattern is non directional
|
||||
// OR
|
||||
// even better, use index on label and property
|
||||
// just one option p->s->g!
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e1.get().update();
|
||||
ea.remove();
|
||||
});
|
||||
|
||||
// just one option p->s->g!
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e1.get().update();
|
||||
ea.remove();
|
||||
});
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e2.get().update();
|
||||
ea.remove();
|
||||
});
|
||||
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e2.get().update();
|
||||
ea.remove();
|
||||
});
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_empty_fields();
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,89 +1,80 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// Query: MATCH (p:profile {profile_id: 111, partner_id:55})-[s:score]-(g:garment {garment_id: 1234}) SET s.score = 1550 RETURN s.score
|
||||
// Query: MATCH (p:profile {profile_id: 111,
|
||||
// partner_id:55})-[s:score]-(g:garment {garment_id: 1234}) SET s.score = 1550
|
||||
// RETURN s.score
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
// TODO: decide path (which index is better)
|
||||
// 3 options p->s->g, g->s->p, g<-s->p
|
||||
// NOTE! both direections have to be chacked
|
||||
// because pattern is non directional
|
||||
// OR
|
||||
// even better, use index on label and property
|
||||
|
||||
// TODO: decide path (which index is better)
|
||||
// 3 options p->s->g, g->s->p, g<-s->p
|
||||
// NOTE! both direections have to be chacked
|
||||
// because pattern is non directional
|
||||
// OR
|
||||
// even better, use index on label and property
|
||||
// just one option p->s->g!
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e1.get().update();
|
||||
ea.set(score_key, std::move(args[3]));
|
||||
});
|
||||
|
||||
// just one option p->s->g!
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e1.get().update();
|
||||
ea.set(score_key, std::move(args[3]));
|
||||
});
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e2.get().update();
|
||||
ea.set(score_key, std::move(args[3]));
|
||||
});
|
||||
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
auto ea = e2.get().update();
|
||||
ea.set(score_key, std::move(args[3]));
|
||||
});
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
|
||||
return t.commit();
|
||||
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,54 +11,44 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (g:garment {garment_id: 1234}) SET g:FF RETURN labels(g)
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
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);
|
||||
|
||||
indices_t indices = {{"garment_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
|
||||
stream.write_field("labels(g)");
|
||||
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();
|
||||
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();
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
stream.write_meta("rw");
|
||||
stream.write_meta("rw");
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,47 +11,37 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (g:garment {garment_id: 3456}) SET g.reveals = 50 RETURN g
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto reveals_key = t.vertex_property_key("reveals", args[1].key.flags());
|
||||
|
||||
auto reveals_key =
|
||||
t.vertex_property_key("reveals", args[1].key.flags());
|
||||
indices_t indices = {{"garment_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
|
||||
indices_t indices = {{"garment_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
stream.write_field("g");
|
||||
|
||||
stream.write_field("g");
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.fill()
|
||||
.for_all([&](auto va) {
|
||||
va.set(reveals_key, args[1]);
|
||||
stream.write_vertex_record(va);
|
||||
});
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.fill()
|
||||
.for_all([&](auto va) {
|
||||
va.set(reveals_key, args[1]);
|
||||
stream.write_vertex_record(va);
|
||||
});
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,42 +11,31 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (p:profile {partner_id: 1}) RETURN p
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
indices_t indices = {{"partner_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
|
||||
indices_t indices = {{"partner_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("profile");
|
||||
|
||||
auto &label = t.label_find_or_create("profile");
|
||||
stream.write_field("p");
|
||||
|
||||
stream.write_field("p");
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) { stream.write_vertex_record(va); });
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) {
|
||||
stream.write_vertex_record(va);
|
||||
});
|
||||
stream.write_meta("r");
|
||||
|
||||
stream.write_meta("r");
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
@@ -11,42 +11,31 @@ using std::endl;
|
||||
|
||||
// Query: MATCH (g:garment {garment_id: 1}) RETURN g
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
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);
|
||||
|
||||
indices_t indices = {{"garment_id", 0}};
|
||||
auto properties = query_properties(indices, args);
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
|
||||
auto &label = t.label_find_or_create("garment");
|
||||
stream.write_field("g");
|
||||
|
||||
stream.write_field("g");
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) -> void { stream.write_vertex_record(va); });
|
||||
|
||||
label.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, properties)
|
||||
.for_all([&](auto va) -> void {
|
||||
stream.write_vertex_record(va);
|
||||
});
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,73 +1,65 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#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: MERGE (g1:garment {garment_id:1234})-[r:default_outfit]-(g2:garment {garment_id: 2345}) RETURN r
|
||||
// Query: MERGE (g1:garment {garment_id:1234})-[r:default_outfit]-(g2:garment
|
||||
// {garment_id: 2345}) RETURN r
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
// TODO: support for index on label and property
|
||||
|
||||
// TODO: support for index on label and property
|
||||
// prepare iterator for g1
|
||||
indices_t indices_1 = {{"garment_id", 0}};
|
||||
auto properties_1 = query_properties(indices_1, args);
|
||||
auto &label_1 = t.label_find_or_create("garment");
|
||||
|
||||
// prepare iterator for g1
|
||||
indices_t indices_1 = {{"garment_id", 0}};
|
||||
auto properties_1 = query_properties(indices_1, args);
|
||||
auto &label_1 = t.label_find_or_create("garment");
|
||||
auto it_vertex_1 =
|
||||
label_1.index().for_range(t).properties_filter(t, properties_1);
|
||||
|
||||
auto it_vertex_1 =
|
||||
label_1.index().for_range(t).properties_filter(t, properties_1);
|
||||
// prepare iterator for g1
|
||||
indices_t indices_2 = {{"garment_id", 1}};
|
||||
auto properties_2 = query_properties(indices_2, args);
|
||||
auto &label_2 = t.label_find_or_create("garment");
|
||||
|
||||
// prepare iterator for g1
|
||||
indices_t indices_2 = {{"garment_id", 1}};
|
||||
auto properties_2 = query_properties(indices_2, args);
|
||||
auto &label_2 = t.label_find_or_create("garment");
|
||||
auto it_vertex_2 =
|
||||
label_2.index().for_range(t).properties_filter(t, properties_2);
|
||||
|
||||
auto it_vertex_2 =
|
||||
label_2.index().for_range(t).properties_filter(t, properties_2);
|
||||
auto &edge_type = t.type_find_or_create("default_outfit");
|
||||
|
||||
auto &edge_type = t.type_find_or_create("default_outfit");
|
||||
// TODO: create g1 and g2 if don't exist
|
||||
|
||||
// TODO: create g1 and g2 if don't exist
|
||||
// TODO: figure out something better
|
||||
|
||||
// TODO: figure out something better
|
||||
stream.write_field("r");
|
||||
|
||||
stream.write_field("r");
|
||||
it_vertex_1.fill().for_all([&](auto va1) -> void {
|
||||
it_vertex_2.fill().for_all([&](auto va2) -> void {
|
||||
auto edge_accessor = t.edge_insert(va1, va2);
|
||||
edge_accessor.edge_type(edge_type);
|
||||
|
||||
it_vertex_1.fill().for_all([&](auto va1) -> void {
|
||||
it_vertex_2.fill().for_all([&](auto va2) -> void {
|
||||
auto edge_accessor = t.edge_insert(va1, va2);
|
||||
edge_accessor.edge_type(edge_type);
|
||||
stream.write_edge_record(edge_accessor);
|
||||
});
|
||||
});
|
||||
|
||||
stream.write_edge_record(edge_accessor);
|
||||
});
|
||||
});
|
||||
stream.write_meta("w");
|
||||
|
||||
stream.write_meta("w");
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,105 +1,97 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "query/util.hpp"
|
||||
#include "query/plan_interface.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "query/util.hpp"
|
||||
#include "storage/edge_x_vertex.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "using.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
// Query: MERGE (p:profile {profile_id: 111, partner_id: 55})-[s:score]-(g.garment {garment_id: 1234}) SET s.score=1500 RETURN s
|
||||
// Query: MERGE (p:profile {profile_id: 111, partner_id:
|
||||
// 55})-[s:score]-(g.garment {garment_id: 1234}) SET s.score=1500 RETURN s
|
||||
|
||||
class CPUPlan : public PlanInterface<Stream>
|
||||
{
|
||||
public:
|
||||
class CPUPlan : public PlanInterface<Stream> {
|
||||
public:
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override {
|
||||
DbAccessor t(db);
|
||||
|
||||
bool run(Db &db, const PlanArgsT &args, Stream &stream) override
|
||||
{
|
||||
DbAccessor t(db);
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
|
||||
auto &profile = t.label_find_or_create("profile");
|
||||
auto &score = t.type_find_or_create("score");
|
||||
auto &garment = t.label_find_or_create("garment");
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
|
||||
indices_t profile_ind = {{"profile_id", 0}, {"partner_id", 1}};
|
||||
indices_t garment_ind = {{"garment_id", 2}};
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
|
||||
auto profile_prop = query_properties(profile_ind, args);
|
||||
auto garment_prop = query_properties(garment_ind, args);
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
|
||||
auto score_key = t.edge_property_key("score", args[3].key.flags());
|
||||
|
||||
stream.write_field("s");
|
||||
stream.write_field("s");
|
||||
|
||||
// TODO: implement
|
||||
bool exists = false;
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
exists = true;
|
||||
auto ea = e1.get().update();
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
// TODO: implement
|
||||
bool exists = false;
|
||||
Option<const EdgeAccessor> e1;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.out()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.to()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
exists = true;
|
||||
auto ea = e1.get().update();
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
exists = true;
|
||||
auto ea = e2.get().update();
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
Option<const EdgeAccessor> e2;
|
||||
profile.index()
|
||||
.for_range(t)
|
||||
.properties_filter(t, profile_prop)
|
||||
.in()
|
||||
.type(score)
|
||||
.clone_to(e1)
|
||||
.from()
|
||||
.label(garment)
|
||||
.properties_filter(t, garment_prop)
|
||||
.for_all([&](auto va) -> void {
|
||||
exists = true;
|
||||
auto ea = e2.get().update();
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
|
||||
if (!exists) {
|
||||
auto it_vertex_garment =
|
||||
garment.index().for_range(t).properties_filter(t, garment_prop);
|
||||
auto it_vertex_profile =
|
||||
profile.index().for_range(t).properties_filter(t, profile_prop);
|
||||
if (!exists) {
|
||||
auto it_vertex_garment =
|
||||
garment.index().for_range(t).properties_filter(t, garment_prop);
|
||||
auto it_vertex_profile =
|
||||
profile.index().for_range(t).properties_filter(t, profile_prop);
|
||||
|
||||
it_vertex_profile.fill().for_all([&](auto va1) -> void {
|
||||
it_vertex_garment.fill().for_all([&](auto va2) -> void {
|
||||
auto ea = t.edge_insert(va1, va2);
|
||||
ea.edge_type(score);
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
stream.write_field("w");
|
||||
|
||||
return t.commit();
|
||||
it_vertex_profile.fill().for_all([&](auto va1) -> void {
|
||||
it_vertex_garment.fill().for_all([&](auto va2) -> void {
|
||||
auto ea = t.edge_insert(va1, va2);
|
||||
ea.edge_type(score);
|
||||
ea.set(score_key, args[3]);
|
||||
stream.write_edge_record(ea);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
stream.write_field("w");
|
||||
|
||||
return t.commit();
|
||||
}
|
||||
|
||||
~CPUPlan() {}
|
||||
};
|
||||
|
||||
extern "C" PlanInterface<Stream>* produce()
|
||||
{
|
||||
return new CPUPlan();
|
||||
}
|
||||
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
||||
|
||||
extern "C" void destruct(PlanInterface<Stream>* p)
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "query_engine_common.hpp"
|
||||
#include "dbms/dbms.hpp"
|
||||
#include "query_engine_common.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace tests::integration;
|
||||
@@ -13,25 +13,24 @@ Logger logger;
|
||||
* NOTE: The correctnes can be tested by custom Stream object.
|
||||
* NOTE: This test will be usefull to test generated query plans.
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/**
|
||||
* init arguments
|
||||
*/
|
||||
REGISTER_ARGS(argc, argv);
|
||||
int main(int argc, char *argv[]) {
|
||||
/**
|
||||
* init arguments
|
||||
*/
|
||||
REGISTER_ARGS(argc, argv);
|
||||
|
||||
/**
|
||||
* init engine
|
||||
*/
|
||||
auto log = init_logging("IntegrationQueryEngine");
|
||||
Dbms dbms;
|
||||
StreamT stream(std::cout);
|
||||
QueryEngineT query_engine;
|
||||
// IMPORTANT: PrintRecordStream can be replaces with a smarter
|
||||
// object that can test the results
|
||||
/**
|
||||
* init engine
|
||||
*/
|
||||
auto log = init_logging("IntegrationQueryEngine");
|
||||
Dbms dbms;
|
||||
StreamT stream(std::cout);
|
||||
QueryEngineT query_engine;
|
||||
// IMPORTANT: PrintRecordStream can be replaces with a smarter
|
||||
// object that can test the results
|
||||
|
||||
auto db_accessor = dbms.active();
|
||||
WarmUpEngine(log, query_engine, db_accessor, stream);
|
||||
auto db_accessor = dbms.active();
|
||||
WarmUpEngine(log, query_engine, db_accessor, stream);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -14,15 +14,13 @@ namespace fs = std::experimental::filesystem;
|
||||
#include "utils/string/file.hpp"
|
||||
#include "utils/string/trim.hpp"
|
||||
|
||||
namespace tests
|
||||
{
|
||||
namespace integration
|
||||
{
|
||||
namespace tests {
|
||||
namespace integration {
|
||||
|
||||
using namespace utils;
|
||||
using QueryHashesT = std::set<HashType>;
|
||||
using QueryHashesT = std::set<HashType>;
|
||||
using QueryEngineT = QueryEngine<PrintRecordStream>;
|
||||
using StreamT = PrintRecordStream;
|
||||
using StreamT = PrintRecordStream;
|
||||
|
||||
/**
|
||||
* Init logging for tested query_engine (test specific logger). It has to be
|
||||
@@ -32,11 +30,10 @@ using StreamT = PrintRecordStream;
|
||||
*
|
||||
* @return logger instance
|
||||
*/
|
||||
auto init_logging(const std::string &logger_name)
|
||||
{
|
||||
logging::init_sync();
|
||||
logging::log->pipe(std::make_unique<Stdout>());
|
||||
return logging::log->logger(logger_name);
|
||||
auto init_logging(const std::string &logger_name) {
|
||||
logging::init_sync();
|
||||
logging::log->pipe(std::make_unique<Stdout>());
|
||||
return logging::log->logger(logger_name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,26 +45,24 @@ auto init_logging(const std::string &logger_name)
|
||||
*
|
||||
* @return a set with all query hashes from the file
|
||||
*/
|
||||
auto LoadQueryHashes(Logger &log, const fs::path &path)
|
||||
{
|
||||
log.info("*** Get query hashes from the file defied with path ***");
|
||||
// the intention of following block is to get all hashes
|
||||
// for which query implementations have to be compiled
|
||||
// calculate all hashes from queries file
|
||||
QueryPreprocessor preprocessor;
|
||||
// hashes calculated from all queries in queries file
|
||||
QueryHashesT query_hashes;
|
||||
// fill the above set
|
||||
auto queries = utils::read_lines(path);
|
||||
for (auto &query : queries)
|
||||
{
|
||||
if (query.empty()) continue;
|
||||
query_hashes.insert(preprocessor.preprocess(query).hash);
|
||||
}
|
||||
permanent_assert(query_hashes.size() > 0,
|
||||
"At least one hash has to be present");
|
||||
log.info("{} different query hashes exist", query_hashes.size());
|
||||
return query_hashes;
|
||||
auto LoadQueryHashes(Logger &log, const fs::path &path) {
|
||||
log.info("*** Get query hashes from the file defied with path ***");
|
||||
// the intention of following block is to get all hashes
|
||||
// for which query implementations have to be compiled
|
||||
// calculate all hashes from queries file
|
||||
QueryPreprocessor preprocessor;
|
||||
// hashes calculated from all queries in queries file
|
||||
QueryHashesT query_hashes;
|
||||
// fill the above set
|
||||
auto queries = utils::read_lines(path);
|
||||
for (auto &query : queries) {
|
||||
if (query.empty()) continue;
|
||||
query_hashes.insert(preprocessor.preprocess(query).hash);
|
||||
}
|
||||
permanent_assert(query_hashes.size() > 0,
|
||||
"At least one hash has to be present");
|
||||
log.info("{} different query hashes exist", query_hashes.size());
|
||||
return query_hashes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,41 +76,38 @@ auto LoadQueryHashes(Logger &log, const fs::path &path)
|
||||
* @return void
|
||||
*/
|
||||
auto LoadQueryPlans(Logger &log, QueryEngineT &engine,
|
||||
const QueryHashesT &query_hashes, const fs::path &path)
|
||||
{
|
||||
log.info("*** Load/compile needed query implementations ***");
|
||||
QueryPreprocessor preprocessor;
|
||||
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: ");
|
||||
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)
|
||||
{
|
||||
// find query in the line
|
||||
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()));
|
||||
// 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
|
||||
if (query_hashes.find(preprocessor.preprocess(query).hash) ==
|
||||
query_hashes.end())
|
||||
continue;
|
||||
log.info("Path {} will be loaded.", plan_path.c_str());
|
||||
engine.ReloadCustom(query, plan_path);
|
||||
break;
|
||||
}
|
||||
const QueryHashesT &query_hashes, const fs::path &path) {
|
||||
log.info("*** Load/compile needed query implementations ***");
|
||||
QueryPreprocessor preprocessor;
|
||||
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: ");
|
||||
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) {
|
||||
// find query in the line
|
||||
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()));
|
||||
// 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
|
||||
if (query_hashes.find(preprocessor.preprocess(query).hash) ==
|
||||
query_hashes.end())
|
||||
continue;
|
||||
log.info("Path {} will be loaded.", plan_path.c_str());
|
||||
engine.ReloadCustom(query, plan_path);
|
||||
break;
|
||||
}
|
||||
permanent_assert(query_hashes.size() == engine.Size(),
|
||||
"Query engine doesn't contain appropriate number of query "
|
||||
"implementations");
|
||||
}
|
||||
permanent_assert(query_hashes.size() == engine.Size(),
|
||||
"Query engine doesn't contain appropriate number of query "
|
||||
"implementations");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,19 +121,18 @@ auto LoadQueryPlans(Logger &log, QueryEngineT &engine,
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine, GraphDbAccessor &db_accessor,
|
||||
const fs::path &path, StreamT &stream)
|
||||
{
|
||||
log.info("*** Execute the queries from the queries_file ***");
|
||||
// execute all queries from queries_file
|
||||
auto queries = utils::read_lines(path);
|
||||
for (auto &query : queries)
|
||||
{
|
||||
if (query.empty()) continue;
|
||||
permanent_assert(engine.Loaded(trim(query)),
|
||||
"Implementation wasn't loaded");
|
||||
engine.Run(query, db_accessor, stream);
|
||||
}
|
||||
auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine,
|
||||
GraphDbAccessor &db_accessor, const fs::path &path,
|
||||
StreamT &stream) {
|
||||
log.info("*** Execute the queries from the queries_file ***");
|
||||
// execute all queries from queries_file
|
||||
auto queries = utils::read_lines(path);
|
||||
for (auto &query : queries) {
|
||||
if (query.empty()) continue;
|
||||
permanent_assert(engine.Loaded(trim(query)),
|
||||
"Implementation wasn't loaded");
|
||||
engine.Run(query, db_accessor, stream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,24 +148,23 @@ auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine, GraphDbAccessor &db_ac
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
auto WarmUpEngine(Logger &log, QueryEngineT &engine, GraphDbAccessor &db_accessor,
|
||||
StreamT &stream)
|
||||
{
|
||||
// path to a file with queries
|
||||
auto queries_file = fs::path(
|
||||
GET_ARG("-q", "../data/queries/core/mg_basic_000.txt").get_string());
|
||||
// forlder with query implementations
|
||||
auto implementations_folder =
|
||||
fs::path(GET_ARG("-i", "../integration/hardcoded_query").get_string());
|
||||
auto WarmUpEngine(Logger &log, QueryEngineT &engine,
|
||||
GraphDbAccessor &db_accessor, StreamT &stream) {
|
||||
// path to a file with queries
|
||||
auto queries_file = fs::path(
|
||||
GET_ARG("-q", "../data/queries/core/mg_basic_000.txt").get_string());
|
||||
// forlder with query implementations
|
||||
auto implementations_folder =
|
||||
fs::path(GET_ARG("-i", "../integration/hardcoded_query").get_string());
|
||||
|
||||
// load all query hashes from queries file
|
||||
auto query_hashes = LoadQueryHashes(log, queries_file);
|
||||
// load all query hashes from queries file
|
||||
auto query_hashes = LoadQueryHashes(log, queries_file);
|
||||
|
||||
// load compile all needed query plans
|
||||
LoadQueryPlans(log, engine, query_hashes, implementations_folder);
|
||||
// load compile all needed query plans
|
||||
LoadQueryPlans(log, engine, query_hashes, implementations_folder);
|
||||
|
||||
// execute all loaded query plasn
|
||||
ExecuteQueryPlans(log, engine, db_accessor, queries_file, stream);
|
||||
// execute all loaded query plasn
|
||||
ExecuteQueryPlans(log, engine, db_accessor, queries_file, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
#include "utils/exceptions/not_yet_implemented.hpp"
|
||||
|
||||
class PrintRecordStream {
|
||||
private:
|
||||
private:
|
||||
std::ostream &stream;
|
||||
|
||||
public:
|
||||
public:
|
||||
PrintRecordStream(std::ostream &stream) : stream(stream) {}
|
||||
|
||||
void write_success() {
|
||||
stream << "SUCCESS\n";
|
||||
}
|
||||
void write_success() { stream << "SUCCESS\n"; }
|
||||
|
||||
void write_success_empty() {
|
||||
stream << "SUCCESS EMPTY\n";
|
||||
}
|
||||
void write_success_empty() { stream << "SUCCESS EMPTY\n"; }
|
||||
|
||||
void write_ignored() {
|
||||
stream << "IGNORED\n";
|
||||
}
|
||||
void write_ignored() { stream << "IGNORED\n"; }
|
||||
|
||||
void write_empty_fields() {
|
||||
stream << "EMPTY FIELDS\n";
|
||||
}
|
||||
void write_empty_fields() { stream << "EMPTY FIELDS\n"; }
|
||||
|
||||
void write_fields(const std::vector <std::string> &fields) {
|
||||
void write_fields(const std::vector<std::string> &fields) {
|
||||
stream << "FIELDS:";
|
||||
for (auto &field : fields) {
|
||||
stream << " " << field;
|
||||
@@ -42,47 +34,31 @@ public:
|
||||
stream << "Field: " << field << '\n';
|
||||
}
|
||||
|
||||
void write_list_header(size_t size) {
|
||||
stream << "List: " << size << '\n';
|
||||
}
|
||||
void write_list_header(size_t size) { stream << "List: " << size << '\n'; }
|
||||
|
||||
void write_record() {
|
||||
stream << "Record\n";
|
||||
}
|
||||
void write_record() { stream << "Record\n"; }
|
||||
|
||||
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) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
|
||||
void write_count(const size_t count) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void write_count(const size_t count) { throw NotYetImplemented(); }
|
||||
|
||||
void write(const VertexAccessor &vertex) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void write(const VertexAccessor &vertex) { throw NotYetImplemented(); }
|
||||
|
||||
void write_vertex_record(const VertexAccessor &va) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
|
||||
void write(const EdgeAccessor &edge) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void write(const EdgeAccessor &edge) { throw NotYetImplemented(); }
|
||||
|
||||
void write_edge_record(const EdgeAccessor &ea) {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void write_edge_record(const EdgeAccessor &ea) { throw NotYetImplemented(); }
|
||||
|
||||
void send() {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void send() { throw NotYetImplemented(); }
|
||||
|
||||
void chunk() {
|
||||
throw NotYetImplemented();
|
||||
}
|
||||
void chunk() { throw NotYetImplemented(); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user