From 6f4996de0e5b34fcaced77be2fbbdd9235b7ad37 Mon Sep 17 00:00:00 2001 From: Kostas Kyrimis Date: Fri, 25 Nov 2022 16:20:38 +0200 Subject: [PATCH] Fix broken merge and address GH comments --- src/functions/awesome_memgraph_functions.hpp | 77 ++++++++++++-------- src/query/v2/accessors.hpp | 5 +- src/query/v2/shard_request_manager.hpp | 4 +- src/storage/v3/bindings/db_accessor.hpp | 2 +- src/storage/v3/request_helper.cpp | 10 +-- tests/unit/query_v2_expression_evaluator.cpp | 2 +- 6 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/functions/awesome_memgraph_functions.hpp b/src/functions/awesome_memgraph_functions.hpp index 475380217..7acfa6943 100644 --- a/src/functions/awesome_memgraph_functions.hpp +++ b/src/functions/awesome_memgraph_functions.hpp @@ -17,6 +17,7 @@ #include #include "storage/v3/result.hpp" +#include "storage/v3/shard.hpp" #include "storage/v3/view.hpp" #include "utils/algorithm.hpp" #include "utils/cast.hpp" @@ -440,15 +441,22 @@ TypedValueT Properties(const TypedValueT *args, int64_t nargs, const FunctionCon if constexpr (std::is_same_v) { auto maybe_props = record_accessor.Properties(ctx.view); if (maybe_props.HasError()) { - switch (maybe_props.GetError()) { - case storage::v3::Error::DELETED_OBJECT: + switch (maybe_props.GetError().code) { + case common::ErrorCode::DELETED_OBJECT: throw functions::FunctionRuntimeException("Trying to get properties from a deleted object."); - case storage::v3::Error::NONEXISTENT_OBJECT: + case common::ErrorCode::NONEXISTENT_OBJECT: throw functions::FunctionRuntimeException("Trying to get properties from an object that doesn't exist."); - case storage::v3::Error::SERIALIZATION_ERROR: - case storage::v3::Error::VERTEX_HAS_EDGES: - case storage::v3::Error::PROPERTIES_DISABLED: - case storage::v3::Error::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SERIALIZATION_ERROR: + case common::ErrorCode::VERTEX_HAS_EDGES: + case common::ErrorCode::PROPERTIES_DISABLED: + case common::ErrorCode::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY: + case common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED: + case common::ErrorCode::OBJECT_NOT_FOUND: throw functions::FunctionRuntimeException("Unexpected error when getting properties."); } } @@ -506,17 +514,24 @@ TypedValueT StartNode(const TypedValueT *args, int64_t nargs, const FunctionCont // This is needed because clang-tidy fails to identify the use of this function in the if-constexpr branch // NOLINTNEXTLINE(clang-diagnostic-unused-function) -inline size_t UnwrapDegreeResult(storage::v3::Result maybe_degree) { +inline size_t UnwrapDegreeResult(storage::v3::ShardResult maybe_degree) { if (maybe_degree.HasError()) { - switch (maybe_degree.GetError()) { - case storage::v3::Error::DELETED_OBJECT: + switch (maybe_degree.GetError().code) { + case common::ErrorCode::DELETED_OBJECT: throw functions::FunctionRuntimeException("Trying to get degree of a deleted node."); - case storage::v3::Error::NONEXISTENT_OBJECT: + case common::ErrorCode::NONEXISTENT_OBJECT: throw functions::FunctionRuntimeException("Trying to get degree of a node that doesn't exist."); - case storage::v3::Error::SERIALIZATION_ERROR: - case storage::v3::Error::VERTEX_HAS_EDGES: - case storage::v3::Error::PROPERTIES_DISABLED: - case storage::v3::Error::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SERIALIZATION_ERROR: + case common::ErrorCode::VERTEX_HAS_EDGES: + case common::ErrorCode::PROPERTIES_DISABLED: + case common::ErrorCode::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY: + case common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED: + case common::ErrorCode::OBJECT_NOT_FOUND: throw functions::FunctionRuntimeException("Unexpected error when getting node degree."); } } @@ -688,15 +703,22 @@ TypedValueT Labels(const TypedValueT *args, int64_t nargs, const FunctionContext if constexpr (std::is_same_v) { auto maybe_labels = args[0].ValueVertex().Labels(ctx.view); if (maybe_labels.HasError()) { - switch (maybe_labels.GetError()) { - case storage::v3::Error::DELETED_OBJECT: + switch (maybe_labels.GetError().code) { + case common::ErrorCode::DELETED_OBJECT: throw functions::FunctionRuntimeException("Trying to get labels from a deleted node."); - case storage::v3::Error::NONEXISTENT_OBJECT: + case common::ErrorCode::NONEXISTENT_OBJECT: throw functions::FunctionRuntimeException("Trying to get labels from a node that doesn't exist."); - case storage::v3::Error::SERIALIZATION_ERROR: - case storage::v3::Error::VERTEX_HAS_EDGES: - case storage::v3::Error::PROPERTIES_DISABLED: - case storage::v3::Error::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SERIALIZATION_ERROR: + case common::ErrorCode::VERTEX_HAS_EDGES: + case common::ErrorCode::PROPERTIES_DISABLED: + case common::ErrorCode::VERTEX_ALREADY_INSERTED: + case common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY: + case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL: + case common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY: + case common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED: + case common::ErrorCode::OBJECT_NOT_FOUND: throw functions::FunctionRuntimeException("Unexpected error when getting labels."); } } @@ -958,9 +980,9 @@ TypedValueT Counter(const TypedValueT *args, int64_t nargs, const FunctionContex template TypedValueT Id(const TypedValueT *args, int64_t nargs, const FunctionContextT &ctx) { - FType>("id", args, nargs); + FType>("id", args, nargs); const auto &arg = args[0]; - if (arg.IsNull() || arg.IsVertex()) { + if (arg.IsNull()) { return TypedValueT(ctx.memory); } return TypedValueT(static_cast(arg.ValueEdge().CypherId()), ctx.memory); @@ -1395,13 +1417,6 @@ NameToFunction(const std::string &function_name) { if (function_name == "LOCALDATETIME") return functions::impl::LocalDateTime; if (function_name == "DURATION") return functions::impl::Duration; - // Only on QE - if constexpr (std::is_same_v) { - if (function_name == "COUNTER") return functions::impl::Counter; - if (function_name == "STARTNODE") return functions::impl::StartNode; - if (function_name == "ENDNODE") return functions::impl::EndNode; - } - return nullptr; } diff --git a/src/query/v2/accessors.hpp b/src/query/v2/accessors.hpp index ba3937bb8..bb40fcef8 100644 --- a/src/query/v2/accessors.hpp +++ b/src/query/v2/accessors.hpp @@ -94,11 +94,10 @@ class VertexAccessor final { [[nodiscard]] msgs::Vertex GetVertex() const; // NOLINTNEXTLINE(readability-convert-member-functions-to-static) - [[nodiscard]] size_t InDegree() const { return 0; } + [[nodiscard]] size_t InDegree() const { throw utils::NotYetImplemented("InDegree() not yet implemented"); } // NOLINTNEXTLINE(readability-convert-member-functions-to-static) - [[nodiscard]] size_t OutDegree() const { return 0; } - // + [[nodiscard]] size_t OutDegree() const { throw utils::NotYetImplemented("OutDegree() not yet implemented"); } friend bool operator==(const VertexAccessor &lhs, const VertexAccessor &rhs) { return lhs.vertex == rhs.vertex && lhs.properties == rhs.properties; diff --git a/src/query/v2/shard_request_manager.hpp b/src/query/v2/shard_request_manager.hpp index 9c9c1d89e..dbf3a6bd8 100644 --- a/src/query/v2/shard_request_manager.hpp +++ b/src/query/v2/shard_request_manager.hpp @@ -130,7 +130,7 @@ class ShardRequestManagerInterface { virtual const std::string &LabelToName(memgraph::storage::v3::LabelId label) const = 0; virtual const std::string &EdgeTypeToName(memgraph::storage::v3::EdgeTypeId type) const = 0; virtual std::optional MaybeNameToProperty(const std::string &name) const = 0; - virtual std::optional MaybeNameToEdge(const std::string &name) const = 0; + virtual std::optional MaybeNameToEdgeType(const std::string &name) const = 0; virtual std::optional MaybeNameToLabel(const std::string &name) const = 0; virtual bool IsPrimaryLabel(LabelId label) const = 0; virtual bool IsPrimaryKey(LabelId primary_label, PropertyId property) const = 0; @@ -360,7 +360,7 @@ class ShardRequestManager : public ShardRequestManagerInterface { return shards_map_.GetPropertyId(name); } - std::optional MaybeNameToEdge(const std::string &name) const override { + std::optional MaybeNameToEdgeType(const std::string &name) const override { return shards_map_.GetEdgeTypeId(name); } diff --git a/src/storage/v3/bindings/db_accessor.hpp b/src/storage/v3/bindings/db_accessor.hpp index 1a5e846fa..6392ed18f 100644 --- a/src/storage/v3/bindings/db_accessor.hpp +++ b/src/storage/v3/bindings/db_accessor.hpp @@ -88,7 +88,7 @@ class DbAccessor final { } storage::v3::ShardResult> RemoveEdge(EdgeAccessor *edge) { - auto res = accessor_->DeleteEdge(edge->FromVertex(), edge->ToVertex(), edge->Gid()); + auto res = accessor_->DeleteEdge(edge->From(), edge->To(), edge->Gid()); if (res.HasError()) { return res.GetError(); } diff --git a/src/storage/v3/request_helper.cpp b/src/storage/v3/request_helper.cpp index 481741f60..3b0c18326 100644 --- a/src/storage/v3/request_helper.cpp +++ b/src/storage/v3/request_helper.cpp @@ -257,7 +257,7 @@ EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbo case msgs::EdgeDirection::OUT: { is_edge_unique = [](std::set &other_vertex_set, const storage::v3::EdgeAccessor &edge_acc) { - auto [it, insertion_happened] = other_vertex_set.insert(&edge_acc.ToVertex()); + auto [it, insertion_happened] = other_vertex_set.insert(&edge_acc.To()); return insertion_happened; }; break; @@ -265,7 +265,7 @@ EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbo case msgs::EdgeDirection::IN: { is_edge_unique = [](std::set &other_vertex_set, const storage::v3::EdgeAccessor &edge_acc) { - auto [it, insertion_happened] = other_vertex_set.insert(&edge_acc.FromVertex()); + auto [it, insertion_happened] = other_vertex_set.insert(&edge_acc.From()); return insertion_happened; }; break; @@ -311,8 +311,8 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) { value_properties.insert(std::make_pair(prop_key, FromPropertyValueToValue(std::move(prop_val)))); } using EdgeWithAllProperties = msgs::ExpandOneResultRow::EdgeWithAllProperties; - EdgeWithAllProperties edges{ToMsgsVertexId(edge.FromVertex()), msgs::EdgeType{edge.EdgeType()}, - edge.Gid().AsUint(), std::move(value_properties)}; + EdgeWithAllProperties edges{ToMsgsVertexId(edge.From()), msgs::EdgeType{edge.EdgeType()}, edge.Gid().AsUint(), + std::move(value_properties)}; if (is_in_edge) { result_row.in_edges_with_all_properties.push_back(std::move(edges)); } else { @@ -336,7 +336,7 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) { value_properties.emplace_back(FromPropertyValueToValue(std::move(property_result.GetValue()))); } using EdgeWithSpecificProperties = msgs::ExpandOneResultRow::EdgeWithSpecificProperties; - EdgeWithSpecificProperties edges{ToMsgsVertexId(edge.FromVertex()), msgs::EdgeType{edge.EdgeType()}, + EdgeWithSpecificProperties edges{ToMsgsVertexId(edge.From()), msgs::EdgeType{edge.EdgeType()}, edge.Gid().AsUint(), std::move(value_properties)}; if (is_in_edge) { result_row.in_edges_with_specific_properties.push_back(std::move(edges)); diff --git a/tests/unit/query_v2_expression_evaluator.cpp b/tests/unit/query_v2_expression_evaluator.cpp index 396d03eb6..de324ea2b 100644 --- a/tests/unit/query_v2_expression_evaluator.cpp +++ b/tests/unit/query_v2_expression_evaluator.cpp @@ -119,7 +119,7 @@ class MockedShardRequestManager : public memgraph::msgs::ShardRequestManagerInte return shards_map_.GetPropertyId(name); } - std::optional MaybeNameToEdge(const std::string &name) const override { + std::optional MaybeNameToEdgeType(const std::string &name) const override { return shards_map_.GetEdgeTypeId(name); }