diff --git a/src/communication/bolt/v1/serialization/bolt_serializer.hpp b/src/communication/bolt/v1/serialization/bolt_serializer.hpp index 95f68beaa..cd7dfd88b 100644 --- a/src/communication/bolt/v1/serialization/bolt_serializer.hpp +++ b/src/communication/bolt/v1/serialization/bolt_serializer.hpp @@ -119,7 +119,7 @@ class BoltSerializer { encoder.write_string(value.Value()); return; case PropertyValue::Type::Int: - encoder.write_integer(value.Value()); + encoder.write_integer(value.Value()); return; case PropertyValue::Type::Double: encoder.write_double(value.Value()); diff --git a/src/communication/bolt/v1/serialization/result_stream.hpp b/src/communication/bolt/v1/serialization/result_stream.hpp index 7e7bb9d62..6f98a6892 100644 --- a/src/communication/bolt/v1/serialization/result_stream.hpp +++ b/src/communication/bolt/v1/serialization/result_stream.hpp @@ -14,18 +14,18 @@ namespace bolt { * * @tparam TChunkedEncoder Type of chunked encoder used. */ - // TODO templatisation on TChunkedEncoder might not be desired +// TODO templatisation on TChunkedEncoder might not be desired // but makes the code a bit easer to understand because we know // that this class uses a BoltEncoder (and not some arbitrary template) // it helps the programmer, the compiler and the IDE template class RecordStream { public: -// TODO add logging to this class + // TODO add logging to this class + + RecordStream(BoltEncoder &bolt_encoder) + : bolt_encoder_(bolt_encoder), serializer_(bolt_encoder) {} - RecordStream(BoltEncoder &bolt_encoder) : - bolt_encoder_(bolt_encoder), serializer_(bolt_encoder) {} - void Header(const std::vector &fields) { bolt_encoder_.message_success(); bolt_encoder_.write_map_header(1); @@ -65,7 +65,7 @@ class RecordStream { Chunk(); } -private: + private: BoltEncoder bolt_encoder_; BoltSerializer> serializer_; @@ -82,7 +82,7 @@ private: bolt_encoder_.write(value.Value()); break; case TypedValue::Type::Int: - bolt_encoder_.write(value.Value()); + bolt_encoder_.write(value.Value()); break; case TypedValue::Type::Double: bolt_encoder_.write(value.Value()); @@ -103,14 +103,14 @@ private: serializer_.write(value.Value()); break; default: - throw std::runtime_error("Serialization not implemented for given type"); + throw std::runtime_error( + "Serialization not implemented for given type"); } } void Write(const std::vector &values) { bolt_encoder_.write_list_header(values.size()); - for (const auto &value : values) - Write(value); + for (const auto &value : values) Write(value); } void Write(const std::map &values) { diff --git a/src/query/backend/cpp/typed_value.cpp b/src/query/backend/cpp/typed_value.cpp index c3a91e723..63cc4ce9c 100644 --- a/src/query/backend/cpp/typed_value.cpp +++ b/src/query/backend/cpp/typed_value.cpp @@ -18,7 +18,7 @@ TypedValue::TypedValue(const PropertyValue& value) { return; case PropertyValue::Type::Int: type_ = Type::Int; - int_v = value.Value(); + int_v = value.Value(); return; case PropertyValue::Type::Double: type_ = Type::Double; @@ -70,7 +70,7 @@ bool TypedValue::Value() const { } template <> -int TypedValue::Value() const { +int64_t TypedValue::Value() const { if (type_ != TypedValue::Type::Int) { throw TypedValueException("Incompatible template param and type"); } @@ -201,7 +201,7 @@ std::ostream& operator<<(std::ostream& os, const TypedValue& value) { case TypedValue::Type::Bool: return os << (value.Value() ? "true" : "false"); case TypedValue::Type::Int: - return os << value.Value(); + return os << value.Value(); case TypedValue::Type::Double: return os << value.Value(); case TypedValue::Type::String: @@ -318,7 +318,7 @@ TypedValue::~TypedValue() { double ToDouble(const TypedValue& value) { switch (value.type()) { case TypedValue::Type::Int: - return (double)value.Value(); + return (double)value.Value(); case TypedValue::Type::Double: return value.Value(); default: @@ -350,7 +350,7 @@ TypedValue operator<(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) < ToDouble(b); } else { - return a.Value() < b.Value(); + return a.Value() < b.Value(); } } @@ -413,7 +413,7 @@ TypedValue operator==(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) == ToDouble(b); } else { - return a.Value() == b.Value(); + return a.Value() == b.Value(); } } @@ -440,7 +440,7 @@ std::string ValueToString(const TypedValue& value) { case TypedValue::Type::String: return value.Value(); case TypedValue::Type::Int: - return std::to_string(value.Value()); + return std::to_string(value.Value()); case TypedValue::Type::Double: return fmt::format("{}", value.Value()); // unsupported situations @@ -455,7 +455,7 @@ TypedValue operator-(const TypedValue& a) { case TypedValue::Type::Null: return TypedValue::Null; case TypedValue::Type::Int: - return -a.Value(); + return -a.Value(); case TypedValue::Type::Double: return -a.Value(); default: @@ -521,7 +521,7 @@ TypedValue operator+(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) + ToDouble(b); } else { - return a.Value() + b.Value(); + return a.Value() + b.Value(); } } @@ -536,7 +536,7 @@ TypedValue operator-(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) - ToDouble(b); } else { - return a.Value() - b.Value(); + return a.Value() - b.Value(); } } @@ -551,7 +551,7 @@ TypedValue operator/(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) / ToDouble(b); } else { - return a.Value() / b.Value(); + return a.Value() / b.Value(); } } @@ -566,7 +566,7 @@ TypedValue operator*(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return ToDouble(a) * ToDouble(b); } else { - return a.Value() * b.Value(); + return a.Value() * b.Value(); } } @@ -581,7 +581,7 @@ TypedValue operator%(const TypedValue& a, const TypedValue& b) { b.type() == TypedValue::Type::Double) { return (double)fmod(ToDouble(a), ToDouble(b)); } else { - return a.Value() % b.Value(); + return a.Value() % b.Value(); } } diff --git a/src/query/backend/cpp/typed_value.hpp b/src/query/backend/cpp/typed_value.hpp index 3f3845863..213e8bd2a 100644 --- a/src/query/backend/cpp/typed_value.hpp +++ b/src/query/backend/cpp/typed_value.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "utils/exceptions/stacktrace_exception.hpp" #include "utils/total_ordering.hpp" @@ -50,6 +51,7 @@ class TypedValue : public TotalOrdering { // constructors for primitive types TypedValue(bool value) : type_(Type::Bool) { bool_v = value; } TypedValue(int value) : type_(Type::Int) { int_v = value; } + TypedValue(int64_t value) : type_(Type::Int) { int_v = value; } TypedValue(double value) : type_(Type::Double) { double_v = value; } // conversion function to PropertyValue @@ -102,7 +104,7 @@ class TypedValue : public TotalOrdering { // storage for the value of the property union { bool bool_v; - int int_v; + int64_t int_v; double double_v; // Since this is used in query runtime, size of union is not critical so // string and vector are used instead of pointers. It requires copy of data, diff --git a/src/query/stripper.hpp b/src/query/stripper.hpp index e28a99546..f778e1eaa 100644 --- a/src/query/stripper.hpp +++ b/src/query/stripper.hpp @@ -3,5 +3,5 @@ #include "query/stripped.hpp" namespace query { - StrippedQuery Strip(const std::string &query); +StrippedQuery Strip(const std::string &query); }; diff --git a/src/storage/property_value.cpp b/src/storage/property_value.cpp index d00baa245..c27247a15 100644 --- a/src/storage/property_value.cpp +++ b/src/storage/property_value.cpp @@ -25,7 +25,7 @@ std::string PropertyValue::Value() const { } template <> -int PropertyValue::Value() const { +int64_t PropertyValue::Value() const { if (type_ != PropertyValue::Type::Int) { throw PropertyValueException("Incompatible template param and type"); } @@ -105,7 +105,7 @@ std::ostream& operator<<(std::ostream& os, const PropertyValue& value) { case PropertyValue::Type::String: return os << value.Value(); case PropertyValue::Type::Int: - return os << value.Value(); + return os << value.Value(); case PropertyValue::Type::Double: return os << value.Value(); case PropertyValue::Type::List: diff --git a/src/storage/property_value.hpp b/src/storage/property_value.hpp index 35c19a751..94723fbac 100644 --- a/src/storage/property_value.hpp +++ b/src/storage/property_value.hpp @@ -32,6 +32,7 @@ class PropertyValue { // constructors for primitive types PropertyValue(bool value) : type_(Type::Bool) { bool_v = value; } PropertyValue(int value) : type_(Type::Int) { int_v = value; } + PropertyValue(int64_t value) : type_(Type::Int) { int_v = value; } PropertyValue(double value) : type_(Type::Double) { double_v = value; } /// constructors for non-primitive types (shared pointers) @@ -71,7 +72,7 @@ class PropertyValue { // storage for the value of the property union { bool bool_v; - int int_v; + int64_t int_v; double double_v; std::shared_ptr string_v; // We support lists of values of different types, neo4j supports lists of diff --git a/src/storage/property_value_utils.hpp b/src/storage/property_value_utils.hpp index 5f4c4fe14..0c52a5f32 100644 --- a/src/storage/property_value_utils.hpp +++ b/src/storage/property_value_utils.hpp @@ -16,19 +16,19 @@ * @param ostream The stream to write to. */ void PropertyValuesToJson(const PropertyValueStore& store, - std::ostream& ostream = std::cout) { + std::ostream& ostream = std::cout) { bool first = true; - auto write_key = [&ostream, - &first](const PropertyValueStore::TKey& key) -> std::ostream& { - if (first) { - ostream << '{'; - first = false; - } else - ostream << ','; + auto write_key = + [&ostream, &first](const PropertyValueStore::TKey& key) -> std::ostream& { + if (first) { + ostream << '{'; + first = false; + } else + ostream << ','; - return ostream << '"' << key << "\":"; - }; + return ostream << '"' << key << "\":"; + }; auto handler = [&ostream, &write_key](const PropertyValueStore::TKey& key, const PropertyValue& value) { @@ -42,7 +42,7 @@ void PropertyValuesToJson(const PropertyValueStore& store, write_key(key) << '"' << value.Value() << '"'; break; case PropertyValue::Type::Int: - write_key(key) << value.Value(); + write_key(key) << value.Value(); break; case PropertyValue::Type::Float: write_key(key) << value.Value(); diff --git a/tests/integration/hardcoded_query/clique.hpp b/tests/integration/hardcoded_query/clique.hpp index 295b2684d..357144b0e 100644 --- a/tests/integration/hardcoded_query/clique.hpp +++ b/tests/integration/hardcoded_query/clique.hpp @@ -28,9 +28,8 @@ using std::endl; enum CliqueQuery { SCORE_AND_LIMIT, FIND_ALL }; -bool run_general_query(GraphDbAccessor &db_accessor, - const Parameters &args, Stream &stream, - enum CliqueQuery query_type) { +bool run_general_query(GraphDbAccessor &db_accessor, const Parameters &args, + Stream &stream, enum CliqueQuery query_type) { if (query_type == CliqueQuery::FIND_ALL) stream.write_fields( {"a.garment_id", "b.garment_id", "c.garment_id", "d.garment_id"}); @@ -72,8 +71,8 @@ bool run_general_query(GraphDbAccessor &db_accessor, edges_indexed.push_back(&edges[i]); } const int n = vertices_indexed.size(); - auto cmp_vertex = [](const VertexAccessor *a, - const VertexAccessor *b) -> bool { return *a < *b; }; + auto cmp_vertex = [](const VertexAccessor *a, const VertexAccessor *b) + -> bool { return *a < *b; }; auto cmp_edge = [](const EdgeAccessor *a, const EdgeAccessor *b) -> bool { if (a->from() != b->from()) return a->from() < b->from(); return a->to() < b->to(); @@ -83,15 +82,15 @@ bool run_general_query(GraphDbAccessor &db_accessor, * @param v VertexAccessor to a vertex. * @return position of vertex or -1 if it doesn't exist. */ - auto query = [&vertices_indexed, - &cmp_vertex](const VertexAccessor &v) -> int { - int pos = lower_bound(vertices_indexed.begin(), vertices_indexed.end(), &v, - cmp_vertex) - - vertices_indexed.begin(); - if (pos == (int)vertices_indexed.size() || *vertices_indexed[pos] != v) - return -1; - return pos; - }; + auto query = + [&vertices_indexed, &cmp_vertex](const VertexAccessor &v) -> int { + int pos = lower_bound(vertices_indexed.begin(), vertices_indexed.end(), + &v, cmp_vertex) - + vertices_indexed.begin(); + if (pos == (int)vertices_indexed.size() || *vertices_indexed[pos] != v) + return -1; + return pos; + }; /** * Update bitset of neighbours. Set bit to 1 for index of every vertex * endpoint of edges with type default_outfit. @@ -148,15 +147,16 @@ bool run_general_query(GraphDbAccessor &db_accessor, * @return EdgeAccessor* if it exists, nullptr otherwise. */ auto get_edge = [&edges_indexed]( - const VertexAccessor &first, - const VertexAccessor &second) -> EdgeAccessor * { - auto cmp_edge_to_pair = []( - const EdgeAccessor *edge, - const pair &e) -> bool { - if (edge->from() != *e.first) return edge->from() < *e.first; - if (edge->to() != *e.second) return edge->to() < *e.second; - return false; - }; + const VertexAccessor &first, + const VertexAccessor &second) -> EdgeAccessor *{ + auto cmp_edge_to_pair = + [](const EdgeAccessor *edge, + const pair &e) + -> bool { + if (edge->from() != *e.first) return edge->from() < *e.first; + if (edge->to() != *e.second) return edge->to() < *e.second; + return false; + }; auto pos = lower_bound(edges_indexed.begin(), edges_indexed.end(), std::make_pair(&first, &second), cmp_edge_to_pair) - edges_indexed.begin(); @@ -180,18 +180,20 @@ bool run_general_query(GraphDbAccessor &db_accessor, * @param V index of clique vertices in vertices_indexed. * @return score if profile_index exists, else 0. */ - auto calc_score = [&db_accessor, &vertices, &profile_index, &vertices_indexed, - &get_edge](const std::vector &V) -> int { - int res = 0; - if (profile_index == -1) return 0; - for (auto x : V) { - auto edge = get_edge(vertices[profile_index], *vertices_indexed[x]); - if (edge == nullptr) continue; - auto prop = TypedValue(edge->PropsAt(db_accessor.property("score"))); - if (prop.type() == TypedValue::Type::Int) res += prop.Value(); - } - return res; - }; + auto calc_score = + [&db_accessor, &vertices, &profile_index, &vertices_indexed, &get_edge]( + const std::vector &V) -> int { + int res = 0; + if (profile_index == -1) return 0; + for (auto x : V) { + auto edge = get_edge(vertices[profile_index], *vertices_indexed[x]); + if (edge == nullptr) continue; + auto prop = TypedValue(edge->PropsAt(db_accessor.property("score"))); + if (prop.type() == TypedValue::Type::Int) + res += prop.Value(); + } + return res; + }; if (query_type == CliqueQuery::SCORE_AND_LIMIT) { auto cmp_results = [&calc_score](const std::vector &first, const std::vector &second) { @@ -201,7 +203,7 @@ bool run_general_query(GraphDbAccessor &db_accessor, reverse(results.begin(), results.end()); } const int limit = query_type == CliqueQuery::SCORE_AND_LIMIT - ? args.At((int)args.Size() - 1).Value() + ? args.at((int)args.size() - 1).Value() : (int)results.size(); for (int i = 0; i < std::min(limit, (int)results.size()); ++i) { stream.write_record(); @@ -210,7 +212,7 @@ bool run_general_query(GraphDbAccessor &db_accessor, for (auto x : results[i]) { stream.write(vertices_indexed[x] ->PropsAt(db_accessor.property("garment_id")) - .Value()); + .Value()); } if (query_type == CliqueQuery::SCORE_AND_LIMIT) stream.write(calc_score(results[i])); diff --git a/tests/unit/property_value_store.cpp b/tests/unit/property_value_store.cpp index 9ff51c91c..34b1d8748 100644 --- a/tests/unit/property_value_store.cpp +++ b/tests/unit/property_value_store.cpp @@ -19,7 +19,7 @@ TEST(PropertyValueStore, At) { props.set(0, some_string); EXPECT_EQ(PropertyValue(props.at(0)).Value(), some_string); props.set(120, 42); - EXPECT_EQ(PropertyValue(props.at(120)).Value(), 42); + EXPECT_EQ(PropertyValue(props.at(120)).Value(), 42); } TEST(PropertyValueStore, AtNull) { @@ -56,7 +56,7 @@ TEST(PropertyValueStore, Remove) { TEST(PropertyValueStore, Replace) { PropertyValueStore<> props; props.set(10, 42); - EXPECT_EQ(props.at(10).Value(), 42); + EXPECT_EQ(props.at(10).Value(), 42); props.set(10, 0.25f); EXPECT_EQ(props.at(10).type(), PropertyValue::Type::Double); EXPECT_FLOAT_EQ(props.at(10).Value(), 0.25); @@ -119,7 +119,7 @@ TEST(PropertyValueStore, InsertRetrieveList) { auto l = p.Value>(); EXPECT_EQ(l.size(), 5); EXPECT_EQ(l[0].type(), PropertyValue::Type::Int); - EXPECT_EQ(l[0].Value(), 1); + EXPECT_EQ(l[0].Value(), 1); EXPECT_EQ(l[1].type(), PropertyValue::Type::Bool); EXPECT_EQ(l[1].Value(), true); EXPECT_EQ(l[2].type(), PropertyValue::Type::Double); diff --git a/tests/unit/record_edge_vertex_accessor.cpp b/tests/unit/record_edge_vertex_accessor.cpp index 4d00291d6..b8660bd10 100644 --- a/tests/unit/record_edge_vertex_accessor.cpp +++ b/tests/unit/record_edge_vertex_accessor.cpp @@ -22,8 +22,8 @@ TEST(RecordAccessor, Properties) { EXPECT_EQ(vertex.PropsAt(property).type(), PropertyValue::Type::Null); vertex.PropsSet(property, 42); - EXPECT_EQ(vertex.PropsAt(property).Value(), 42); - EXPECT_EQ(properties.at(property).Value(), 42); + EXPECT_EQ(vertex.PropsAt(property).Value(), 42); + EXPECT_EQ(properties.at(property).Value(), 42); EXPECT_EQ(vertex.PropsAt(property_other).type(), PropertyValue::Type::Null); EXPECT_EQ(properties.at(property_other).type(), PropertyValue::Type::Null); diff --git a/tests/unit/typed_value.cpp b/tests/unit/typed_value.cpp index f9ebfaa14..5eb14e58a 100644 --- a/tests/unit/typed_value.cpp +++ b/tests/unit/typed_value.cpp @@ -61,7 +61,7 @@ TEST(TypedValue, CreationValues) { EXPECT_EQ(TypedValue(std::string("bla")).Value(), "bla"); EXPECT_EQ(TypedValue("bla2").Value(), "bla2"); - EXPECT_EQ(TypedValue(55).Value(), 55); + EXPECT_EQ(TypedValue(55).Value(), 55); EXPECT_FLOAT_EQ(TypedValue(66.6).Value(), 66.6); } @@ -139,7 +139,7 @@ TEST(TypedValue, LogicalNot) { TEST(TypedValue, UnaryMinus) { EXPECT_TRUE((-TypedValue::Null).type() == TypedValue::Type::Null); - EXPECT_PROP_EQ((-TypedValue(2).Value()), -2); + EXPECT_PROP_EQ((-TypedValue(2).Value()), -2); EXPECT_FLOAT_EQ((-TypedValue(2.0).Value()), -2.0); EXPECT_THROW(-TypedValue(true), TypedValueException); @@ -192,7 +192,7 @@ TEST(TypedValue, Sum) { true, [](const TypedValue& a, const TypedValue& b) { return a + b; }); // sum of props of the same type - EXPECT_EQ((TypedValue(2) + TypedValue(3)).Value(), 5); + EXPECT_EQ((TypedValue(2) + TypedValue(3)).Value(), 5); EXPECT_FLOAT_EQ((TypedValue(2.5) + TypedValue(1.25)).Value(), 3.75); EXPECT_EQ((TypedValue("one") + TypedValue("two")).Value(), "onetwo"); @@ -221,7 +221,7 @@ TEST(TypedValue, Difference) { false, [](const TypedValue& a, const TypedValue& b) { return a - b; }); // difference of props of the same type - EXPECT_EQ((TypedValue(2) - TypedValue(3)).Value(), -1); + EXPECT_EQ((TypedValue(2) - TypedValue(3)).Value(), -1); EXPECT_FLOAT_EQ((TypedValue(2.5) - TypedValue(2.25)).Value(), 0.25); // implicit casting