Fix broken merge and address GH comments

This commit is contained in:
Kostas Kyrimis 2022-11-25 16:20:38 +02:00
parent 01d5953bb6
commit 6f4996de0e
6 changed files with 57 additions and 43 deletions

View File

@ -17,6 +17,7 @@
#include <unordered_map>
#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<Tag, StorageEngineTag>) {
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<size_t> maybe_degree) {
inline size_t UnwrapDegreeResult(storage::v3::ShardResult<size_t> 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<Tag, StorageEngineTag>) {
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 <typename TypedValueT, typename FunctionContextT>
TypedValueT Id(const TypedValueT *args, int64_t nargs, const FunctionContextT &ctx) {
FType<TypedValueT, Or<Null, Vertex, Edge>>("id", args, nargs);
FType<TypedValueT, Or<Null, Edge>>("id", args, nargs);
const auto &arg = args[0];
if (arg.IsNull() || arg.IsVertex()) {
if (arg.IsNull()) {
return TypedValueT(ctx.memory);
}
return TypedValueT(static_cast<int64_t>(arg.ValueEdge().CypherId()), ctx.memory);
@ -1395,13 +1417,6 @@ NameToFunction(const std::string &function_name) {
if (function_name == "LOCALDATETIME") return functions::impl::LocalDateTime<TypedValueT, FunctionContextT>;
if (function_name == "DURATION") return functions::impl::Duration<TypedValueT, FunctionContextT>;
// Only on QE
if constexpr (std::is_same_v<Tag, QueryEngineTag>) {
if (function_name == "COUNTER") return functions::impl::Counter<TypedValueT, FunctionContextT>;
if (function_name == "STARTNODE") return functions::impl::StartNode<TypedValueT, FunctionContextT, Conv>;
if (function_name == "ENDNODE") return functions::impl::EndNode<TypedValueT, FunctionContextT>;
}
return nullptr;
}

View File

@ -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;

View File

@ -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<storage::v3::PropertyId> MaybeNameToProperty(const std::string &name) const = 0;
virtual std::optional<storage::v3::EdgeTypeId> MaybeNameToEdge(const std::string &name) const = 0;
virtual std::optional<storage::v3::EdgeTypeId> MaybeNameToEdgeType(const std::string &name) const = 0;
virtual std::optional<storage::v3::LabelId> 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<storage::v3::EdgeTypeId> MaybeNameToEdge(const std::string &name) const override {
std::optional<storage::v3::EdgeTypeId> MaybeNameToEdgeType(const std::string &name) const override {
return shards_map_.GetEdgeTypeId(name);
}

View File

@ -88,7 +88,7 @@ class DbAccessor final {
}
storage::v3::ShardResult<std::optional<EdgeAccessor>> 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();
}

View File

@ -257,7 +257,7 @@ EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbo
case msgs::EdgeDirection::OUT: {
is_edge_unique = [](std::set<const storage::v3::VertexId *, VertexIdCmpr> &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<const storage::v3::VertexId *, VertexIdCmpr> &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));

View File

@ -119,7 +119,7 @@ class MockedShardRequestManager : public memgraph::msgs::ShardRequestManagerInte
return shards_map_.GetPropertyId(name);
}
std::optional<storage::v3::EdgeTypeId> MaybeNameToEdge(const std::string &name) const override {
std::optional<storage::v3::EdgeTypeId> MaybeNameToEdgeType(const std::string &name) const override {
return shards_map_.GetEdgeTypeId(name);
}