tmp commit
tmp commit tmp commit v2 Finished reimplementation of propertys. They now can be placed in a holder with different source of type information. Tmp commit
This commit is contained in:
parent
95dd0a65b7
commit
5d235b51f3
@ -211,7 +211,6 @@ FILE(COPY ${include_dir}/storage/model/properties/properties.hpp DESTINATION ${b
|
||||
FILE(COPY ${include_dir}/storage/model/properties/property.hpp DESTINATION ${build_include_dir}/storage/model/properties)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/traversers/consolewriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/traversers/jsonwriter.hpp DESTINATION ${build_include_dir}/storage/model/properties/traversers)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/handler.hpp DESTINATION ${build_include_dir}/storage/model/properties)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/all.hpp DESTINATION ${build_include_dir}/storage/model/properties)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/bool.hpp DESTINATION ${build_include_dir}/storage/model/properties)
|
||||
FILE(COPY ${include_dir}/storage/model/properties/float.hpp DESTINATION ${build_include_dir}/storage/model/properties)
|
||||
@ -438,12 +437,16 @@ set(memgraph_src_files
|
||||
${src_dir}/storage/label/label_store.cpp
|
||||
${src_dir}/storage/edge_type/edge_type.cpp
|
||||
${src_dir}/storage/edge_type/edge_type_store.cpp
|
||||
${src_dir}/storage/model/properties/property.cpp
|
||||
${src_dir}/storage/model/properties/null.cpp
|
||||
${src_dir}/storage/model/properties/bool.cpp
|
||||
${src_dir}/storage/model/properties/int32.cpp
|
||||
${src_dir}/storage/model/properties/int64.cpp
|
||||
${src_dir}/storage/model/properties/float.cpp
|
||||
${src_dir}/storage/model/properties/double.cpp
|
||||
${src_dir}/storage/model/properties/string.cpp
|
||||
${src_dir}/storage/model/properties/array.cpp
|
||||
${src_dir}/storage/model/properties/properties.cpp
|
||||
${src_dir}/storage/model/properties/stored_property.cpp
|
||||
${src_dir}/storage/model/properties/property_family.cpp
|
||||
${src_dir}/storage/indexes/index_base.cpp
|
||||
${src_dir}/storage/indexes/index_record.cpp
|
||||
|
@ -147,17 +147,14 @@ public:
|
||||
|
||||
void remove() const;
|
||||
|
||||
const Property &at(VertexPropertyFamily &key) const;
|
||||
const StoredProperty<TypeGroupVertex> &at(VertexPropertyFamily &key) const;
|
||||
|
||||
const Property &at(VertexPropertyKey &key) const;
|
||||
const StoredProperty<TypeGroupVertex> &at(VertexPropertyKey &key) const;
|
||||
|
||||
template <class V>
|
||||
OptionPtr<V> at(VertexPropertyType<V> &key) const;
|
||||
OptionPtr<const V> at(VertexPropertyType<V> &key) const;
|
||||
|
||||
template <class V, class... Args>
|
||||
void set(VertexPropertyType<V> &key, Args &&... args);
|
||||
|
||||
void set(VertexPropertyKey &key, Property::sptr value);
|
||||
void set(VertexPropertyKey &key, Property &&value);
|
||||
|
||||
void clear(VertexPropertyKey &key);
|
||||
|
||||
@ -206,17 +203,14 @@ public:
|
||||
|
||||
void remove() const;
|
||||
|
||||
const Property &at(EdgePropertyFamily &key) const;
|
||||
const StoredProperty<TypeGroupEdge> &at(EdgePropertyFamily &key) const;
|
||||
|
||||
const Property &at(EdgePropertyKey &key) const;
|
||||
const StoredProperty<TypeGroupEdge> &at(EdgePropertyKey &key) const;
|
||||
|
||||
template <class V>
|
||||
OptionPtr<V> at(EdgePropertyType<V> &key) const;
|
||||
OptionPtr<const V> at(EdgePropertyType<V> &key) const;
|
||||
|
||||
template <class V, class... Args>
|
||||
void set(EdgePropertyType<V> &key, Args &&... args);
|
||||
|
||||
void set(EdgePropertyKey &key, Property::sptr value);
|
||||
void set(EdgePropertyKey &key, Property &&value);
|
||||
|
||||
void clear(EdgePropertyKey &key);
|
||||
|
||||
@ -474,15 +468,22 @@ public:
|
||||
|
||||
void write(const VertexAccessor &vertex);
|
||||
void write(const EdgeAccessor &edge);
|
||||
void write(const Property &prop);
|
||||
void write(const StoredProperty<TypeGroupVertex> &prop);
|
||||
void write(const StoredProperty<TypeGroupEdge> &prop);
|
||||
void write_null();
|
||||
void write(const Null &v);
|
||||
void write(const Bool &prop);
|
||||
void write(const Float &prop);
|
||||
void write(const Double &prop);
|
||||
void write(const Int32 &prop);
|
||||
void write(const Int64 &prop);
|
||||
void write(const std::string &value);
|
||||
void write(const String &prop);
|
||||
void write(const ArrayBool &);
|
||||
void write(const ArrayInt32 &);
|
||||
void write(const ArrayInt64 &);
|
||||
void write(const ArrayFloat &);
|
||||
void write(const ArrayDouble &);
|
||||
void write(const ArrayString &);
|
||||
|
||||
void write_success();
|
||||
void write_success_empty();
|
||||
|
@ -9,6 +9,8 @@
|
||||
// barrier.cpp
|
||||
#include "mvcc/id.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/stored_property.hpp"
|
||||
#include "utils/border.hpp"
|
||||
#include "utils/iterator/iterator.hpp"
|
||||
#include "utils/option_ptr.hpp"
|
||||
|
@ -161,7 +161,7 @@ namespace barrier
|
||||
// TRANSFORM_REF(, ::);
|
||||
// template <class T> TRANSFORM_REF_TEMPLATED(<T>,::<T>);
|
||||
|
||||
// ***************** TRANSFORMS of reference
|
||||
// ***************** TRANSFORMS of reference and pointers
|
||||
DUP(Label, TRANSFORM_REF);
|
||||
DUP(EdgeType, TRANSFORM_REF);
|
||||
DUP(VertexPropertyFamily, TRANSFORM_REF);
|
||||
|
@ -6,10 +6,10 @@
|
||||
#include "storage/edge_accessor.hpp"
|
||||
#include "storage/vertex_accessor.hpp"
|
||||
|
||||
#include "storage/edge_type/edge_type.hpp"
|
||||
#include "storage/label/label.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "storage/model/properties/properties.hpp"
|
||||
#include "storage/label/label.hpp"
|
||||
#include "storage/edge_type/edge_type.hpp"
|
||||
#include "storage/vertex_record.hpp"
|
||||
|
||||
namespace bolt
|
||||
@ -59,8 +59,8 @@ public:
|
||||
encoder.write_map_header(props.size());
|
||||
|
||||
for (auto &prop : props) {
|
||||
write(prop.first.family_name());
|
||||
write(*prop.second);
|
||||
write(prop.key.family_name());
|
||||
prop.accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,25 +77,41 @@ public:
|
||||
*/
|
||||
void write(const EdgeAccessor &edge);
|
||||
|
||||
void write(const Property &prop) { accept(prop, *this); }
|
||||
|
||||
void write_null() { encoder.write_null(); }
|
||||
|
||||
void write(const Null &v) { encoder.write_null(); }
|
||||
|
||||
void write(const Bool &prop) { encoder.write_bool(prop.value()); }
|
||||
|
||||
void write(const Float &prop) { encoder.write_double(prop.value); }
|
||||
void write(const Float &prop) { encoder.write_double(prop.value()); }
|
||||
|
||||
void write(const Double &prop) { encoder.write_double(prop.value); }
|
||||
void write(const Double &prop) { encoder.write_double(prop.value()); }
|
||||
|
||||
void write(const Int32 &prop) { encoder.write_integer(prop.value); }
|
||||
void write(const Int32 &prop) { encoder.write_integer(prop.value()); }
|
||||
|
||||
void write(const Int64 &prop) { encoder.write_integer(prop.value); }
|
||||
void write(const Int64 &prop) { encoder.write_integer(prop.value()); }
|
||||
|
||||
void write(const std::string &value) { encoder.write_string(value); }
|
||||
void write(const String &value) { encoder.write_string(value.value()); }
|
||||
|
||||
void write(const String &prop) { encoder.write_string(prop.value); }
|
||||
// Not yet implemented
|
||||
void write(const ArrayBool &) { assert(false); }
|
||||
|
||||
void write_failure(const std::map<std::string, std::string>& data)
|
||||
// Not yet implemented
|
||||
void write(const ArrayInt32 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void write(const ArrayInt64 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void write(const ArrayFloat &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void write(const ArrayDouble &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void write(const ArrayString &) { assert(false); }
|
||||
|
||||
void write_failure(const std::map<std::string, std::string> &data)
|
||||
{
|
||||
encoder.message_failure();
|
||||
encoder.write_map_header(data.size());
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
chunk();
|
||||
}
|
||||
|
||||
void write_field(const std::string& field)
|
||||
void write_field(const std::string &field)
|
||||
{
|
||||
bolt_encoder.message_success();
|
||||
bolt_encoder.write_map_header(1);
|
||||
@ -74,16 +74,13 @@ public:
|
||||
bolt_encoder.write_list_header(size);
|
||||
}
|
||||
|
||||
void write_record()
|
||||
{
|
||||
bolt_encoder.message_record();
|
||||
}
|
||||
void write_record() { bolt_encoder.message_record(); }
|
||||
|
||||
// writes metadata at the end of the message
|
||||
// TODO: write whole implementation (currently, only type is supported)
|
||||
// { "stats": { "nodes created": 1, "properties set": 1},
|
||||
// "type": "r" | "rw" | ...
|
||||
void write_meta(const std::string& type)
|
||||
void write_meta(const std::string &type)
|
||||
{
|
||||
bolt_encoder.message_success();
|
||||
bolt_encoder.write_map_header(1);
|
||||
@ -92,33 +89,41 @@ public:
|
||||
chunk();
|
||||
}
|
||||
|
||||
void write_failure(const std::map<std::string, std::string>& data)
|
||||
void write_failure(const std::map<std::string, std::string> &data)
|
||||
{
|
||||
serializer.write_failure(data);
|
||||
chunk();
|
||||
chunk();
|
||||
}
|
||||
// -- BOLT SPECIFIC METHODS -----------------------------------------------
|
||||
|
||||
void write(const VertexAccessor &vertex) { serializer.write(vertex); }
|
||||
void write(const EdgeAccessor &edge) { serializer.write(edge); }
|
||||
|
||||
void write(const Property &prop) { serializer.write(prop); }
|
||||
void write(const Bool& prop) { serializer.write(prop); }
|
||||
void write(const Float& prop) { serializer.write(prop); }
|
||||
void write(const Int32& prop) { serializer.write(prop); }
|
||||
void write(const Int64& prop) { serializer.write(prop); }
|
||||
void write(const Double& prop) { serializer.write(prop); }
|
||||
void write(const String& prop) { serializer.write(prop); }
|
||||
|
||||
void send()
|
||||
void write(const StoredProperty<TypeGroupEdge> &prop)
|
||||
{
|
||||
chunked_buffer.flush();
|
||||
prop.accept(serializer);
|
||||
}
|
||||
|
||||
void chunk()
|
||||
void write(const StoredProperty<TypeGroupVertex> &prop)
|
||||
{
|
||||
chunked_encoder.write_chunk();
|
||||
prop.accept(serializer);
|
||||
}
|
||||
void write(const Null &prop) { serializer.write(prop); }
|
||||
void write(const Bool &prop) { serializer.write(prop); }
|
||||
void write(const Float &prop) { serializer.write(prop); }
|
||||
void write(const Int32 &prop) { serializer.write(prop); }
|
||||
void write(const Int64 &prop) { serializer.write(prop); }
|
||||
void write(const Double &prop) { serializer.write(prop); }
|
||||
void write(const String &prop) { serializer.write(prop); }
|
||||
void write(const ArrayBool &prop) { serializer.write(prop); }
|
||||
void write(const ArrayInt32 &prop) { serializer.write(prop); }
|
||||
void write(const ArrayInt64 &prop) { serializer.write(prop); }
|
||||
void write(const ArrayFloat &prop) { serializer.write(prop); }
|
||||
void write(const ArrayDouble &prop) { serializer.write(prop); }
|
||||
void write(const ArrayString &prop) { serializer.write(prop); }
|
||||
|
||||
void send() { chunked_buffer.flush(); }
|
||||
|
||||
void chunk() { chunked_encoder.write_chunk(); }
|
||||
|
||||
void _write_test()
|
||||
{
|
||||
@ -152,6 +157,5 @@ private:
|
||||
chunked_encoder_t chunked_encoder{chunked_buffer};
|
||||
bolt_encoder_t bolt_encoder{chunked_encoder};
|
||||
bolt_serializer_t serializer{bolt_encoder};
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ private:
|
||||
|
||||
template <class TG>
|
||||
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey
|
||||
prop_key(const char *name, Flags type)
|
||||
property_key(const char *name, Flags type)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
@ -209,7 +209,7 @@ private:
|
||||
std::unique_ptr<Filler> f(
|
||||
name[0] == '\0' ? new IdFiller<TG>()
|
||||
: new IdFiller<TG>(make_option(
|
||||
prop_key<TG>(name, Flags::Int64))));
|
||||
property_key<TG>(name, Flags::Int64))));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "start_id") || equal_str(type, "from_id") ||
|
||||
@ -240,66 +240,66 @@ private:
|
||||
// return make_filler_property<BoolFiller>(vertex, name,
|
||||
// Flags::Bool);
|
||||
std::unique_ptr<Filler> f(
|
||||
new BoolFiller<TG>(prop_key<TG>(name, Flags::Bool)));
|
||||
new BoolFiller<TG>(property_key<TG>(name, Flags::Bool)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "double")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
new DoubleFiller<TG>(prop_key<TG>(name, Flags::Double)));
|
||||
new DoubleFiller<TG>(property_key<TG>(name, Flags::Double)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "float")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
new FloatFiller<TG>(prop_key<TG>(name, Flags::Float)));
|
||||
new FloatFiller<TG>(property_key<TG>(name, Flags::Float)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "int")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
new Int32Filler<TG>(prop_key<TG>(name, Flags::Int32)));
|
||||
new Int32Filler<TG>(property_key<TG>(name, Flags::Int32)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "long")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
new Int64Filler<TG>(prop_key<TG>(name, Flags::Int64)));
|
||||
new Int64Filler<TG>(property_key<TG>(name, Flags::Int64)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "string")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
new StringFiller<TG>(prop_key<TG>(name, Flags::String)));
|
||||
new StringFiller<TG>(property_key<TG>(name, Flags::String)));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "bool[]")) {
|
||||
std::unique_ptr<Filler> f(make_array_filler<TG, bool, ArrayBool>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayBool), to_bool));
|
||||
*this, property_key<TG>(name, Flags::ArrayBool), to_bool));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "float[]")) {
|
||||
std::unique_ptr<Filler> f(make_array_filler<TG, float, ArrayFloat>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayFloat), to_float));
|
||||
*this, property_key<TG>(name, Flags::ArrayFloat), to_float));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "double[]")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
make_array_filler<TG, double, ArrayDouble>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayDouble), to_double));
|
||||
*this, property_key<TG>(name, Flags::ArrayDouble), to_double));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "int[]")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
make_array_filler<TG, int32_t, ArrayInt32>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayInt32), to_int32));
|
||||
*this, property_key<TG>(name, Flags::ArrayInt32), to_int32));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "long[]")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
make_array_filler<TG, int64_t, ArrayInt64>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayInt64), to_int64));
|
||||
*this, property_key<TG>(name, Flags::ArrayInt64), to_int64));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else if (equal_str(type, "string[]")) {
|
||||
std::unique_ptr<Filler> f(
|
||||
make_array_filler<TG, string, ArrayString>(
|
||||
*this, prop_key<TG>(name, Flags::ArrayString), to_string));
|
||||
*this, property_key<TG>(name, Flags::ArrayString), to_string));
|
||||
return make_option(std::move(f));
|
||||
|
||||
} else {
|
||||
@ -326,14 +326,14 @@ private:
|
||||
|
||||
template <>
|
||||
PropertyFamily<TypeGroupVertex>::PropertyType::PropertyFamilyKey
|
||||
CSVImporter::prop_key<TypeGroupVertex>(const char *name, Flags type)
|
||||
CSVImporter::property_key<TypeGroupVertex>(const char *name, Flags type)
|
||||
{
|
||||
return db.vertex_property_key(name, Type(type));
|
||||
}
|
||||
|
||||
template <>
|
||||
PropertyFamily<TypeGroupEdge>::PropertyType::PropertyFamilyKey
|
||||
CSVImporter::prop_key<TypeGroupEdge>(const char *name, Flags type)
|
||||
CSVImporter::property_key<TypeGroupEdge>(const char *name, Flags type)
|
||||
{
|
||||
return db.edge_property_key(name, Type(type));
|
||||
}
|
||||
|
@ -10,43 +10,17 @@
|
||||
class ElementSkeleton
|
||||
{
|
||||
|
||||
class Prop
|
||||
{
|
||||
|
||||
public:
|
||||
Prop(VertexPropertyFamily::PropertyType::PropertyFamilyKey key,
|
||||
Option<std::shared_ptr<Property>> &&prop)
|
||||
: key_v(key), prop(std::move(prop))
|
||||
{
|
||||
}
|
||||
|
||||
Prop(EdgePropertyFamily::PropertyType::PropertyFamilyKey key,
|
||||
Option<std::shared_ptr<Property>> &&prop)
|
||||
: key_e(key), prop(std::move(prop))
|
||||
{
|
||||
}
|
||||
|
||||
union
|
||||
{
|
||||
VertexPropertyFamily::PropertyType::PropertyFamilyKey key_v;
|
||||
EdgePropertyFamily::PropertyType::PropertyFamilyKey key_e;
|
||||
};
|
||||
Option<std::shared_ptr<Property>> prop;
|
||||
};
|
||||
|
||||
public:
|
||||
ElementSkeleton(DbAccessor &db) : db(db){};
|
||||
|
||||
void add_property(VertexPropertyFamily::PropertyType::PropertyFamilyKey key,
|
||||
std::shared_ptr<Property> &&prop)
|
||||
void add_property(StoredProperty<TypeGroupVertex> &&prop)
|
||||
{
|
||||
properties.push_back(Prop(key, make_option(std::move(prop))));
|
||||
properties_v.push_back(std::move(prop));
|
||||
}
|
||||
|
||||
void add_property(EdgePropertyFamily::PropertyType::PropertyFamilyKey key,
|
||||
std::shared_ptr<Property> &&prop)
|
||||
void add_property(StoredProperty<TypeGroupEdge> &&prop)
|
||||
{
|
||||
properties.push_back(Prop(key, make_option(std::move(prop))));
|
||||
properties_e.push_back(std::move(prop));
|
||||
}
|
||||
|
||||
void set_element_id(size_t id)
|
||||
@ -77,9 +51,8 @@ public:
|
||||
va.add_label(*l);
|
||||
}
|
||||
|
||||
for (auto prop : properties) {
|
||||
assert(prop.prop.is_present());
|
||||
va.set(prop.key_v, prop.prop.take());
|
||||
for (auto prop : properties_v) {
|
||||
va.set(std::move(prop));
|
||||
}
|
||||
|
||||
return va;
|
||||
@ -100,9 +73,8 @@ public:
|
||||
ve.edge_type(*type.get());
|
||||
}
|
||||
|
||||
for (auto prop : properties) {
|
||||
assert(prop.prop.is_present());
|
||||
ve.set(prop.key_e, prop.prop.take());
|
||||
for (auto prop : properties_e) {
|
||||
ve.set(std::move(prop));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
@ -115,7 +87,8 @@ public:
|
||||
from_va = make_option<VertexAccessor>();
|
||||
type = make_option<EdgeType const *>();
|
||||
labels.clear();
|
||||
properties.clear();
|
||||
properties_v.clear();
|
||||
properties_e.clear();
|
||||
}
|
||||
|
||||
// Returns import local id.
|
||||
@ -138,5 +111,6 @@ private:
|
||||
Option<VertexAccessor> from_va;
|
||||
Option<EdgeType const *> type;
|
||||
std::vector<Label const *> labels;
|
||||
std::vector<Prop> properties;
|
||||
std::vector<StoredProperty<TypeGroupEdge>> properties_e;
|
||||
std::vector<StoredProperty<TypeGroupVertex>> properties_v;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
}
|
||||
}
|
||||
if (vec.size() > 0) {
|
||||
data.add_property(key, make_shared<A>(std::move(vec)));
|
||||
data.add_property(StoredProperty<TG>(A(std::move(vec)), key));
|
||||
}
|
||||
return make_option<std::string>();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<Bool>(to_bool(str)));
|
||||
data.add_property(StoredProperty<TG>(Bool(to_bool(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<Double>(to_double(str)));
|
||||
data.add_property(StoredProperty<TG>(Double(to_double(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<Float>(to_float(str)));
|
||||
data.add_property(StoredProperty<TG>(Float(to_float(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
if (str[0] != '\0') {
|
||||
data.set_element_id(atol(str));
|
||||
if (key.is_present()) {
|
||||
data.add_property(key.get(),
|
||||
std::make_shared<Int64>(to_int64(str)));
|
||||
data.add_property(
|
||||
StoredProperty<TG>(Int64(to_int64(str)), key.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<Int32>(to_int32(str)));
|
||||
data.add_property(StoredProperty<TG>(Int32(to_int32(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<Int64>(to_int64(str)));
|
||||
data.add_property(StoredProperty<TG>(Int64(to_int64(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
Option<std::string> fill(ElementSkeleton &data, char *str) final
|
||||
{
|
||||
if (str[0] != '\0') {
|
||||
data.add_property(key, std::make_shared<String>(to_string(str)));
|
||||
data.add_property(StoredProperty<TG>(String(to_string(str)), key));
|
||||
}
|
||||
|
||||
return make_option<std::string>();
|
||||
|
@ -11,64 +11,66 @@ namespace barrier
|
||||
{
|
||||
auto load_queries(Db &db)
|
||||
{
|
||||
std::map<uint64_t, std::function<bool(const properties_t &)>> queries;
|
||||
std::map<uint64_t, std::function<bool(properties_t &&)>> queries;
|
||||
|
||||
// CREATE (n {prop: 0}) RETURN n)
|
||||
auto create_node = [&db](const properties_t &args) {
|
||||
auto create_node = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_key = t.vertex_property_key("prop", args[0]->flags);
|
||||
auto property_key = t.vertex_property_key("prop", args[0].key.flags());
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(prop_key, args[0]);
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
return t.commit();
|
||||
};
|
||||
queries[11597417457737499503u] = create_node;
|
||||
|
||||
auto create_labeled_and_named_node = [&db](const properties_t &args) {
|
||||
auto create_labeled_and_named_node = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_key = t.vertex_property_key("name", args[0]->flags);
|
||||
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(prop_key, args[0]);
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
// cout_properties(vertex_accessor.properties());
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto create_labeled_and_named_node_v2 = [&db](const properties_t &args) {
|
||||
auto create_labeled_and_named_node_v2 = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_key = t.vertex_property_key("name", args[0]->flags);
|
||||
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(prop_key, args[0]);
|
||||
vertex_accessor.set(property_key, std::move(args[0]));
|
||||
vertex_accessor.add_label(label);
|
||||
// cout_properties(vertex_accessor.properties());
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto create_account = [&db](const properties_t &args) {
|
||||
auto create_account = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_id = t.vertex_property_key("id", args[0]->flags);
|
||||
auto prop_name = t.vertex_property_key("name", args[1]->flags);
|
||||
auto prop_country = t.vertex_property_key("country", args[2]->flags);
|
||||
auto prop_created = t.vertex_property_key("created_at", args[3]->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 vertex_accessor = t.vertex_insert();
|
||||
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]);
|
||||
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);
|
||||
// cout_properties(vertex_accessor.properties());
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto find_node_by_internal_id = [&db](const properties_t &args) {
|
||||
auto find_node_by_internal_id = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto maybe_va = t.vertex_find(Id(args[0]->as<Int32>().value));
|
||||
auto maybe_va = t.vertex_find(Id(args[0].as<Int64>().value()));
|
||||
if (!option_fill(maybe_va)) {
|
||||
cout << "vertex doesn't exist" << endl;
|
||||
t.commit();
|
||||
@ -83,14 +85,14 @@ auto load_queries(Db &db)
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto create_edge = [&db](const properties_t &args) {
|
||||
auto create_edge = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto &edge_type = t.type_find_or_create("IS");
|
||||
|
||||
auto v1 = t.vertex_find(args[0]->as<Int32>().value);
|
||||
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<Int32>().value);
|
||||
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());
|
||||
@ -106,9 +108,9 @@ auto load_queries(Db &db)
|
||||
return ret;
|
||||
};
|
||||
|
||||
auto find_edge_by_internal_id = [&db](const properties_t &args) {
|
||||
auto find_edge_by_internal_id = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto maybe_ea = t.edge_find(args[0]->as<Int32>().value);
|
||||
auto maybe_ea = t.edge_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(maybe_ea)) return t.commit(), false;
|
||||
auto edge_accessor = maybe_ea.get();
|
||||
|
||||
@ -130,15 +132,15 @@ auto load_queries(Db &db)
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto update_node = [&db](const properties_t &args) {
|
||||
auto update_node = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_name = t.vertex_property_key("name", args[1]->flags);
|
||||
auto prop_name = t.vertex_property_key("name", args[1].key.flags());
|
||||
|
||||
auto maybe_v = t.vertex_find(args[0]->as<Int32>().value);
|
||||
auto maybe_v = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(maybe_v)) return t.commit(), false;
|
||||
auto v = maybe_v.get();
|
||||
|
||||
v.set(prop_name, args[1]);
|
||||
v.set(prop_name, std::move(args[1]));
|
||||
// cout_properties(v.properties());
|
||||
|
||||
return t.commit();
|
||||
@ -146,19 +148,19 @@ auto load_queries(Db &db)
|
||||
|
||||
// MATCH (n1), (n2) WHERE ID(n1)=0 AND ID(n2)=1 CREATE (n1)<-[r:IS {age: 25,
|
||||
// weight: 70}]-(n2) RETURN r
|
||||
auto create_edge_v2 = [&db](const properties_t &args) {
|
||||
auto create_edge_v2 = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto prop_age = t.edge_property_key("age", args[2]->flags);
|
||||
auto prop_weight = t.edge_property_key("weight", args[3]->flags);
|
||||
auto prop_age = t.edge_property_key("age", args[2].key.flags());
|
||||
auto prop_weight = t.edge_property_key("weight", args[3].key.flags());
|
||||
|
||||
auto n1 = t.vertex_find(args[0]->as<Int64>().value);
|
||||
auto n1 = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(n1)) return t.commit(), false;
|
||||
auto n2 = t.vertex_find(args[1]->as<Int64>().value);
|
||||
auto n2 = t.vertex_find(args[1].as<Int64>().value());
|
||||
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]);
|
||||
r.set(prop_age, std::move(args[2]));
|
||||
r.set(prop_weight, std::move(args[3]));
|
||||
auto &IS = t.type_find_or_create("IS");
|
||||
r.edge_type(IS);
|
||||
|
||||
@ -166,7 +168,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n) RETURN n
|
||||
auto match_all_nodes = [&db](const properties_t &args) {
|
||||
auto match_all_nodes = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
t.vertex_access().fill().for_all(
|
||||
@ -176,21 +178,21 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n:LABEL) RETURN n
|
||||
auto match_by_label = [&db](const properties_t &args) {
|
||||
auto match_by_label = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
auto prop_key = t.vertex_property_key("name", Flags::String);
|
||||
auto property_key = t.vertex_property_key("name", Flags::String);
|
||||
|
||||
cout << "VERTICES" << endl;
|
||||
label.index().for_range(t).for_all(
|
||||
[&](auto a) { cout << a.at(prop_key) << endl; });
|
||||
[&](auto a) { cout << a.at(property_key) << endl; });
|
||||
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
// MATCH (n) DELETE n
|
||||
auto match_all_delete = [&db](const properties_t &args) {
|
||||
auto match_all_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
t.vertex_access().fill().isolated().for_all(
|
||||
@ -200,7 +202,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n:LABEL) DELETE n
|
||||
auto match_label_delete = [&db](const properties_t &args) {
|
||||
auto match_label_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &label = t.label_find_or_create("LABEL");
|
||||
@ -212,10 +214,10 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n) WHERE ID(n) = id DELETE n
|
||||
auto match_id_delete = [&db](const properties_t &args) {
|
||||
auto match_id_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto ov = t.vertex_find(args[0]->as<Int64>().value);
|
||||
auto ov = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(ov)) return t.commit(), false;
|
||||
auto v = ov.take();
|
||||
if (!v.isolated()) return t.commit(), false;
|
||||
@ -225,10 +227,10 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH ()-[r]-() WHERE ID(r) = id DELETE r
|
||||
auto match_edge_id_delete = [&db](const properties_t &args) {
|
||||
auto match_edge_id_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto ov = t.edge_find(args[0]->as<Int64>().value);
|
||||
auto ov = t.edge_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(ov)) return t.commit(), false;
|
||||
|
||||
auto v = ov.take();
|
||||
@ -238,7 +240,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH ()-[r]-() DELETE r
|
||||
auto match_edge_all_delete = [&db](const properties_t &args) {
|
||||
auto match_edge_all_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
t.edge_access().fill().for_all([&](auto a) { a.remove(); });
|
||||
@ -247,7 +249,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH ()-[r:TYPE]-() DELETE r
|
||||
auto match_edge_type_delete = [&db](const properties_t &args) {
|
||||
auto match_edge_type_delete = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
@ -258,12 +260,12 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n)-[:TYPE]->(m) WHERE ID(n) = id RETURN m
|
||||
auto match_id_type_return = [&db](const properties_t &args) {
|
||||
auto match_id_type_return = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
|
||||
auto ov = t.vertex_find(args[0]->as<Int64>().value);
|
||||
auto ov = t.vertex_find(args[0].as<Int64>().value());
|
||||
if (!option_fill(ov)) return t.commit(), false;
|
||||
auto v = ov.take();
|
||||
|
||||
@ -279,11 +281,11 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n)-[:TYPE]->(m) WHERE n.name = "kruno" RETURN m
|
||||
auto match_name_type_return = [&db](const properties_t &args) {
|
||||
auto match_name_type_return = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
auto prop_name = t.vertex_property_key("name", args[0]->flags);
|
||||
auto prop_name = t.vertex_property_key("name", args[0].key.flags());
|
||||
|
||||
Option<const EdgeAccessor> r;
|
||||
|
||||
@ -291,12 +293,12 @@ auto load_queries(Db &db)
|
||||
.for_range(t)
|
||||
.clone_to(r) // Savepoint
|
||||
.from() // Backtracing
|
||||
.has_property(prop_name, *args[0].get())
|
||||
.has_property(prop_name, args[0])
|
||||
.replace(r); // Load savepoint
|
||||
|
||||
auto it_vertex = t.vertex_access()
|
||||
.fill()
|
||||
.has_property(prop_name, *args[0].get())
|
||||
.has_property(prop_name, args[0])
|
||||
.out()
|
||||
.type(type);
|
||||
|
||||
@ -317,11 +319,11 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n)-[:TYPE]->(m) WHERE n.name = "kruno" RETURN n,m
|
||||
auto match_name_type_return_cross = [&db](const properties_t &args) {
|
||||
auto match_name_type_return_cross = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
auto &type = t.type_find_or_create("TYPE");
|
||||
auto prop_name = t.vertex_property_key("name", args[0]->flags);
|
||||
auto prop_name = t.vertex_property_key("name", args[0].key.flags());
|
||||
|
||||
Option<const VertexAccessor> n;
|
||||
Option<const EdgeAccessor> r;
|
||||
@ -330,13 +332,13 @@ auto load_queries(Db &db)
|
||||
.for_range(t)
|
||||
.clone_to(r) // Savepoint
|
||||
.from() // Backtracing
|
||||
.has_property(prop_name, *args[0].get())
|
||||
.has_property(prop_name, args[0])
|
||||
.clone_to(n) // Savepoint
|
||||
.replace(r); // Load savepoint
|
||||
|
||||
auto it_vertex = t.vertex_access()
|
||||
.fill()
|
||||
.has_property(prop_name, *args[0].get())
|
||||
.has_property(prop_name, args[0])
|
||||
.clone_to(n) // Savepoint
|
||||
.out()
|
||||
.type(type);
|
||||
@ -358,7 +360,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// MATCH (n:LABEL)-[:TYPE]->(m) RETURN n
|
||||
auto match_label_type_return = [&db](const properties_t &args) {
|
||||
auto match_label_type_return = [&db](properties_t &&args) {
|
||||
DbAccessor t(db);
|
||||
|
||||
try {
|
||||
@ -400,7 +402,7 @@ auto load_queries(Db &db)
|
||||
};
|
||||
|
||||
// Blueprint:
|
||||
// auto = [&db](const properties_t &args) {
|
||||
// auto = [&db](properties_t &&args) {
|
||||
// DbAccessor t(db);
|
||||
//
|
||||
//
|
||||
@ -412,7 +414,11 @@ auto load_queries(Db &db)
|
||||
queries[15648836733456301916u] = create_edge_v2;
|
||||
queries[10597108978382323595u] = create_account;
|
||||
queries[5397556489557792025u] = create_labeled_and_named_node;
|
||||
|
||||
// Query hasher reports two hash values
|
||||
queries[998725786176032607u] = create_labeled_and_named_node_v2;
|
||||
queries[16090682663946456821u] = create_labeled_and_named_node_v2;
|
||||
|
||||
queries[7939106225150551899u] = create_edge;
|
||||
queries[6579425155585886196u] = create_edge;
|
||||
queries[11198568396549106428u] = find_node_by_internal_id;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
|
||||
using code_args_t = std::vector<Property::sptr>;
|
||||
using code_args_t = std::vector<Property>;
|
||||
|
||||
struct QueryStripped
|
||||
{
|
||||
|
@ -8,17 +8,18 @@
|
||||
|
||||
#include "cypher/cypher.h"
|
||||
#include "cypher/tokenizer/cypher_lexer.hpp"
|
||||
#include "logging/default.hpp"
|
||||
#include "query_stripped.hpp"
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "utils/hashing/fnv.hpp"
|
||||
#include "utils/string/transform.hpp"
|
||||
#include "utils/variadic/variadic.hpp"
|
||||
#include "logging/default.hpp"
|
||||
|
||||
// TODO: Maybe std::move(v) is faster, but it must be cheked for validity.
|
||||
template <class T, class V>
|
||||
void store_query_param(code_args_t &arguments, V &&v)
|
||||
{
|
||||
arguments.emplace_back(std::make_shared<T>(std::forward<V>(v)));
|
||||
arguments.emplace_back(Property(T(std::move(v)), T::type));
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
@ -43,7 +44,8 @@ public:
|
||||
auto strip_space(const std::string &query)
|
||||
{
|
||||
auto stripped = strip(query, " ");
|
||||
return QueryStripped(std::move(stripped.query), stripped.hash, std::move(stripped.arguments));
|
||||
return QueryStripped(std::move(stripped.query), stripped.hash,
|
||||
std::move(stripped.arguments));
|
||||
}
|
||||
|
||||
auto strip(const std::string &query, const std::string &separator = "")
|
||||
@ -87,6 +89,9 @@ public:
|
||||
store_query_param<Float>(stripped_arguments,
|
||||
std::stof(token.value));
|
||||
break;
|
||||
default:
|
||||
// TODO: other propertys
|
||||
assert(false);
|
||||
}
|
||||
stripped_query += std::to_string(index) + separator;
|
||||
} else {
|
||||
|
@ -21,7 +21,7 @@ const std::string transaction_begin = "DbAccessor t(db);";
|
||||
|
||||
const std::string transaction_commit = "t.commit();";
|
||||
|
||||
const std::string set_property = "{}.set({}, args[{}]);";
|
||||
const std::string set_property = "{}.set({}, std::move(args[{}]));";
|
||||
|
||||
// create vertex e.g. CREATE (n:PERSON {name: "Test", age: 23})
|
||||
const std::string create_vertex = "auto {} = t.vertex_insert();";
|
||||
@ -29,26 +29,26 @@ const std::string create_label = "auto &{0} = t.label_find_or_create(\"{0}\");";
|
||||
const std::string add_label = "{}.add_label({});";
|
||||
|
||||
const std::string vertex_property_key =
|
||||
"auto {}=t.vertex_property_key(\"{}\",args[{}]->flags);";
|
||||
"auto {}=t.vertex_property_key(\"{}\",args[{}].key.flags());";
|
||||
const std::string edge_property_key =
|
||||
"auto {}=t.edge_property_key(\"{}\",args[{}]->flags);";
|
||||
"auto {}=t.edge_property_key(\"{}\",args[{}].key.flags());";
|
||||
|
||||
// create edge e.g CREATE (n1)-[r:COST {cost: 100}]->(n2)
|
||||
const std::string create_edge = "auto {} = t.edge_insert({},{});";
|
||||
const std::string find_type = "auto &{0} = t.type_find_or_create(\"{0}\");";
|
||||
const std::string set_type = "{}.edge_type({});";
|
||||
|
||||
const std::string args_id = "auto id = args[{}]->as<Int32>();";
|
||||
const std::string args_id = "Int32 id = args[{}].as<Int32>();";
|
||||
|
||||
const std::string vertex_accessor_args_id =
|
||||
"auto vertex_accessor = t.vertex_find(id.value);";
|
||||
"auto vertex_accessor = t.vertex_find(id.value());";
|
||||
|
||||
const std::string match_vertex_by_id =
|
||||
"auto option_{0} = t.vertex_find(args[{1}]->as<Int64>().value);\n"
|
||||
"auto option_{0} = t.vertex_find(args[{1}].as<Int64>().value());\n"
|
||||
" if (!option_fill(option_{0})) return t.commit(), false;\n"
|
||||
" auto {0}=option_{0}.take();";
|
||||
const std::string match_edge_by_id =
|
||||
"auto option_{0} = t.edge_find(args[{1}]->as<Int64>().value);\n"
|
||||
"auto option_{0} = t.edge_find(args[{1}].as<Int64>().value());\n"
|
||||
" if (!option_fill(option_{0})) return t.commit(), false;\n"
|
||||
" auto {0}=option_{0}.take();";
|
||||
|
||||
@ -59,51 +59,51 @@ const std::string write_entity = "stream.write_field(\"{0}\");\n"
|
||||
" stream.chunk();"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string write_all_vertices =
|
||||
"stream.write_field(\"{0}\");\n"
|
||||
" iter::for_all(t.vertex_access(), [&](auto vertex) {{\n"
|
||||
" if (vertex.fill()) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(vertex);\n"
|
||||
" stream.chunk();\n"
|
||||
" }}\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
const std::string write_all_vertices =
|
||||
"stream.write_field(\"{0}\");\n"
|
||||
" iter::for_all(t.vertex_access(), [&](auto vertex) {{\n"
|
||||
" if (vertex.fill()) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(vertex);\n"
|
||||
" stream.chunk();\n"
|
||||
" }}\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string find_and_write_vertices_by_label =
|
||||
"auto &label = t.label_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" label.index().for_range(t).for_all([&](auto vertex) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(vertex);\n"
|
||||
" stream.chunk();\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
"auto &label = t.label_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" label.index().for_range(t).for_all([&](auto vertex) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(vertex);\n"
|
||||
" stream.chunk();\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string write_all_edges =
|
||||
"stream.write_field(\"{0}\");\n"
|
||||
" iter::for_all(t.edge_access(), [&](auto edge) {{\n"
|
||||
" if (edge.fill()) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(edge);\n"
|
||||
" stream.chunk();\n"
|
||||
" }}\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
"stream.write_field(\"{0}\");\n"
|
||||
" iter::for_all(t.edge_access(), [&](auto edge) {{\n"
|
||||
" if (edge.fill()) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(edge);\n"
|
||||
" stream.chunk();\n"
|
||||
" }}\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string find_and_write_edges_by_type =
|
||||
"auto &type = t.type_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" type.index().for_range(t).for_all([&](auto edge) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(edge);\n"
|
||||
" stream.chunk();\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
"auto &type = t.type_find_or_create(\"{1}\");\n"
|
||||
" stream.write_field(\"{0}\");\n"
|
||||
" type.index().for_range(t).for_all([&](auto edge) {{\n"
|
||||
" stream.write_record();\n"
|
||||
" stream.write_list_header(1);\n"
|
||||
" stream.write(edge);\n"
|
||||
" stream.chunk();\n"
|
||||
" }});\n"
|
||||
" stream.write_meta(\"rw\");\n";
|
||||
|
||||
const std::string return_true = "return true;";
|
||||
|
||||
|
@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "fmt/format.h"
|
||||
#include "logging/default.hpp"
|
||||
#include "query_engine/exceptions/errors.hpp"
|
||||
#include "storage/model/properties/properties.hpp"
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/traversers/consolewriter.hpp"
|
||||
#include "storage/model/properties/traversers/jsonwriter.hpp"
|
||||
#include "utils/types/byte.hpp"
|
||||
#include "logging/default.hpp"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@ -26,7 +28,8 @@ void print_props(const Properties<T> &properties);
|
||||
template <class T>
|
||||
void cout_properties(const Properties<T> &properties);
|
||||
|
||||
void cout_property(const std::string &key, const Property &property);
|
||||
template <class T>
|
||||
void cout_property(const StoredProperty<T> &property);
|
||||
|
||||
// this is a nice way how to avoid multiple definition problem with
|
||||
// headers because it will create a unique namespace for each compilation unit
|
||||
@ -43,7 +46,11 @@ std::string format(const std::string &format_str, const Args &... args)
|
||||
template <typename... Args>
|
||||
std::string code_line(const std::string &format_str, const Args &... args)
|
||||
{
|
||||
return "\t" + format(format_str, args...) + "\n";
|
||||
try {
|
||||
return "\t" + format(format_str, args...) + "\n";
|
||||
} catch (std::runtime_error &e) {
|
||||
throw CodeGenerationError(std::string(e.what()) + " " + format_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,19 +59,19 @@ class CoutSocket
|
||||
public:
|
||||
CoutSocket() : logger(logging::log->logger("Cout Socket")) {}
|
||||
|
||||
int write(const std::string& str)
|
||||
int write(const std::string &str)
|
||||
{
|
||||
logger.info(str);
|
||||
return str.size();
|
||||
}
|
||||
|
||||
int write(const char* data, size_t len)
|
||||
int write(const char *data, size_t len)
|
||||
{
|
||||
logger.info(std::string(data, len));
|
||||
return len;
|
||||
}
|
||||
|
||||
int write(const byte* data, size_t len)
|
||||
int write(const byte *data, size_t len)
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -6,4 +6,5 @@
|
||||
#include "storage/model/properties/float.hpp"
|
||||
#include "storage/model/properties/int32.hpp"
|
||||
#include "storage/model/properties/int64.hpp"
|
||||
#include "storage/model/properties/null.hpp"
|
||||
#include "storage/model/properties/string.hpp"
|
||||
|
@ -1,69 +1,75 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
template <class T, Flags f_type>
|
||||
class Array : public Property
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
|
||||
template <class T>
|
||||
using ArrayStore = std::vector<T>;
|
||||
|
||||
template <class T, Flags flag_t>
|
||||
class Array
|
||||
{
|
||||
public:
|
||||
static constexpr Flags type = f_type;
|
||||
using Arr = std::vector<T>;
|
||||
const static Type type;
|
||||
|
||||
Array(const Array &) = default;
|
||||
Array(Array &&) = default;
|
||||
using Arr = ArrayStore<T>;
|
||||
|
||||
Array(const Arr &value);
|
||||
Array(Arr &&value);
|
||||
Array(Arr &&value) : data(std::make_shared<Arr>(std::move(value))) {}
|
||||
|
||||
operator const Arr &() const;
|
||||
Arr &value() { return *data.get(); }
|
||||
|
||||
bool operator==(const Property &other) const override;
|
||||
Arr const &value() const { return *data.get(); }
|
||||
|
||||
bool operator==(const Array &other) const;
|
||||
std::ostream &print(std::ostream &stream) const
|
||||
{
|
||||
stream << "[";
|
||||
for (auto e : value()) {
|
||||
stream << e << ",";
|
||||
}
|
||||
stream << "]";
|
||||
return stream;
|
||||
}
|
||||
|
||||
bool operator==(const Arr &other) const;
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Array &prop)
|
||||
{
|
||||
return prop.print(stream);
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Array &prop);
|
||||
bool operator==(const Array &other) const { return *this == other.value(); }
|
||||
|
||||
std::ostream &print(std::ostream &stream) const override;
|
||||
bool operator==(const Arr &other) const
|
||||
{
|
||||
auto arr = value();
|
||||
if (arr.size() != other.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Arr const &value_ref() const { return value; }
|
||||
auto n = arr.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (arr[i] != other[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Arr value;
|
||||
return true;
|
||||
}
|
||||
|
||||
operator const Arr &() const { return value(); };
|
||||
|
||||
private:
|
||||
std::shared_ptr<Arr> data;
|
||||
};
|
||||
|
||||
class ArrayString : public Array<std::string, Flags::ArrayString>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayString = Array<std::string, Flags::ArrayString>;
|
||||
|
||||
class ArrayBool : public Array<bool, Flags::ArrayBool>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayBool = Array<bool, Flags::ArrayBool>;
|
||||
|
||||
class ArrayInt32 : public Array<int32_t, Flags::ArrayInt32>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayInt32 = Array<int32_t, Flags::ArrayInt32>;
|
||||
|
||||
class ArrayInt64 : public Array<int64_t, Flags::ArrayInt64>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayInt64 = Array<int64_t, Flags::ArrayInt64>;
|
||||
|
||||
class ArrayFloat : public Array<float, Flags::ArrayFloat>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayFloat = Array<float, Flags::ArrayFloat>;
|
||||
|
||||
class ArrayDouble : public Array<double, Flags::ArrayDouble>
|
||||
{
|
||||
public:
|
||||
using Array::Array;
|
||||
};
|
||||
using ArrayDouble = Array<double, Flags::ArrayDouble>;
|
||||
|
@ -1,28 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
|
||||
class Bool : public Property
|
||||
class Bool
|
||||
{
|
||||
public:
|
||||
static constexpr Flags type = Flags::Bool;
|
||||
const static Type type;
|
||||
|
||||
Bool(bool value);
|
||||
Bool(const Bool &other) = default;
|
||||
Bool(bool d) : data(d) {}
|
||||
|
||||
bool value() const;
|
||||
bool &value() { return data; }
|
||||
|
||||
bool const &value_ref() const;
|
||||
bool const &value() const { return data; }
|
||||
|
||||
explicit operator bool() const;
|
||||
std::ostream &print(std::ostream &stream) const
|
||||
{
|
||||
return operator<<(stream, *this);
|
||||
}
|
||||
|
||||
bool operator==(const Property &other) const override;
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Bool &prop)
|
||||
{
|
||||
return stream << prop.data;
|
||||
}
|
||||
|
||||
bool operator==(const Bool &other) const;
|
||||
bool operator==(const Bool &other) const
|
||||
{
|
||||
return other.value() == value();
|
||||
}
|
||||
|
||||
bool operator==(bool v) const;
|
||||
bool operator==(bool v) const { return value() == v; }
|
||||
|
||||
std::ostream &print(std::ostream &stream) const override;
|
||||
explicit operator bool() const { return value(); }
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Bool &prop);
|
||||
private:
|
||||
bool data;
|
||||
};
|
||||
|
@ -1,14 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "storage/model/properties/floating.hpp"
|
||||
|
||||
struct Double : public Floating<Double>
|
||||
{
|
||||
static constexpr Flags type = Flags::Double;
|
||||
public:
|
||||
const static Type type;
|
||||
|
||||
Double(double value) : Floating(Flags::Double), value(value) {}
|
||||
Double(double d) : data(d) {}
|
||||
|
||||
double const &value_ref() const { return value; }
|
||||
double &value() { return data; }
|
||||
|
||||
double value;
|
||||
double const &value() const { return data; }
|
||||
|
||||
private:
|
||||
double data;
|
||||
};
|
||||
|
@ -1,9 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utils/total_ordering.hpp"
|
||||
#include "utils/underlying_cast.hpp"
|
||||
|
||||
// TODO: Revise this
|
||||
// NOTE: Why not just count all the types?
|
||||
enum class Flags : unsigned
|
||||
{
|
||||
// Type | Mask
|
||||
@ -54,7 +60,6 @@ enum class Flags : unsigned
|
||||
ArrayDouble = (Double << 13) | Array,
|
||||
|
||||
type_mask = 0xFFF
|
||||
|
||||
};
|
||||
|
||||
// Mask to turn flags into type. It passes all bits except 0x2 and 0x4 which
|
||||
@ -65,7 +70,7 @@ const unsigned flags_equal_mask = 0xFF9;
|
||||
class Type : public TotalOrdering<Type>
|
||||
{
|
||||
public:
|
||||
Type(Flags f) : value(underlying_cast(f) & flags_equal_mask)
|
||||
constexpr Type(Flags f) : value(underlying_cast(f) & flags_equal_mask)
|
||||
{
|
||||
Flags o = Flags(value);
|
||||
assert(o == Flags::Null || o == Flags::Bool || o == Flags::String ||
|
||||
@ -75,7 +80,7 @@ public:
|
||||
|
||||
const std::string to_str()
|
||||
{
|
||||
switch (Flags(value)) {
|
||||
switch (flags()) {
|
||||
case Flags::Null:
|
||||
return "null";
|
||||
case Flags::Bool:
|
||||
@ -98,6 +103,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Flags flags() const { return Flags(value); }
|
||||
|
||||
Type get_type() const { return *this; }
|
||||
|
||||
template <class T>
|
||||
bool is() const
|
||||
{
|
||||
return *this == T::type;
|
||||
}
|
||||
|
||||
bool operator==(Flags other) const { return *this == Type(other); }
|
||||
|
||||
bool operator!=(Flags other) const { return *this != Type(other); }
|
||||
@ -113,5 +128,5 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned value;
|
||||
const unsigned value; // TODO: turn this to flags
|
||||
};
|
||||
|
@ -1,18 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/double.hpp"
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "storage/model/properties/floating.hpp"
|
||||
|
||||
class Float : public Floating<Float>
|
||||
{
|
||||
|
||||
public:
|
||||
static constexpr Flags type = Flags::Float;
|
||||
const static Type type;
|
||||
|
||||
Float(float value) : Floating(Flags::Float), value(value) {}
|
||||
Float(float d) : data(d) {}
|
||||
|
||||
operator Double() const { return Double(value); }
|
||||
operator Double() const { return Double(value()); }
|
||||
|
||||
float const &value_ref() const { return value; }
|
||||
float &value() { return data; }
|
||||
|
||||
float value;
|
||||
float const &value() const { return data; }
|
||||
|
||||
private:
|
||||
float data;
|
||||
};
|
||||
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/all.hpp"
|
||||
#include "storage/model/properties/property.hpp"
|
||||
|
||||
template <class Handler>
|
||||
void accept(const Property &property, Handler &h)
|
||||
{
|
||||
switch (property.flags) {
|
||||
|
||||
case Flags::True:
|
||||
return h.handle(static_cast<const Bool &>(property));
|
||||
|
||||
case Flags::False:
|
||||
return h.handle(static_cast<const Bool &>(property));
|
||||
|
||||
case Flags::String:
|
||||
return h.handle(static_cast<const String &>(property));
|
||||
|
||||
case Flags::Int32:
|
||||
return h.handle(static_cast<const Int32 &>(property));
|
||||
|
||||
case Flags::Int64:
|
||||
return h.handle(static_cast<const Int64 &>(property));
|
||||
|
||||
case Flags::Float:
|
||||
return h.handle(static_cast<const Float &>(property));
|
||||
|
||||
case Flags::Double:
|
||||
return h.handle(static_cast<const Double &>(property));
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
@ -1,18 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "storage/model/properties/int64.hpp"
|
||||
#include "storage/model/properties/integral.hpp"
|
||||
|
||||
class Int32 : public Integral<Int32>
|
||||
{
|
||||
public:
|
||||
static constexpr Flags type = Flags::Int32;
|
||||
const static Type type;
|
||||
|
||||
Int32(int32_t value) : Integral(Flags::Int32), value(value) {}
|
||||
Int32(int32_t d) : data(d) {}
|
||||
|
||||
operator Int64() const { return Int64(value); }
|
||||
operator Int64() const { return Int64(value()); }
|
||||
|
||||
int32_t const &value_ref() const { return value; }
|
||||
int32_t &value() { return data; }
|
||||
|
||||
int32_t value;
|
||||
int32_t const &value() const { return data; }
|
||||
|
||||
private:
|
||||
int32_t data;
|
||||
};
|
||||
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "storage/model/properties/integral.hpp"
|
||||
|
||||
class Int64 : public Integral<Int64>
|
||||
{
|
||||
public:
|
||||
static constexpr Flags type = Flags::Int64;
|
||||
const static Type type;
|
||||
|
||||
Int64(int64_t value) : Integral(Flags::Int64), value(value) {}
|
||||
Int64(int64_t d) : data(d) {}
|
||||
|
||||
int64_t const &value_ref() const { return value; }
|
||||
int64_t &value() { return data; }
|
||||
|
||||
int64_t value;
|
||||
int64_t const &value() const { return data; }
|
||||
private:
|
||||
int64_t data;
|
||||
};
|
||||
|
@ -1,31 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "utils/void.hpp"
|
||||
|
||||
class Null : public Property
|
||||
class Null
|
||||
{
|
||||
public:
|
||||
friend class Property;
|
||||
const static Type type;
|
||||
|
||||
static constexpr Flags type = Flags::Null;
|
||||
Void &value() { return Void::_void; }
|
||||
Void const &value() const { return Void::_void; }
|
||||
|
||||
Null(const Null&) = delete;
|
||||
Null(Null&&) = delete;
|
||||
std::ostream &print(std::ostream &stream) const;
|
||||
|
||||
Null operator=(const Null&) = delete;
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Null &prop);
|
||||
|
||||
bool operator==(const Property& other) const override;
|
||||
|
||||
bool operator==(const Null&) const;
|
||||
bool operator==(const Null &) const;
|
||||
|
||||
explicit operator bool();
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const Null&);
|
||||
|
||||
std::ostream& print(std::ostream& stream) const override;
|
||||
|
||||
private:
|
||||
// the constructor for null is private, it can be constructed only as a
|
||||
// value inside the Property class, Property::Null
|
||||
Null();
|
||||
};
|
||||
|
@ -1,41 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/utils/math_operations.hpp"
|
||||
#include "storage/model/properties/utils/unary_negation.hpp"
|
||||
#include "utils/total_ordering.hpp"
|
||||
|
||||
template <class Derived>
|
||||
class Number : public Property,
|
||||
public TotalOrdering<Derived>,
|
||||
class Number : public TotalOrdering<Derived>,
|
||||
public MathOperations<Derived>,
|
||||
public UnaryNegation<Derived>
|
||||
{
|
||||
|
||||
public:
|
||||
using Property::Property;
|
||||
|
||||
bool operator==(const Property &other) const override
|
||||
std::ostream &print(std::ostream &stream) const
|
||||
{
|
||||
return other.is<Derived>() && this->derived() == other.as<Derived>();
|
||||
}
|
||||
|
||||
friend bool operator==(const Derived &lhs, const Derived &rhs)
|
||||
{
|
||||
return lhs.value == rhs.value;
|
||||
}
|
||||
|
||||
friend bool operator<(const Derived &lhs, const Derived &rhs)
|
||||
{
|
||||
return lhs.value == rhs.value;
|
||||
return operator<<(stream, this->derived());
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &s, const Derived &number)
|
||||
{
|
||||
return s << number.value;
|
||||
return s << number.value();
|
||||
}
|
||||
|
||||
std::ostream &print(std::ostream &stream) const override
|
||||
friend bool operator==(const Derived &lhs, const Derived &rhs)
|
||||
{
|
||||
return operator<<(stream, this->derived());
|
||||
return lhs.value() == rhs.value();
|
||||
}
|
||||
|
||||
friend bool operator<(const Derived &lhs, const Derived &rhs)
|
||||
{
|
||||
return lhs.value() == rhs.value();
|
||||
}
|
||||
};
|
||||
|
@ -1,13 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/property_family.hpp"
|
||||
#include "utils/option.hpp"
|
||||
#include "utils/option_ptr.hpp"
|
||||
|
||||
template <class TG>
|
||||
using prop_key_t = typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey;
|
||||
#include "storage/model/properties/property_family.hpp"
|
||||
#include "storage/model/properties/stored_property.hpp"
|
||||
|
||||
template <class TG, class T>
|
||||
using type_key_t =
|
||||
@ -17,9 +16,7 @@ template <class TG>
|
||||
class Properties
|
||||
{
|
||||
public:
|
||||
using sptr = std::shared_ptr<Properties>;
|
||||
|
||||
using prop_key_t =
|
||||
using property_key =
|
||||
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey;
|
||||
|
||||
template <class T>
|
||||
@ -34,44 +31,26 @@ public:
|
||||
|
||||
size_t size() const { return props.size(); }
|
||||
|
||||
const Property &at(PropertyFamily<TG> &key) const;
|
||||
const StoredProperty<TG> &at(PropertyFamily<TG> &key) const;
|
||||
|
||||
const Property &at(prop_key_t &key) const;
|
||||
const StoredProperty<TG> &at(property_key &key) const;
|
||||
|
||||
template <class T>
|
||||
OptionPtr<T> at(type_key_t<T> &key) const
|
||||
OptionPtr<const T> at(type_key_t<T> &key) const
|
||||
{
|
||||
auto f_key = key.family_key();
|
||||
auto it = props.find(f_key);
|
||||
|
||||
if (it == props.end() || it->first.prop_type() != key.prop_type())
|
||||
return OptionPtr<T>();
|
||||
|
||||
return OptionPtr<T>(&(it->second.get()->template as<T>()));
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
void set(type_key_t<T> &key, Args &&... args)
|
||||
{
|
||||
auto value = std::make_shared<T>(std::forward<Args>(args)...);
|
||||
|
||||
// try to emplace the item
|
||||
// TODO: There is uneccesary copying of value here.
|
||||
auto result = props.emplace(std::make_pair(key, value));
|
||||
|
||||
if (!result.second) {
|
||||
// It is necessary to change key because the types from before and
|
||||
// now
|
||||
// could be different.
|
||||
prop_key_t &key_ref = const_cast<prop_key_t &>(result.first->first);
|
||||
key_ref = key;
|
||||
result.first->second = std::move(value);
|
||||
for (auto &prop : props) {
|
||||
if (prop.key == f_key) {
|
||||
return OptionPtr<const T>(&(prop.template as<T>()));
|
||||
}
|
||||
}
|
||||
|
||||
return OptionPtr<const T>();
|
||||
}
|
||||
|
||||
void set(prop_key_t &key, Property::sptr value);
|
||||
void set(StoredProperty<TG> &&value);
|
||||
|
||||
void clear(prop_key_t &key);
|
||||
void clear(property_key &key);
|
||||
|
||||
void clear(PropertyFamily<TG> &key);
|
||||
|
||||
@ -79,7 +58,7 @@ public:
|
||||
void accept(Handler &handler) const
|
||||
{
|
||||
for (auto &kv : props)
|
||||
handler.handle(kv.first, *kv.second);
|
||||
kv.accept(handler);
|
||||
|
||||
handler.finish();
|
||||
}
|
||||
@ -88,11 +67,10 @@ public:
|
||||
void for_all(Handler handler) const
|
||||
{
|
||||
for (auto &kv : props)
|
||||
handler(kv.first, kv.second);
|
||||
handler(kv);
|
||||
}
|
||||
|
||||
private:
|
||||
using props_t =
|
||||
std::unordered_map<prop_key_t, Property::sptr, PropertyHash<TG>>;
|
||||
using props_t = std::vector<StoredProperty<TG>>;
|
||||
props_t props;
|
||||
};
|
||||
|
@ -7,48 +7,15 @@
|
||||
#include <vector>
|
||||
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "utils/underlying_cast.hpp"
|
||||
#include "storage/model/properties/property_holder.hpp"
|
||||
|
||||
class Null;
|
||||
|
||||
class Property
|
||||
// Property Class designated for creation outside the database.
|
||||
class Property : public PropertyHolder<Type>
|
||||
{
|
||||
public:
|
||||
using sptr = std::shared_ptr<Property>;
|
||||
|
||||
static const Null Null;
|
||||
|
||||
Property(Flags flags);
|
||||
|
||||
virtual bool operator==(const Property &other) const = 0;
|
||||
|
||||
bool operator!=(const Property &other) const;
|
||||
|
||||
template <class T>
|
||||
bool is() const
|
||||
{
|
||||
return underlying_cast(flags) & underlying_cast(T::type);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T &as()
|
||||
{
|
||||
assert(this->is<T>());
|
||||
return *static_cast<T *>(this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T &as() const
|
||||
{
|
||||
assert(this->is<T>());
|
||||
return *static_cast<const T *>(this);
|
||||
}
|
||||
|
||||
virtual std::ostream &print(std::ostream &stream) const = 0;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const Property &prop);
|
||||
|
||||
const Flags flags;
|
||||
using PropertyHolder<Type>::PropertyHolder;
|
||||
};
|
||||
|
||||
using properties_t = std::vector<Property::sptr>;
|
||||
using properties_t = std::vector<Property>;
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
|
||||
public:
|
||||
// Ordered on POINTERS to PropertyFamily
|
||||
// TODO: This probably isn't necessary anymore.
|
||||
class PropertyFamilyKey
|
||||
: public TotalOrdering<PropertyFamilyKey>,
|
||||
public TotalOrdering<PropertyFamilyKey, PropertyFamily>,
|
||||
@ -81,6 +82,8 @@ public:
|
||||
return &(lhs) < &(rhs.type->family);
|
||||
}
|
||||
|
||||
Type get_type() const { return type->type; }
|
||||
|
||||
Type prop_type() const { return type->type; }
|
||||
|
||||
std::string const &family_name() const
|
||||
@ -105,7 +108,7 @@ public:
|
||||
public:
|
||||
PropertyFamilyKey family_key() { return PropertyFamilyKey(type); }
|
||||
|
||||
Type prop_type() const { return type.type; }
|
||||
Type const &prop_type() const { return type.type; }
|
||||
|
||||
friend bool operator==(const PropertyTypeKey &lhs,
|
||||
const PropertyTypeKey &rhs)
|
||||
@ -176,7 +179,7 @@ public:
|
||||
PropertyType &get(Type type);
|
||||
|
||||
// Return pointer for NULL type. Extremly fast.
|
||||
PropertyType &getNull() { return *null_type; }
|
||||
PropertyType &getNull() const { return *null_type; }
|
||||
|
||||
friend bool operator<(const PropertyFamily &lhs, const PropertyFamily &rhs);
|
||||
|
||||
@ -204,17 +207,3 @@ using VertexPropertyType =
|
||||
template <class T>
|
||||
using EdgePropertyType =
|
||||
PropertyFamily<TypeGroupEdge>::PropertyType::PropertyTypeKey<T>;
|
||||
|
||||
template <class TG>
|
||||
class PropertyHash
|
||||
{
|
||||
public:
|
||||
size_t operator()(
|
||||
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey const &key)
|
||||
const
|
||||
{
|
||||
return (std::hash<const void *>()((const void *)(&(key.get_family()))) +
|
||||
7) *
|
||||
UINT64_C(0xbf58476d1ce4e5b9);
|
||||
}
|
||||
};
|
||||
|
256
include/storage/model/properties/property_holder.hpp
Normal file
256
include/storage/model/properties/property_holder.hpp
Normal file
@ -0,0 +1,256 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/all.hpp"
|
||||
|
||||
// Generates constructor by value which accepts type_name object and stores them
|
||||
// in union_name field.
|
||||
#define GENERATE_CONSTRUCTOR_FOR_DATA(type_name, union_name) \
|
||||
PropertyHolder(type_name &&data, T k) \
|
||||
: union_name(std::move(data)), key(k) \
|
||||
{ \
|
||||
assert(type_name::type == key.get_type()); \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to construct type_name object in
|
||||
// place of union_name field by a move from other
|
||||
#define GENERATE_CASE_CLAUSE_FOR_CONSTRUCTOR_MOVE(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
new (&(this->union_name)) type_name(std::move(other.union_name)); \
|
||||
break; \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to construct type_name object in
|
||||
// place of union_name field by a copy from other
|
||||
#define GENERATE_CASE_CLAUSE_FOR_CONSTRUCTOR_COPY(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
new (&(this->union_name)) type_name(other.union_name); \
|
||||
break; \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to destruct type_name object in
|
||||
// place of union_name field
|
||||
#define GENERATE_CASE_CLAUSE_FOR_DESTRUCTOR(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
this->union_name.~type_name(); \
|
||||
break; \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to handle type_name object from
|
||||
// field of union_name
|
||||
#define GENERATE_CASE_CLAUSE_FOR_HANDLER(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
h.handle(this->union_name); \
|
||||
break; \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to print type_name object from
|
||||
// field of union_name
|
||||
#define GENERATE_CASE_CLAUSE_FOR_PRINT(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
return this->union_name.print(stream); \
|
||||
}
|
||||
|
||||
// Genrates case claus for Flags::type_name to comapre type_name object from
|
||||
// field of union_name with same named and field from other holder.
|
||||
#define GENERATE_CASE_CLAUSE_FOR_COMPARISON(type_name, union_name) \
|
||||
case Flags::type_name: { \
|
||||
return this->union_name == other.union_name; \
|
||||
}
|
||||
|
||||
// Generates field in a union with a given type and name
|
||||
#define GENERATE_UNION_FIELD(type_name, union_name) type_name union_name
|
||||
|
||||
// Generates signatures GENERATE_define_generator(type_name, union_name );
|
||||
// for every pair type,property
|
||||
#define GENERATE_FOR_ALL_PROPERTYS(define_generator) \
|
||||
GENERATE_##define_generator(Null, null_v); \
|
||||
GENERATE_##define_generator(Bool, bool_v); \
|
||||
GENERATE_##define_generator(Int32, int32_v); \
|
||||
GENERATE_##define_generator(Int64, int64_v); \
|
||||
GENERATE_##define_generator(Float, float_V); \
|
||||
GENERATE_##define_generator(Double, double_v); \
|
||||
GENERATE_##define_generator(String, string_v); \
|
||||
GENERATE_##define_generator(ArrayBool, array_bool); \
|
||||
GENERATE_##define_generator(ArrayInt32, array_int32); \
|
||||
GENERATE_##define_generator(ArrayInt64, array_int64); \
|
||||
GENERATE_##define_generator(ArrayFloat, array_float); \
|
||||
GENERATE_##define_generator(ArrayDouble, array_double); \
|
||||
GENERATE_##define_generator(ArrayString, array_string);
|
||||
|
||||
// Holds property and has some means of determining its type.
|
||||
// T must have method get_type() const which returns Type.
|
||||
template <class T>
|
||||
class PropertyHolder
|
||||
{
|
||||
// He is his own best friend.
|
||||
template <class O>
|
||||
friend class PropertyHolder;
|
||||
|
||||
public:
|
||||
PropertyHolder() = delete;
|
||||
|
||||
GENERATE_FOR_ALL_PROPERTYS(CONSTRUCTOR_FOR_DATA);
|
||||
|
||||
PropertyHolder(PropertyHolder const &other) : key(other.key)
|
||||
{
|
||||
switch (other.key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_CONSTRUCTOR_COPY);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
PropertyHolder(PropertyHolder &&other) : key(other.key)
|
||||
{
|
||||
switch (other.key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_CONSTRUCTOR_MOVE);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
template <class O>
|
||||
PropertyHolder(PropertyHolder<O> &&other, T const &key) : key(key)
|
||||
{
|
||||
assert(other.key.get_type() == key.get_type());
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_CONSTRUCTOR_MOVE);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
~PropertyHolder()
|
||||
{
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_DESTRUCTOR);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
PropertyHolder &operator=(PropertyHolder const &other)
|
||||
{
|
||||
this->~PropertyHolder();
|
||||
new (this) PropertyHolder(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PropertyHolder &operator=(PropertyHolder &&other)
|
||||
{
|
||||
this->~PropertyHolder();
|
||||
new (this) PropertyHolder(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Handler>
|
||||
void accept(Handler &h) const
|
||||
{
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_HANDLER);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
std::ostream &print(std::ostream &stream) const
|
||||
{
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_PRINT);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream,
|
||||
const PropertyHolder &prop)
|
||||
{
|
||||
return prop.print(stream);
|
||||
}
|
||||
|
||||
bool operator==(const PropertyHolder &other) const
|
||||
{
|
||||
if (key == other.key) {
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_COMPARISON);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class O>
|
||||
bool operator==(const PropertyHolder<O> &other) const
|
||||
{
|
||||
if (key.get_type() == other.key.get_type()) {
|
||||
switch (key.get_type().flags()) {
|
||||
GENERATE_FOR_ALL_PROPERTYS(CASE_CLAUSE_FOR_COMPARISON);
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class O, Flags f = O::type.flags()>
|
||||
bool operator==(const O &other) const
|
||||
{
|
||||
if (key.get_type() == O::type) {
|
||||
return other == as<O>();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator!=(const PropertyHolder &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
// True if contains T property
|
||||
template <class D>
|
||||
bool is() const
|
||||
{
|
||||
return D::type == key.get_type();
|
||||
}
|
||||
|
||||
// T MUST be type with which this holder was constructed.
|
||||
template <class D>
|
||||
D &as()
|
||||
{
|
||||
assert(is<D>());
|
||||
return *reinterpret_cast<D *>(&array_string);
|
||||
}
|
||||
|
||||
// T MUST be type with which this PropertyData was constructed.
|
||||
// Specialized after this class
|
||||
template <class D>
|
||||
D const &as() const
|
||||
{
|
||||
assert(is<D>());
|
||||
return *reinterpret_cast<D const *>(&array_string);
|
||||
}
|
||||
|
||||
// Knows type
|
||||
const T key;
|
||||
|
||||
private:
|
||||
// Stored data.
|
||||
union
|
||||
{
|
||||
GENERATE_FOR_ALL_PROPERTYS(UNION_FIELD);
|
||||
};
|
||||
};
|
||||
|
||||
#undef GENERATE_CONSTRUCTOR_FOR_DATA
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_CONSTRUCTOR_MOVE
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_CONSTRUCTOR_COPY
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_DESTRUCTOR
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_HANDLER
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_PRINT
|
||||
#undef GENERATE_CASE_CLAUSE_FOR_COMPARISON
|
||||
#undef GENERATE_UNION_FIELD
|
||||
#undef GENERATE_FOR_ALL_PROPERTYS
|
24
include/storage/model/properties/stored_property.hpp
Normal file
24
include/storage/model/properties/stored_property.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
#include "storage/model/properties/property_family.hpp"
|
||||
#include "storage/model/properties/property_holder.hpp"
|
||||
|
||||
template <class TG>
|
||||
using property_key =
|
||||
typename PropertyFamily<TG>::PropertyType::PropertyFamilyKey;
|
||||
|
||||
// Property Class designated for creation outside the database.
|
||||
template <class TG>
|
||||
class StoredProperty : public PropertyHolder<property_key<TG>>
|
||||
{
|
||||
// null property family
|
||||
const static class PropertyFamily<TG> null_family;
|
||||
|
||||
public:
|
||||
// Needed for properties to return reference on stored property when they
|
||||
// don't cointain searched property.
|
||||
const static class StoredProperty<TG> null;
|
||||
|
||||
using PropertyHolder<property_key<TG>>::PropertyHolder;
|
||||
};
|
@ -1,31 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
class String : public Property
|
||||
#include "storage/model/properties/flags.hpp"
|
||||
|
||||
class String
|
||||
{
|
||||
public:
|
||||
static constexpr Flags type = Flags::String;
|
||||
const static Type type;
|
||||
|
||||
String(const String &) = default;
|
||||
String(String &&) = default;
|
||||
String(std::string const &d) : data(d) {}
|
||||
String(std::string &&d) : data(std::move(d)) {}
|
||||
|
||||
String(const std::string &value);
|
||||
String(std::string &&value);
|
||||
std::string &value() { return data; }
|
||||
|
||||
operator const std::string &() const;
|
||||
std::string const &value() const { return data; }
|
||||
|
||||
bool operator==(const Property &other) const override;
|
||||
std::ostream &print(std::ostream &stream) const;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const String &prop);
|
||||
|
||||
bool operator==(const String &other) const;
|
||||
|
||||
bool operator==(const std::string &other) const;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const String &prop);
|
||||
operator const std::string &() const;
|
||||
|
||||
std::ostream &print(std::ostream &stream) const override;
|
||||
|
||||
std::string const &value_ref() const { return value; }
|
||||
|
||||
std::string value;
|
||||
private:
|
||||
std::string data;
|
||||
};
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "storage/model/properties/handler.hpp"
|
||||
#include "storage/model/properties/properties.hpp"
|
||||
#include "storage/type_group_edge.hpp"
|
||||
#include "storage/type_group_vertex.hpp"
|
||||
@ -15,45 +14,59 @@ class ConsoleWriter
|
||||
public:
|
||||
ConsoleWriter() {}
|
||||
|
||||
void handle(const typename PropertyFamily<
|
||||
TypeGroupEdge>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
void handle(const StoredProperty<TypeGroupEdge> &value)
|
||||
{
|
||||
handle<TypeGroupEdge>(key, value);
|
||||
handle<TypeGroupEdge>(value);
|
||||
}
|
||||
|
||||
void handle(const typename PropertyFamily<
|
||||
TypeGroupVertex>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
void handle(const StoredProperty<TypeGroupVertex> &value)
|
||||
{
|
||||
handle<TypeGroupVertex>(key, value);
|
||||
handle<TypeGroupVertex>(value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void handle(
|
||||
const typename PropertyFamily<T>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
void handle(StoredProperty<T> const &value)
|
||||
{
|
||||
cout << "KEY: " << key.family_name() << "; VALUE: ";
|
||||
cout << "KEY: " << value.key.family_name() << "; VALUE: ";
|
||||
|
||||
accept(value, *this);
|
||||
value.accept(*this);
|
||||
|
||||
// value.accept(*this);
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void handle(const Bool &b) { cout << b.value(); }
|
||||
void handle(const Null &v) { cout << "NULL"; }
|
||||
|
||||
void handle(const String &s) { cout << s.value; }
|
||||
void handle(const Bool &b) { cout << b; }
|
||||
|
||||
void handle(const Int32 &int32) { cout << int32.value; }
|
||||
void handle(const String &s) { cout << s; }
|
||||
|
||||
void handle(const Int64 &int64) { cout << int64.value; }
|
||||
void handle(const Int32 &int32) { cout << int32; }
|
||||
|
||||
void handle(const Float &f) { cout << f.value; }
|
||||
void handle(const Int64 &int64) { cout << int64; }
|
||||
|
||||
void handle(const Double &d) { cout << d.value; }
|
||||
void handle(const Float &f) { cout << f; }
|
||||
|
||||
void handle(const Double &d) { cout << d; }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayBool &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayInt32 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayInt64 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayFloat &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayDouble &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayString &) { assert(false); }
|
||||
|
||||
void finish() {}
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "storage/model/properties/handler.hpp"
|
||||
#include "storage/model/properties/properties.hpp"
|
||||
#include "storage/type_group_edge.hpp"
|
||||
#include "storage/type_group_vertex.hpp"
|
||||
@ -11,45 +10,59 @@ struct JsonWriter
|
||||
public:
|
||||
JsonWriter(Buffer &buffer) : buffer(buffer) { buffer << '{'; };
|
||||
|
||||
void handle(const typename PropertyFamily<
|
||||
TypeGroupEdge>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
void handle(const StoredProperty<TypeGroupEdge> &prop)
|
||||
{
|
||||
handle<TypeGroupEdge>(key, value);
|
||||
handle<TypeGroupEdge>(prop);
|
||||
}
|
||||
|
||||
void handle(const typename PropertyFamily<
|
||||
TypeGroupVertex>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
void handle(const StoredProperty<TypeGroupVertex> &prop)
|
||||
{
|
||||
handle<TypeGroupVertex>(key, value);
|
||||
handle<TypeGroupVertex>(prop);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void handle(
|
||||
const typename PropertyFamily<T>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &value)
|
||||
template <class TG>
|
||||
void handle(const StoredProperty<TG> &prop)
|
||||
{
|
||||
if (!first) buffer << ',';
|
||||
|
||||
if (first) first = false;
|
||||
|
||||
buffer << '"' << key.family_name() << "\":";
|
||||
// value.accept(*this);
|
||||
accept(value, *this);
|
||||
buffer << '"' << prop.get_property_key().family_name() << "\":";
|
||||
|
||||
prop.accept(*this);
|
||||
}
|
||||
|
||||
void handle(const Bool &b) { buffer << (b.value() ? "true" : "false"); }
|
||||
void handle(const Null &v) { buffer << "NULL"; }
|
||||
|
||||
void handle(const String &s) { buffer << '"' << s.value << '"'; }
|
||||
void handle(const Bool &b) { buffer << (b ? "true" : "false"); }
|
||||
|
||||
void handle(const Int32 &int32) { buffer << std::to_string(int32.value); }
|
||||
void handle(const String &s) { buffer << '"' << s << '"'; }
|
||||
|
||||
void handle(const Int64 &int64) { buffer << std::to_string(int64.value); }
|
||||
void handle(const Int32 &int32) { buffer << std::to_string(int32.value()); }
|
||||
|
||||
void handle(const Float &f) { buffer << std::to_string(f.value); }
|
||||
void handle(const Int64 &int64) { buffer << std::to_string(int64.value()); }
|
||||
|
||||
void handle(const Double &d) { buffer << std::to_string(d.value); }
|
||||
void handle(const Float &f) { buffer << std::to_string(f.value()); }
|
||||
|
||||
void handle(const Double &d) { buffer << std::to_string(d.value()); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayBool &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayInt32 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayInt64 &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayFloat &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayDouble &) { assert(false); }
|
||||
|
||||
// Not yet implemented
|
||||
void handle(const ArrayString &) { assert(false); }
|
||||
|
||||
void finish() { buffer << '}'; }
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "storage/model/properties/properties.hpp"
|
||||
#include "storage/model/properties/property.hpp"
|
||||
#include "storage/model/properties/property_family.hpp"
|
||||
#include "storage/model/properties/stored_property.hpp"
|
||||
#include "transactions/transaction.hpp"
|
||||
|
||||
template <class TG, class Derived>
|
||||
@ -73,34 +74,30 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const Property &at(PropertyFamily<TG> &key) const
|
||||
const StoredProperty<TG> &at(PropertyFamily<TG> &key) const
|
||||
{
|
||||
return properties().at(key);
|
||||
}
|
||||
|
||||
const Property &at(prop_key_t<TG> &key) const
|
||||
const StoredProperty<TG> &at(property_key<TG> &key) const
|
||||
{
|
||||
return properties().at(key);
|
||||
}
|
||||
|
||||
template <class V>
|
||||
OptionPtr<V> at(type_key_t<TG, V> &key) const
|
||||
OptionPtr<const V> at(type_key_t<TG, V> &key) const
|
||||
{
|
||||
return properties().template at<V>(key);
|
||||
}
|
||||
|
||||
template <class V, class... Args>
|
||||
void set(type_key_t<TG, V> &key, Args &&... args)
|
||||
void set(property_key<TG> &key, Property value)
|
||||
{
|
||||
properties().template set<V>(key, std::forward<Args>(args)...);
|
||||
properties().set(StoredProperty<TG>(std::move(value), key));
|
||||
}
|
||||
|
||||
void set(prop_key_t<TG> &key, Property::sptr value)
|
||||
{
|
||||
properties().set(key, std::move(value));
|
||||
}
|
||||
void set(StoredProperty<TG> value) { properties().set(std::move(value)); }
|
||||
|
||||
void clear(prop_key_t<TG> &key) { properties().clear(key); }
|
||||
void clear(property_key<TG> &key) { properties().clear(key); }
|
||||
|
||||
void clear(PropertyFamily<TG> &key) { properties().clear(key); }
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <fmt/format.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "utils/auto_scope.hpp"
|
||||
#include "utils/stacktrace.hpp"
|
||||
@ -9,9 +9,8 @@
|
||||
class BasicException : public std::exception
|
||||
{
|
||||
public:
|
||||
BasicException(const std::string& message) noexcept
|
||||
: message(message),
|
||||
stacktrace_size(3)
|
||||
BasicException(const std::string &message) noexcept : message(message),
|
||||
stacktrace_size(10)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
this->message += '\n';
|
||||
@ -22,27 +21,24 @@ public:
|
||||
// (limit the size of stacktrace)
|
||||
uint64_t count = 0;
|
||||
|
||||
for(auto& line : stacktrace) {
|
||||
this->message += fmt::format(" at {} ({})\n",
|
||||
line.function, line.location);
|
||||
for (auto &line : stacktrace) {
|
||||
this->message +=
|
||||
fmt::format(" at {} ({})\n", line.function, line.location);
|
||||
|
||||
if (++count >= stacktrace_size)
|
||||
break;
|
||||
if (++count >= stacktrace_size) break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
BasicException(const std::string& format, Args&&... args) noexcept
|
||||
: BasicException(fmt::format(format, std::forward<Args>(args)...)) {}
|
||||
|
||||
const char* what() const noexcept override
|
||||
BasicException(const std::string &format, Args &&... args) noexcept
|
||||
: BasicException(fmt::format(format, std::forward<Args>(args)...))
|
||||
{
|
||||
return message.c_str();
|
||||
}
|
||||
|
||||
const char *what() const noexcept override { return message.c_str(); }
|
||||
|
||||
private:
|
||||
std::string message;
|
||||
uint64_t stacktrace_size;
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
class Void : public TotalOrdering<Void>
|
||||
{
|
||||
public:
|
||||
static Void _void;
|
||||
|
||||
friend bool operator<(const Void &lhs, const Void &rhs) { return false; }
|
||||
|
||||
friend bool operator==(const Void &lhs, const Void &rhs) { return true; }
|
||||
|
@ -21,11 +21,11 @@
|
||||
#include "storage/model/properties/properties.cpp"
|
||||
#include "storage/record_accessor.cpp"
|
||||
// #include "storage/vertex_accessor.cpp"
|
||||
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
|
||||
#include "storage/vertex_accessor.hpp"
|
||||
#include "storage/vertices.cpp"
|
||||
#include "storage/vertices.hpp"
|
||||
#include "utils/command_line/arguments.hpp"
|
||||
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
|
||||
|
||||
const int max_score = 1000000;
|
||||
|
||||
@ -60,7 +60,7 @@ public:
|
||||
auto now = this;
|
||||
double sum = 0;
|
||||
do {
|
||||
sum += (now->vacc.at(tkey).get())->value;
|
||||
sum += (now->vacc.at(tkey).get())->value();
|
||||
now = now->parent;
|
||||
} while (now != nullptr);
|
||||
return sum;
|
||||
@ -91,7 +91,7 @@ double calc_heuristic_cost_dummy(type_key_t<TypeGroupVertex, Double> tkey,
|
||||
EdgeAccessor &edge, VertexAccessor &vertex)
|
||||
{
|
||||
assert(!vertex.empty());
|
||||
return 1 - vertex.at(tkey).get()->value;
|
||||
return 1 - vertex.at(tkey).get()->value();
|
||||
}
|
||||
|
||||
typedef bool (*EdgeFilter)(DbAccessor &t, EdgeAccessor &, Node *before);
|
||||
@ -289,9 +289,9 @@ void add_scores(Db &db)
|
||||
if (v.fill()) {
|
||||
// from Kruno's head :) (could be ALMOST anything else)
|
||||
std::srand(i ^ 0x7482616);
|
||||
v.set(key_score,
|
||||
std::make_shared<Double>((std::rand() % max_score) /
|
||||
(max_score + 0.0)));
|
||||
v.set(StoredProperty<TypeGroupVertex>(
|
||||
Double((std::rand() % max_score) / (max_score + 0.0)),
|
||||
key_score));
|
||||
i++;
|
||||
}
|
||||
});
|
||||
|
@ -136,7 +136,7 @@ void fill_with_bt(unordered_map<string, double> &values, VertexAccessor &com,
|
||||
{
|
||||
auto bus_t = com.at(prop_vertex_business_types);
|
||||
if (bus_t.is_present()) {
|
||||
for (auto &bt : bus_t.get()->value) {
|
||||
for (auto &bt : bus_t.get()->value()) {
|
||||
values[bt] += weight;
|
||||
}
|
||||
}
|
||||
@ -240,7 +240,7 @@ auto query(DbAccessor &t, const Id &start_id)
|
||||
return;
|
||||
}
|
||||
|
||||
auto str = feedback.get()->value.c_str();
|
||||
auto str = feedback.get()->value().c_str();
|
||||
double weight = 0;
|
||||
if (strcasecmp(str, "like") == 0) {
|
||||
weight = 1;
|
||||
@ -266,7 +266,7 @@ auto query(DbAccessor &t, const Id &start_id)
|
||||
if (!os.is_present()) {
|
||||
return;
|
||||
}
|
||||
auto str = os.get()->value.c_str();
|
||||
auto str = os.get()->value().c_str();
|
||||
|
||||
if (strcasecmp(str, "pending") == 0) {
|
||||
weight = 0.5;
|
||||
@ -283,7 +283,7 @@ auto query(DbAccessor &t, const Id &start_id)
|
||||
ee_type == type_searched_and_clicked) {
|
||||
auto count = employ_edge.at(prop_edge_count);
|
||||
if (count.is_present()) {
|
||||
weight = 0.01 * (count.get()->value);
|
||||
weight = 0.01 * (count.get()->value());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "barrier/barrier.hpp"
|
||||
#include "barrier/trans.hpp"
|
||||
|
||||
// ************************* Implementations
|
||||
@ -290,33 +289,29 @@ VertexAccessor VertexAccessor::update() const { return CALL(update()); }
|
||||
|
||||
void VertexAccessor::remove() const { HALF_CALL(remove()); }
|
||||
|
||||
const Property &VertexAccessor::at(VertexPropertyFamily &key) const
|
||||
const StoredProperty<TypeGroupVertex> &
|
||||
VertexAccessor::at(VertexPropertyFamily &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans(key)));
|
||||
}
|
||||
|
||||
const Property &VertexAccessor::at(VertexPropertyKey &key) const
|
||||
const StoredProperty<TypeGroupVertex> &
|
||||
VertexAccessor::at(VertexPropertyKey &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans(key)));
|
||||
}
|
||||
|
||||
template <class V>
|
||||
OptionPtr<V> VertexAccessor::at(VertexPropertyType<V> &key) const
|
||||
OptionPtr<const V> VertexAccessor::at(VertexPropertyType<V> &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans<V>(key)));
|
||||
}
|
||||
#define VertexAccessor_at(x) \
|
||||
template OptionPtr<x> VertexAccessor::at(VertexPropertyType<x> &key) const;
|
||||
template OptionPtr<const x> VertexAccessor::at(VertexPropertyType<x> &key) \
|
||||
const;
|
||||
INSTANTIATE_FOR_PROPERTY(VertexAccessor_at);
|
||||
|
||||
// NOTE: I am not quite sure if this method will have any use
|
||||
template <class V, class... Args>
|
||||
void VertexAccessor::set(VertexPropertyType<V> &key, Args &&... args)
|
||||
{
|
||||
HALF_CALL(set(trans(key), args...));
|
||||
}
|
||||
|
||||
void VertexAccessor::set(VertexPropertyKey &key, Property::sptr value)
|
||||
void VertexAccessor::set(VertexPropertyKey &key, Property &&value)
|
||||
{
|
||||
HALF_CALL(set(trans(key), std::move(value)));
|
||||
}
|
||||
@ -380,33 +375,29 @@ EdgeAccessor EdgeAccessor::update() const { return CALL(update()); }
|
||||
|
||||
void EdgeAccessor::remove() const { HALF_CALL(remove()); }
|
||||
|
||||
const Property &EdgeAccessor::at(EdgePropertyFamily &key) const
|
||||
const StoredProperty<TypeGroupEdge> &
|
||||
EdgeAccessor::at(EdgePropertyFamily &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans(key)));
|
||||
}
|
||||
|
||||
const Property &EdgeAccessor::at(EdgePropertyKey &key) const
|
||||
const StoredProperty<TypeGroupEdge> &
|
||||
EdgeAccessor::at(EdgePropertyKey &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans(key)));
|
||||
}
|
||||
|
||||
template <class V>
|
||||
OptionPtr<V> EdgeAccessor::at(EdgePropertyType<V> &key) const
|
||||
OptionPtr<const V> EdgeAccessor::at(EdgePropertyType<V> &key) const
|
||||
{
|
||||
return HALF_CALL(at(trans<V>(key)));
|
||||
}
|
||||
#define EdgeAccessor_at(x) \
|
||||
template OptionPtr<x> EdgeAccessor::at(EdgePropertyType<x> &key) const;
|
||||
template OptionPtr<const x> EdgeAccessor::at(EdgePropertyType<x> &key) \
|
||||
const;
|
||||
INSTANTIATE_FOR_PROPERTY(EdgeAccessor_at);
|
||||
|
||||
// NOTE: I am not quite sure if this method will have any use
|
||||
template <class V, class... Args>
|
||||
void EdgeAccessor::set(EdgePropertyType<V> &key, Args &&... args)
|
||||
{
|
||||
HALF_CALL(set(trans(key), args...));
|
||||
}
|
||||
|
||||
void EdgeAccessor::set(EdgePropertyKey &key, Property::sptr value)
|
||||
void EdgeAccessor::set(EdgePropertyKey &key, Property &&value)
|
||||
{
|
||||
HALF_CALL(set(trans(key), std::move(value)));
|
||||
}
|
||||
@ -548,7 +539,13 @@ void RecordStream<Stream>::write(const EdgeAccessor &edge)
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const Property &prop)
|
||||
void RecordStream<Stream>::write(const StoredProperty<TypeGroupEdge> &prop)
|
||||
{
|
||||
HALF_CALL(write(prop));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const StoredProperty<TypeGroupVertex> &prop)
|
||||
{
|
||||
HALF_CALL(write(prop));
|
||||
}
|
||||
@ -559,6 +556,12 @@ void RecordStream<Stream>::write(const Property &prop)
|
||||
// HALF_CALL(write_null());
|
||||
// }
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const Null &v)
|
||||
{
|
||||
HALF_CALL(write(v));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const Bool &prop)
|
||||
{
|
||||
@ -590,15 +593,45 @@ void RecordStream<Stream>::write(const Int64 &prop)
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const std::string &value)
|
||||
void RecordStream<Stream>::write(const String &value)
|
||||
{
|
||||
HALF_CALL(write(value));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const String &prop)
|
||||
void RecordStream<Stream>::write(const ArrayBool &arr)
|
||||
{
|
||||
HALF_CALL(write(prop));
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const ArrayInt32 &arr)
|
||||
{
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const ArrayInt64 &arr)
|
||||
{
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const ArrayFloat &arr)
|
||||
{
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const ArrayDouble &arr)
|
||||
{
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
void RecordStream<Stream>::write(const ArrayString &arr)
|
||||
{
|
||||
HALF_CALL(write(arr));
|
||||
}
|
||||
|
||||
template <class Stream>
|
||||
|
@ -27,8 +27,8 @@ void bolt::BoltSerializer<Stream>::write(const EdgeAccessor &edge)
|
||||
encoder.write_map_header(props.size());
|
||||
|
||||
for (auto &prop : props) {
|
||||
write(prop.first.family_name());
|
||||
write(*prop.second);
|
||||
write(prop.key.family_name());
|
||||
prop.accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace bolt
|
||||
{
|
||||
|
||||
Session::Session(io::Socket&& socket, Bolt& bolt)
|
||||
Session::Session(io::Socket &&socket, Bolt &bolt)
|
||||
: Stream(std::forward<io::Socket>(socket)), bolt(bolt)
|
||||
{
|
||||
logger = logging::log->logger("Session");
|
||||
@ -12,30 +12,22 @@ Session::Session(io::Socket&& socket, Bolt& bolt)
|
||||
state = bolt.states.handshake.get();
|
||||
}
|
||||
|
||||
bool Session::alive() const
|
||||
{
|
||||
return state != nullptr;
|
||||
}
|
||||
bool Session::alive() const { return state != nullptr; }
|
||||
|
||||
void Session::execute(const byte* data, size_t len)
|
||||
void Session::execute(const byte *data, size_t len)
|
||||
{
|
||||
// mark the end of the message
|
||||
auto end = data + len;
|
||||
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
auto size = end - data;
|
||||
|
||||
if(LIKELY(connected))
|
||||
{
|
||||
if (LIKELY(connected)) {
|
||||
logger.debug("Decoding chunk of size {}", size);
|
||||
auto finished = decoder.decode(data, size);
|
||||
|
||||
if(!finished)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!finished) return;
|
||||
} else {
|
||||
logger.debug("Decoding handshake of size {}", size);
|
||||
decoder.handshake(data, size);
|
||||
}
|
||||
@ -51,9 +43,5 @@ void Session::close()
|
||||
bolt.close(this);
|
||||
}
|
||||
|
||||
Db& Session::active_db()
|
||||
{
|
||||
return bolt.dbms.active();
|
||||
}
|
||||
|
||||
Db &Session::active_db() { return bolt.dbms.active(); }
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ bool update_property_indexes(IU &iu, const tx::Transaction &t)
|
||||
for (auto kp : iu.record->data.props) {
|
||||
|
||||
// FamilyProperty index
|
||||
auto opi = kp.first.get_family().index.get_write(t);
|
||||
auto opi = kp.key.get_family().index.get_write(t);
|
||||
if (opi.is_present()) {
|
||||
TRY(opi.get()->insert(IndexRecord<TG, std::nullptr_t>(
|
||||
std::nullptr_t(), iu.record, iu.vlist)));
|
||||
|
@ -21,12 +21,10 @@ void cout_properties(const Properties<T> &properties)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void cout_property(
|
||||
const typename PropertyFamily<T>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &property)
|
||||
void cout_property(const StoredProperty<T> &property)
|
||||
{
|
||||
ConsoleWriter writer;
|
||||
writer.handle<T>(key, property);
|
||||
property.accept(writer);
|
||||
cout << "----" << endl;
|
||||
}
|
||||
|
||||
@ -42,12 +40,8 @@ cout_properties<TypeGroupEdge>(const Properties<TypeGroupEdge> &properties);
|
||||
template void
|
||||
cout_properties<TypeGroupVertex>(const Properties<TypeGroupVertex> &properties);
|
||||
|
||||
template void cout_property<TypeGroupEdge>(
|
||||
const typename PropertyFamily<
|
||||
TypeGroupEdge>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &property);
|
||||
template void
|
||||
cout_property<TypeGroupEdge>(const StoredProperty<TypeGroupEdge> &property);
|
||||
|
||||
template void cout_property<TypeGroupVertex>(
|
||||
const typename PropertyFamily<
|
||||
TypeGroupVertex>::PropertyType::PropertyFamilyKey &key,
|
||||
const Property &property);
|
||||
template void
|
||||
cout_property<TypeGroupVertex>(const StoredProperty<TypeGroupVertex> &property);
|
||||
|
@ -1,70 +1,16 @@
|
||||
#include "storage/model/properties/array.hpp"
|
||||
|
||||
template <class T, Flags f_type>
|
||||
Array<T, f_type>::Array(const Arr &value) : Property(f_type), value(value)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
Array<T, f_type>::Array(Arr &&value) : Property(f_type), value(value)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
Array<T, f_type>::operator const Arr &() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
bool Array<T, f_type>::operator==(const Property &other) const
|
||||
{
|
||||
return other.is<Array>() && operator==(other.as<Array>());
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
bool Array<T, f_type>::operator==(const Array &other) const
|
||||
{
|
||||
return this->operator==(other.value);
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
bool Array<T, f_type>::operator==(const Arr &other) const
|
||||
{
|
||||
if (value.size() != other.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto n = value.size();
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (value[i] != other[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
std::ostream &operator<<(std::ostream &stream, const Array<T, f_type> &prop)
|
||||
{
|
||||
return prop.print(stream);
|
||||
}
|
||||
|
||||
template <class T, Flags f_type>
|
||||
std::ostream &Array<T, f_type>::print(std::ostream &stream) const
|
||||
{
|
||||
stream << "[";
|
||||
for (auto e : value) {
|
||||
stream << e << ",";
|
||||
}
|
||||
stream << "]";
|
||||
return stream;
|
||||
}
|
||||
template <class T, Flags flag_t>
|
||||
const Type Array<T, flag_t>::type = Type(flag_t);
|
||||
|
||||
template class Array<std::string, Flags::ArrayString>;
|
||||
|
||||
template class Array<bool, Flags::ArrayBool>;
|
||||
|
||||
template class Array<int32_t, Flags::ArrayInt32>;
|
||||
|
||||
template class Array<int64_t, Flags::ArrayInt64>;
|
||||
|
||||
template class Array<float, Flags::ArrayFloat>;
|
||||
|
||||
template class Array<double, Flags::ArrayDouble>;
|
||||
|
@ -1,42 +1,3 @@
|
||||
#include "storage/model/properties/bool.hpp"
|
||||
|
||||
const bool TRUE = true;
|
||||
const bool FALSE = false;
|
||||
|
||||
Bool::Bool(bool value) : Property(value ? Flags::True : Flags::False) {}
|
||||
|
||||
bool Bool::value() const
|
||||
{
|
||||
// true when the subtraction of True from flags is equal to zero
|
||||
|
||||
// True 0000 0000 0000 0000 0000 0000 0000 0011
|
||||
// False 0000 0000 0000 0000 0000 0000 0000 0101
|
||||
//
|
||||
// True - True = 0
|
||||
// False - True != 0
|
||||
|
||||
return (underlying_cast(flags) - underlying_cast(Flags::True)) == 0;
|
||||
}
|
||||
|
||||
bool const &Bool::value_ref() const { return value() ? TRUE : FALSE; }
|
||||
|
||||
Bool::operator bool() const { return value(); }
|
||||
|
||||
bool Bool::operator==(const Property &other) const
|
||||
{
|
||||
return other.is<Bool>() && operator==(other.as<Bool>());
|
||||
}
|
||||
|
||||
bool Bool::operator==(const Bool &other) const { return other.flags == flags; }
|
||||
|
||||
bool Bool::operator==(bool v) const { return value() == v; }
|
||||
|
||||
std::ostream &Bool::print(std::ostream &stream) const
|
||||
{
|
||||
return operator<<(stream, *this);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const Bool &prop)
|
||||
{
|
||||
return stream << prop.value();
|
||||
}
|
||||
const Type Bool::type = Type(Flags::Bool);
|
||||
|
3
src/storage/model/properties/double.cpp
Normal file
3
src/storage/model/properties/double.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "storage/model/properties/double.hpp"
|
||||
|
||||
const Type Double::type = Type(Flags::Double);
|
3
src/storage/model/properties/float.cpp
Normal file
3
src/storage/model/properties/float.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "storage/model/properties/float.hpp"
|
||||
|
||||
const Type Float::type = Type(Flags::Float);
|
3
src/storage/model/properties/int32.cpp
Normal file
3
src/storage/model/properties/int32.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "storage/model/properties/int32.hpp"
|
||||
|
||||
const Type Int32::type = Type(Flags::Int32);
|
3
src/storage/model/properties/int64.cpp
Normal file
3
src/storage/model/properties/int64.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "storage/model/properties/int64.hpp"
|
||||
|
||||
const Type Int64::type = Type(Flags::Int64);
|
@ -1,30 +1,17 @@
|
||||
#include "storage/model/properties/null.hpp"
|
||||
|
||||
bool Null::operator==(const Property& other) const
|
||||
{
|
||||
return other.is<Null>();
|
||||
}
|
||||
const Type Null::type = Type(Flags::Null);
|
||||
|
||||
bool Null::operator==(const Null&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Null::operator==(const Null &) const { return true; }
|
||||
|
||||
Null::operator bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Null::operator bool() { return false; }
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Null&)
|
||||
std::ostream &operator<<(std::ostream &stream, const Null &)
|
||||
{
|
||||
return stream << "NULL";
|
||||
}
|
||||
|
||||
std::ostream& Null::print(std::ostream& stream) const
|
||||
std::ostream &Null::print(std::ostream &stream) const
|
||||
{
|
||||
return operator<<(stream, *this);
|
||||
}
|
||||
|
||||
Null::Null() : Property(Flags::Null) {}
|
||||
|
||||
const Null Property::Null;
|
||||
|
@ -8,49 +8,53 @@
|
||||
#include "storage/type_group_vertex.hpp"
|
||||
|
||||
template <class TG>
|
||||
const Property &Properties<TG>::at(PropertyFamily<TG> &fam) const
|
||||
const StoredProperty<TG> &Properties<TG>::at(PropertyFamily<TG> &fam) const
|
||||
{
|
||||
// It doesn't matter whit which type
|
||||
// find is called, thats why getNull
|
||||
// compare is done, thats why getNull
|
||||
// method is here to give fast access
|
||||
// to such key.
|
||||
auto key = fam.getNull().family_key();
|
||||
auto it = props.find(key);
|
||||
|
||||
if (it == props.end()) return Property::Null;
|
||||
|
||||
return *it->second.get();
|
||||
auto f_key = fam.getNull().family_key();
|
||||
return at(f_key);
|
||||
}
|
||||
|
||||
template <class TG>
|
||||
const Property &Properties<TG>::at(prop_key_t &key) const
|
||||
const StoredProperty<TG> &Properties<TG>::at(property_key &key) const
|
||||
{
|
||||
auto it = props.find(key);
|
||||
|
||||
if (it == props.end() || it->first.prop_type() != key.prop_type())
|
||||
return Property::Null;
|
||||
|
||||
return *it->second.get();
|
||||
}
|
||||
|
||||
template <class TG>
|
||||
void Properties<TG>::set(prop_key_t &key, Property::sptr value)
|
||||
{
|
||||
// TODO: There is uneccesary copying of value here.
|
||||
auto result = props.insert(make_pair(key, value));
|
||||
if (!result.second) {
|
||||
// It is necessary to change key because the types from before and now
|
||||
// could be different.
|
||||
prop_key_t &key_ref = const_cast<prop_key_t &>(result.first->first);
|
||||
key_ref = key;
|
||||
result.first->second = std::move(value);
|
||||
for (auto &prop : props) {
|
||||
if (prop.key == key) {
|
||||
return prop;
|
||||
}
|
||||
}
|
||||
return StoredProperty<TG>::null;
|
||||
}
|
||||
|
||||
template <class TG>
|
||||
void Properties<TG>::clear(prop_key_t &key)
|
||||
void Properties<TG>::set(StoredProperty<TG> &&value)
|
||||
{
|
||||
props.erase(key);
|
||||
for (auto &prop : props) {
|
||||
if (prop.key == value.key) {
|
||||
// It is necessary to change key because the types from before and
|
||||
// now
|
||||
// could be different.
|
||||
StoredProperty<TG> &sp = const_cast<StoredProperty<TG> &>(prop);
|
||||
sp = std::move(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
props.push_back(std::move(value));
|
||||
}
|
||||
|
||||
template <class TG>
|
||||
void Properties<TG>::clear(property_key &key)
|
||||
{
|
||||
auto end = props.end();
|
||||
for (auto it = props.begin(); it != end; it++) {
|
||||
if (it->key == key) {
|
||||
props.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class TG>
|
||||
@ -60,8 +64,8 @@ void Properties<TG>::clear(PropertyFamily<TG> &fam)
|
||||
// find is called, thats why getNull
|
||||
// method is here to give fast access
|
||||
// to such key.
|
||||
auto key = fam.getNull().family_key();
|
||||
props.erase(key);
|
||||
auto f_key = fam.getNull().family_key();
|
||||
clear(f_key);
|
||||
}
|
||||
|
||||
template class Properties<TypeGroupEdge>;
|
||||
|
@ -1,13 +0,0 @@
|
||||
#include "storage/model/properties/property.hpp"
|
||||
|
||||
Property::Property(Flags flags) : flags(flags) {}
|
||||
|
||||
bool Property::operator!=(const Property& other) const
|
||||
{
|
||||
return !operator==(other);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Property& prop)
|
||||
{
|
||||
return prop.print(stream);
|
||||
}
|
11
src/storage/model/properties/stored_property.cpp
Normal file
11
src/storage/model/properties/stored_property.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "storage/model/properties/stored_property.hpp"
|
||||
|
||||
template <class TG>
|
||||
const PropertyFamily<TG> StoredProperty<TG>::null_family("NULL");
|
||||
|
||||
template <class TG>
|
||||
const StoredProperty<TG> StoredProperty<TG>::null = {
|
||||
Null(), StoredProperty<TG>::null_family.getNull().family_key()};
|
||||
|
||||
template class StoredProperty<TypeGroupVertex>;
|
||||
template class StoredProperty<TypeGroupEdge>;
|
@ -1,36 +1,25 @@
|
||||
#include "storage/model/properties/string.hpp"
|
||||
|
||||
String::String(const std::string& value) : Property(Flags::String), value(value) {}
|
||||
String::String(std::string&& value) : Property(Flags::String), value(value) {}
|
||||
const Type String::type = Type(Flags::String);
|
||||
|
||||
String::operator const std::string &() const { return value(); }
|
||||
|
||||
String::operator const std::string&() const
|
||||
bool String::operator==(const String &other) const
|
||||
{
|
||||
return value;
|
||||
return value() == other.value();
|
||||
}
|
||||
|
||||
bool String::operator==(const Property& other) const
|
||||
bool String::operator==(const std::string &other) const
|
||||
{
|
||||
return other.is<String>() && operator==(other.as<String>());
|
||||
return value() == other;
|
||||
}
|
||||
|
||||
bool String::operator==(const String& other) const
|
||||
std::ostream &operator<<(std::ostream &stream, const String &prop)
|
||||
{
|
||||
return value == other.value;
|
||||
return stream << prop.value();
|
||||
}
|
||||
|
||||
bool String::operator==(const std::string& other) const
|
||||
{
|
||||
return value == other;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const String& prop)
|
||||
{
|
||||
return stream << prop.value;
|
||||
}
|
||||
|
||||
std::ostream& String::print(std::ostream& stream) const
|
||||
std::ostream &String::print(std::ostream &stream) const
|
||||
{
|
||||
return operator<<(stream, *this);
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,8 @@ void run(size_t n, std::string &query, S &stripper, Q &qf)
|
||||
std::cout << "Running query [" << stripped.hash << "] for " << n << " time."
|
||||
<< std::endl;
|
||||
for (int i = 0; i < n; i++) {
|
||||
assert(qf[stripped.hash](stripped.arguments));
|
||||
properties_t vec = stripped.arguments;
|
||||
assert(qf[stripped.hash](std::move(vec)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,8 @@ int main(void)
|
||||
for (auto &query : queries) {
|
||||
auto stripped = stripper.strip(query);
|
||||
std::cout << "Query hash: " << stripped.hash << std::endl;
|
||||
auto result = query_functions[stripped.hash](stripped.arguments);
|
||||
auto result =
|
||||
query_functions[stripped.hash](std::move(stripped.arguments));
|
||||
permanent_assert(result == true,
|
||||
"Result retured from query function is not true");
|
||||
}
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
#include "barrier/barrier.cpp"
|
||||
|
||||
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
|
||||
#include "database/db.hpp"
|
||||
#include "query_engine/query_stripper.hpp"
|
||||
#include "storage/edges.cpp"
|
||||
#include "storage/edges.hpp"
|
||||
#include "storage/vertices.cpp"
|
||||
#include "storage/vertices.hpp"
|
||||
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -46,7 +46,7 @@ int main(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto result = queries[stripped.hash](stripped.arguments);
|
||||
auto result = queries[stripped.hash](std::move(stripped.arguments));
|
||||
cout << "RETURN: " << result << endl;
|
||||
|
||||
} while (command != "quit");
|
||||
|
@ -10,7 +10,7 @@ using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// arguments parsing
|
||||
auto arguments = all_arguments(argc, argv);
|
||||
@ -19,7 +19,7 @@ int main(int argc, char** argv)
|
||||
auto input_query = extract_query(arguments);
|
||||
|
||||
cout << "QUERY: " << input_query << endl;
|
||||
|
||||
|
||||
auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL);
|
||||
auto stripped = stripper.strip(input_query);
|
||||
|
||||
@ -28,10 +28,10 @@ int main(int argc, char** argv)
|
||||
QueryHasher query_hasher;
|
||||
|
||||
cout << "QUERY HASH: " << query_hasher.hash(stripped.query) << endl;
|
||||
|
||||
|
||||
cout << "PROPERTIES:" << endl;
|
||||
for (auto property : stripped.arguments) {
|
||||
cout << " " << *property << endl;
|
||||
cout << " " << property << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user