merged interface branch

This commit is contained in:
Marko Budiselic
2016-08-19 11:28:10 +01:00
95 changed files with 2435 additions and 766 deletions

View File

@@ -1,11 +1,15 @@
#pragma once
#include "database/db.hpp"
#include "database/db_accessor.cpp"
#include "database/db_accessor.hpp"
#include "query_engine/query_stripper.hpp"
#include "query_engine/util.hpp"
#include "storage/indexes/impl/nonunique_unordered_index.cpp"
#include "storage/model/properties/property.hpp"
#include "storage/model/properties/property_family.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/iterator/iterator.hpp"
auto load_queries(Db &db)
{
@@ -14,8 +18,12 @@ auto load_queries(Db &db)
// CREATE (n {prop: 0}) RETURN n)
auto create_node = [&db](const properties_t &args) {
DbAccessor t(db);
auto prop_key = t.vertex_property_family_get("prop")
.get(args[0]->flags)
.family_key();
auto vertex_accessor = t.vertex_insert();
vertex_accessor.property("prop", args[0]);
vertex_accessor.set(prop_key, args[0]);
t.commit();
return true;
};
@@ -23,8 +31,12 @@ auto load_queries(Db &db)
auto create_labeled_and_named_node = [&db](const properties_t &args) {
DbAccessor t(db);
auto prop_key = t.vertex_property_family_get("name")
.get(args[0]->flags)
.family_key();
auto vertex_accessor = t.vertex_insert();
vertex_accessor.property("name", args[0]);
vertex_accessor.set(prop_key, args[0]);
auto &label = t.label_find_or_create("LABEL");
vertex_accessor.add_label(label);
cout_properties(vertex_accessor.properties());
@@ -34,11 +46,23 @@ auto load_queries(Db &db)
auto create_account = [&db](const properties_t &args) {
DbAccessor t(db);
auto prop_id =
t.vertex_property_family_get("id").get(args[0]->flags).family_key();
auto prop_name = t.vertex_property_family_get("name")
.get(args[1]->flags)
.family_key();
auto prop_country = t.vertex_property_family_get("country")
.get(args[2]->flags)
.family_key();
auto prop_created = t.vertex_property_family_get("created_at")
.get(args[3]->flags)
.family_key();
auto vertex_accessor = t.vertex_insert();
vertex_accessor.property("id", args[0]);
vertex_accessor.property("name", args[1]);
vertex_accessor.property("country", args[2]);
vertex_accessor.property("created_at", args[3]);
vertex_accessor.set(prop_id, args[0]);
vertex_accessor.set(prop_name, args[1]);
vertex_accessor.set(prop_country, args[2]);
vertex_accessor.set(prop_created, args[3]);
auto &label = t.label_find_or_create("ACCOUNT");
vertex_accessor.add_label(label);
cout_properties(vertex_accessor.properties());
@@ -48,13 +72,13 @@ auto load_queries(Db &db)
auto find_node_by_internal_id = [&db](const properties_t &args) {
DbAccessor t(db);
auto id = static_cast<Int32 &>(*args[0]);
auto vertex_accessor = t.vertex_find(Id(id.value));
if (!vertex_accessor) {
auto maybe_va = t.vertex_find(Id(args[0]->as<Int32>().value));
if (!option_fill(maybe_va)) {
cout << "vertex doesn't exist" << endl;
t.commit();
return false;
}
auto vertex_accessor = maybe_va.get();
cout_properties(vertex_accessor.properties());
cout << "LABELS:" << endl;
for (auto label_ref : vertex_accessor.labels()) {
@@ -68,12 +92,12 @@ auto load_queries(Db &db)
DbAccessor t(db);
auto v1 = t.vertex_find(args[0]->as<Int32>().value);
if (!v1) return t.commit(), false;
if (!option_fill(v1)) return t.commit(), false;
auto v2 = t.vertex_find(args[1]->as<Int32>().value);
if (!v2) return t.commit(), false;
if (!option_fill(v2)) return t.commit(), false;
auto edge_accessor = t.edge_insert(v1.vlist, v2.vlist);
auto edge_accessor = t.edge_insert(v1.get(), v2.get());
auto &edge_type = t.type_find_or_create("IS");
edge_accessor.edge_type(edge_type);
@@ -89,19 +113,24 @@ auto load_queries(Db &db)
auto find_edge_by_internal_id = [&db](const properties_t &args) {
DbAccessor t(db);
auto edge_accessor = t.edge_find(args[0]->as<Int32>().value);
if (!edge_accessor) return t.commit(), false;
auto maybe_ea = t.edge_find(args[0]->as<Int32>().value);
if (!option_fill(maybe_ea)) return t.commit(), false;
auto edge_accessor = maybe_ea.get();
// print edge type and properties
cout << "EDGE_TYPE: " << edge_accessor.edge_type() << endl;
auto from = edge_accessor.from();
if (!from.fill()) return t.commit(), false;
cout << "FROM:" << endl;
cout_properties(from.record->data.props);
cout_properties(from->data.props);
auto to = edge_accessor.to();
if (!to.fill()) return t.commit(), false;
cout << "TO:" << endl;
cout_properties(to.record->data.props);
cout_properties(to->data.props);
t.commit();
@@ -110,11 +139,15 @@ auto load_queries(Db &db)
auto update_node = [&db](const properties_t &args) {
DbAccessor t(db);
auto prop_name = t.vertex_property_family_get("name")
.get(args[1]->flags)
.family_key();
auto v = t.vertex_find(args[0]->as<Int32>().value);
if (!v) return t.commit(), false;
auto maybe_v = t.vertex_find(args[0]->as<Int32>().value);
if (!option_fill(maybe_v)) return t.commit(), false;
auto v = maybe_v.get();
v.property("name", args[1]);
v.set(prop_name, args[1]);
cout_properties(v.properties());
t.commit();
@@ -126,13 +159,20 @@ auto load_queries(Db &db)
// weight: 70}]-(n2) RETURN r
auto create_edge_v2 = [&db](const properties_t &args) {
DbAccessor t(db);
auto prop_age =
t.edge_property_family_get("age").get(args[2]->flags).family_key();
auto prop_weight = t.edge_property_family_get("weight")
.get(args[3]->flags)
.family_key();
auto n1 = t.vertex_find(args[0]->as<Int64>().value);
if (!n1) return t.commit(), false;
if (!option_fill(n1)) return t.commit(), false;
auto n2 = t.vertex_find(args[1]->as<Int64>().value);
if (!n2) return t.commit(), false;
auto r = t.edge_insert(n2.vlist, n1.vlist);
r.property("age", args[2]);
r.property("weight", args[3]);
if (!option_fill(n2)) return t.commit(), false;
auto r = t.edge_insert(n2.get(), n1.get());
r.set(prop_age, args[2]);
r.set(prop_weight, args[3]);
auto &IS = t.type_find_or_create("IS");
r.edge_type(IS);
@@ -145,15 +185,11 @@ auto load_queries(Db &db)
auto match_all_nodes = [&db](const properties_t &args) {
DbAccessor t(db);
auto vertices_accessor = t.vertex_access();
for (auto &it : vertices_accessor) {
auto vertex = it.second.find(*t);
if (vertex == nullptr) continue;
cout_properties(vertex->data.props);
}
// TODO
// db.graph.vertices.filter().all(t, handler);
iter::for_all(t.vertex_access(), [&](auto vertex) {
if (vertex.fill()) {
cout_properties(vertex->data.props);
}
});
t.commit();
@@ -166,21 +202,17 @@ auto load_queries(Db &db)
DbAccessor t(db);
auto &label = t.label_find_or_create("LABEL");
auto prop_key =
t.vertex_property_family_get("name").get(Type::String).family_key();
auto &index_record_collection = t.label_find_index(label);
auto accessor = index_record_collection.access();
cout << "VERTICES" << endl;
for (auto &v : accessor) {
cout << v.record->data.props.at("name").as<String>().value << endl;
}
// TODO
// db.graph.vertices.fileter("LABEL").all(t, handler);
iter::for_all(label.index->for_range_exact(t),
[&](auto a) { cout << a.at(prop_key) << endl; });
return true;
};
queries[4857652843629217005u] = find_by_label;
queries[4857652843629217005u] = find_by_label;
queries[10597108978382323595u] = create_account;
queries[5397556489557792025u] = create_labeled_and_named_node;
queries[7939106225150551899u] = create_edge;

View File

@@ -40,5 +40,4 @@ std::string code_line(const std::string &format_str, const Args &... args)
{
return "\t" + format(format_str, args...) + "\n";
}
}