memgraph/tests/integration/hardcoded_query/match_garment_default_outfit.cpp
florijan 1d112e1141 GraphDbAccessor - style change
Summary: Not strictly neccessary, but it's been itching me. It took an hour.

Reviewers: buda, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D648
2017-08-09 16:09:08 +02:00

61 lines
2.0 KiB
C++

#include <iostream>
#include <string>
#include "query/parameters.hpp"
#include "query/plan_interface.hpp"
#include "query/typed_value.hpp"
#include "storage/edge_accessor.hpp"
#include "storage/vertex_accessor.hpp"
#include "using.hpp"
using std::cout;
using std::endl;
using query::TypedValue;
// 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 Parameters &args,
Stream &stream) {
std::vector<std::string> headers{std::string("r")};
stream.Header(headers);
std::vector<VertexAccessor> g1_set, g2_set;
for (auto g1 : db_accessor.Vertices(false)) {
if (g1.has_label(db_accessor.Label("garment"))) {
TypedValue prop = g1.PropsAt(db_accessor.Property("garment_id"));
if (prop.type() == TypedValue::Type::Null) continue;
auto cmp = prop == args.At(0).second;
if (cmp.type() != TypedValue::Type::Bool) continue;
if (cmp.Value<bool>() != true) continue;
g1_set.push_back(g1);
}
}
for (auto g2 : db_accessor.Vertices(false)) {
if (g2.has_label(db_accessor.Label("garment"))) {
auto prop = g2.PropsAt(db_accessor.Property("garment_id"));
if (prop.type() == PropertyValue::Type::Null) continue;
auto cmp = prop == args.At(1).second;
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.InsertEdge(
g1, g2, db_accessor.EdgeType("default_outfit"));
std::vector<TypedValue> result{TypedValue(e)};
stream.Result(result);
}
return true;
}
~CPUPlan() {}
};
extern "C" PlanInterface<Stream> *produce() { return new CPUPlan(); }
extern "C" void destruct(PlanInterface<Stream> *p) { delete p; }