From 8629ee5ebcfa87258b00de437b669000b077bac6 Mon Sep 17 00:00:00 2001 From: jbajic Date: Tue, 15 Nov 2022 19:30:34 +0100 Subject: [PATCH] Fix query v2 --- src/query/v2/common.hpp | 25 ++------------- src/query/v2/db_accessor.hpp | 56 ++++++++++++++++------------------ src/query/v2/plan/operator.cpp | 24 ++++++++++----- 3 files changed, 44 insertions(+), 61 deletions(-) diff --git a/src/query/v2/common.hpp b/src/query/v2/common.hpp index 55c60ce10..774a90a37 100644 --- a/src/query/v2/common.hpp +++ b/src/query/v2/common.hpp @@ -28,7 +28,6 @@ #include "storage/v3/id_types.hpp" #include "storage/v3/property_value.hpp" #include "storage/v3/result.hpp" -#include "storage/v3/shard_operation_result.hpp" #include "storage/v3/view.hpp" #include "utils/exceptions.hpp" #include "utils/logging.hpp" @@ -85,7 +84,7 @@ inline void ExpectType(const Symbol &symbol, const TypedValue &value, TypedValue template concept AccessorWithSetProperty = requires(T accessor, const storage::v3::PropertyId key, const storage::v3::PropertyValue new_value) { - { accessor.SetProperty(key, new_value) } -> std::same_as>; + { accessor.SetProperty(key, new_value) } -> std::same_as>; }; template @@ -93,28 +92,8 @@ concept AccessorWithSetPropertyAndValidate = requires(T accessor, const storage: const storage::v3::PropertyValue new_value) { { accessor.SetPropertyAndValidate(key, new_value) - } -> std::same_as>; + } -> std::same_as>; }; -template -concept RecordAccessor = - AccessorWithSetProperty || AccessorWithSetPropertyAndValidate; - -inline void HandleErrorOnPropertyUpdate(const storage::v3::Error error) { - switch (error) { - case storage::v3::Error::SERIALIZATION_ERROR: - throw TransactionSerializationException(); - case storage::v3::Error::DELETED_OBJECT: - throw QueryRuntimeException("Trying to set properties on a deleted object."); - case storage::v3::Error::PROPERTIES_DISABLED: - throw QueryRuntimeException("Can't set property because properties on edges are disabled."); - case storage::v3::Error::VERTEX_HAS_EDGES: - case storage::v3::Error::NONEXISTENT_OBJECT: - case storage::v3::Error::VERTEX_ALREADY_INSERTED: - - throw QueryRuntimeException("Unexpected error when setting a property."); - } -} - int64_t QueryTimestamp(); } // namespace memgraph::query::v2 diff --git a/src/query/v2/db_accessor.hpp b/src/query/v2/db_accessor.hpp index 11118a899..dfa23376f 100644 --- a/src/query/v2/db_accessor.hpp +++ b/src/query/v2/db_accessor.hpp @@ -64,21 +64,21 @@ class EdgeAccessor final { auto Properties(storage::v3::View view) const { return impl_.Properties(view); } - storage::v3::Result GetProperty(storage::v3::View view, - storage::v3::PropertyId key) const { + storage::v3::ShardResult GetProperty(storage::v3::View view, + storage::v3::PropertyId key) const { return impl_.GetProperty(key, view); } - storage::v3::Result SetProperty(storage::v3::PropertyId key, - const storage::v3::PropertyValue &value) { + storage::v3::ShardResult SetProperty(storage::v3::PropertyId key, + const storage::v3::PropertyValue &value) { return impl_.SetProperty(key, value); } - storage::v3::Result RemoveProperty(storage::v3::PropertyId key) { + storage::v3::ShardResult RemoveProperty(storage::v3::PropertyId key) { return SetProperty(key, storage::v3::PropertyValue()); } - storage::v3::Result> ClearProperties() { + storage::v3::ShardResult> ClearProperties() { return impl_.ClearProperties(); } @@ -113,53 +113,49 @@ class VertexAccessor final { auto PrimaryKey(storage::v3::View view) const { return impl_.PrimaryKey(view); } - storage::v3::ShardOperationResult AddLabel(storage::v3::LabelId label) { + storage::v3::ShardResult AddLabel(storage::v3::LabelId label) { return impl_.AddLabelAndValidate(label); } + + storage::v3::ShardResult AddLabelAndValidate(storage::v3::LabelId label) { return impl_.AddLabelAndValidate(label); } - storage::v3::ShardOperationResult AddLabelAndValidate(storage::v3::LabelId label) { - return impl_.AddLabelAndValidate(label); - } + storage::v3::ShardResult RemoveLabel(storage::v3::LabelId label) { return impl_.RemoveLabelAndValidate(label); } - storage::v3::ShardOperationResult RemoveLabel(storage::v3::LabelId label) { + storage::v3::ShardResult RemoveLabelAndValidate(storage::v3::LabelId label) { return impl_.RemoveLabelAndValidate(label); } - storage::v3::ShardOperationResult RemoveLabelAndValidate(storage::v3::LabelId label) { - return impl_.RemoveLabelAndValidate(label); - } - - storage::v3::Result HasLabel(storage::v3::View view, storage::v3::LabelId label) const { + storage::v3::ShardResult HasLabel(storage::v3::View view, storage::v3::LabelId label) const { return impl_.HasLabel(label, view); } auto Properties(storage::v3::View view) const { return impl_.Properties(view); } - storage::v3::Result GetProperty(storage::v3::View view, - storage::v3::PropertyId key) const { + storage::v3::ShardResult GetProperty(storage::v3::View view, + storage::v3::PropertyId key) const { return impl_.GetProperty(key, view); } - storage::v3::ShardOperationResult SetProperty(storage::v3::PropertyId key, - const storage::v3::PropertyValue &value) { + storage::v3::ShardResult SetProperty(storage::v3::PropertyId key, + const storage::v3::PropertyValue &value) { return impl_.SetPropertyAndValidate(key, value); } - storage::v3::ShardOperationResult SetPropertyAndValidate( - storage::v3::PropertyId key, const storage::v3::PropertyValue &value) { + storage::v3::ShardResult SetPropertyAndValidate(storage::v3::PropertyId key, + const storage::v3::PropertyValue &value) { return impl_.SetPropertyAndValidate(key, value); } - storage::v3::ShardOperationResult RemovePropertyAndValidate(storage::v3::PropertyId key) { + storage::v3::ShardResult RemovePropertyAndValidate(storage::v3::PropertyId key) { return SetPropertyAndValidate(key, storage::v3::PropertyValue{}); } - storage::v3::Result> ClearProperties() { + storage::v3::ShardResult> ClearProperties() { return impl_.ClearProperties(); } auto InEdges(storage::v3::View view, const std::vector &edge_types) const - -> storage::v3::Result { + -> storage::v3::ShardResult { auto maybe_edges = impl_.InEdges(view, edge_types); if (maybe_edges.HasError()) return maybe_edges.GetError(); return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges)); @@ -169,7 +165,7 @@ class VertexAccessor final { auto InEdges(storage::v3::View view, const std::vector &edge_types, const VertexAccessor &dest) const - -> storage::v3::Result { + -> storage::v3::ShardResult { const auto dest_id = dest.impl_.Id(view).GetValue(); auto maybe_edges = impl_.InEdges(view, edge_types, &dest_id); if (maybe_edges.HasError()) return maybe_edges.GetError(); @@ -177,7 +173,7 @@ class VertexAccessor final { } auto OutEdges(storage::v3::View view, const std::vector &edge_types) const - -> storage::v3::Result { + -> storage::v3::ShardResult { auto maybe_edges = impl_.OutEdges(view, edge_types); if (maybe_edges.HasError()) return maybe_edges.GetError(); return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges)); @@ -187,16 +183,16 @@ class VertexAccessor final { auto OutEdges(storage::v3::View view, const std::vector &edge_types, const VertexAccessor &dest) const - -> storage::v3::Result { + -> storage::v3::ShardResult { const auto dest_id = dest.impl_.Id(view).GetValue(); auto maybe_edges = impl_.OutEdges(view, edge_types, &dest_id); if (maybe_edges.HasError()) return maybe_edges.GetError(); return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges)); } - storage::v3::Result InDegree(storage::v3::View view) const { return impl_.InDegree(view); } + storage::v3::ShardResult InDegree(storage::v3::View view) const { return impl_.InDegree(view); } - storage::v3::Result OutDegree(storage::v3::View view) const { return impl_.OutDegree(view); } + storage::v3::ShardResult OutDegree(storage::v3::View view) const { return impl_.OutDegree(view); } // TODO(jbajic) Fix Remove Gid static int64_t CypherId() { return 1; } diff --git a/src/query/v2/plan/operator.cpp b/src/query/v2/plan/operator.cpp index 068ca9192..5e6e8bc9a 100644 --- a/src/query/v2/plan/operator.cpp +++ b/src/query/v2/plan/operator.cpp @@ -42,6 +42,7 @@ #include "query/v2/shard_request_manager.hpp" #include "storage/v3/conversions.hpp" #include "storage/v3/property_value.hpp" +#include "storage/v3/result.hpp" #include "utils/algorithm.hpp" #include "utils/csv_parsing.hpp" #include "utils/event_counter.hpp" @@ -566,17 +567,24 @@ UniqueCursorPtr ScanAllById::MakeCursor(utils::MemoryResource *mem) const { namespace { template -auto UnwrapEdgesResult(storage::v3::Result &&result) { +auto UnwrapEdgesResult(storage::v3::ShardResult &&result) { if (result.HasError()) { - switch (result.GetError()) { - case storage::v3::Error::DELETED_OBJECT: + switch (result.GetError().code) { + case storage::v3::ErrorCode::DELETED_OBJECT: throw QueryRuntimeException("Trying to get relationships of a deleted node."); - case storage::v3::Error::NONEXISTENT_OBJECT: + case storage::v3::ErrorCode::NONEXISTENT_OBJECT: throw query::v2::QueryRuntimeException("Trying to get relationships from a node that doesn't exist."); - case storage::v3::Error::VERTEX_HAS_EDGES: - case storage::v3::Error::SERIALIZATION_ERROR: - case storage::v3::Error::PROPERTIES_DISABLED: + case storage::v3::ErrorCode::VERTEX_HAS_EDGES: + case storage::v3::ErrorCode::SERIALIZATION_ERROR: + case storage::v3::ErrorCode::PROPERTIES_DISABLED: throw QueryRuntimeException("Unexpected error when accessing relationships."); + case storage::v3::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL: + case storage::v3::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE: + case storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY: + case storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL: + case storage::v3::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY: + case storage::v3::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED: + throw QueryRuntimeException("SchemaViolation occurred when accessing relationships."); } } return std::move(*result); @@ -843,7 +851,7 @@ concept AccessorWithProperties = requires(T value, storage::v3::PropertyId prope storage::v3::PropertyValue property_value) { { value.ClearProperties() - } -> std::same_as>>; + } -> std::same_as>>; {value.SetProperty(property_id, property_value)}; };