2017-02-23 21:19:52 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2017-03-01 02:38:57 +08:00
|
|
|
#include "query/backend/cpp/typed_value.hpp"
|
2017-02-23 21:19:52 +08:00
|
|
|
#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:
|
2017-03-01 02:38:57 +08:00
|
|
|
bool run(GraphDbAccessor &db_accessor, const PropertyValueStore<> &args,
|
2017-02-23 21:19:52 +08:00
|
|
|
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"))) {
|
2017-03-01 02:38:57 +08:00
|
|
|
TypedValue prop = g1.PropsAt(db_accessor.property("garment_id"));
|
|
|
|
if (prop.type() == TypedValue::Type::Null) continue;
|
2017-02-23 21:19:52 +08:00
|
|
|
auto cmp = prop == args.at(0);
|
2017-03-01 02:38:57 +08:00
|
|
|
if (cmp.type() != TypedValue::Type::Bool) continue;
|
2017-02-23 21:19:52 +08:00
|
|
|
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"));
|
2017-03-01 02:38:57 +08:00
|
|
|
if (prop.type() == PropertyValue::Type::Null) continue;
|
2017-02-23 21:19:52 +08:00
|
|
|
auto cmp = prop == args.at(1);
|
2017-03-01 02:38:57 +08:00
|
|
|
if (cmp.type() != TypedValue::Type::Bool) continue;
|
2017-02-23 21:19:52 +08:00
|
|
|
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");
|
2017-02-24 18:27:54 +08:00
|
|
|
db_accessor.transaction_.commit();
|
|
|
|
return true;
|
2017-02-23 21:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~CPUPlan() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
|
|
|
|
|
|
|
|
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }
|