Address review comments
This commit is contained in:
parent
e565fc6e3a
commit
ab5fc05fd7
@ -71,9 +71,9 @@ query::v2::TypedValue ToTypedValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
BoltResult<communication::bolt::Vertex> ToBoltVertex(const query::v2::accessors::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
communication::bolt::Vertex ToBoltVertex(const query::v2::accessors::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
auto id = communication::bolt::Id::FromUint(0);
|
||||
|
||||
auto labels = vertex.Labels();
|
||||
@ -91,9 +91,9 @@ BoltResult<communication::bolt::Vertex> ToBoltVertex(const query::v2::accessors:
|
||||
return communication::bolt::Vertex{id, new_labels, new_properties};
|
||||
}
|
||||
|
||||
BoltResult<communication::bolt::Edge> ToBoltEdge(const query::v2::accessors::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
communication::bolt::Edge ToBoltEdge(const query::v2::accessors::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
// TODO(jbajic) Fix bolt communication
|
||||
auto id = communication::bolt::Id::FromUint(0);
|
||||
auto from = communication::bolt::Id::FromUint(0);
|
||||
@ -108,15 +108,16 @@ BoltResult<communication::bolt::Edge> ToBoltEdge(const query::v2::accessors::Edg
|
||||
return communication::bolt::Edge{id, from, to, type, new_properties};
|
||||
}
|
||||
|
||||
BoltResult<communication::bolt::Path> ToBoltPath(const query::v2::accessors::Path & /*edge*/,
|
||||
const msgs::ShardRequestManagerInterface * /*shard_request_manager*/,
|
||||
storage::v3::View /*view*/) {
|
||||
communication::bolt::Path ToBoltPath(const query::v2::accessors::Path & /*edge*/,
|
||||
const msgs::ShardRequestManagerInterface * /*shard_request_manager*/,
|
||||
storage::v3::View /*view*/) {
|
||||
// TODO(jbajic) Fix bolt communication
|
||||
return {SHARD_ERROR(ErrorCode::DELETED_OBJECT)};
|
||||
MG_ASSERT(false, "Path is unimplemented!");
|
||||
return {};
|
||||
}
|
||||
|
||||
BoltResult<Value> ToBoltValue(const query::v2::TypedValue &value,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager, storage::v3::View view) {
|
||||
Value ToBoltValue(const query::v2::TypedValue &value, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view) {
|
||||
switch (value.type()) {
|
||||
case query::v2::TypedValue::Type::Null:
|
||||
return Value();
|
||||
@ -132,35 +133,30 @@ BoltResult<Value> ToBoltValue(const query::v2::TypedValue &value,
|
||||
std::vector<Value> values;
|
||||
values.reserve(value.ValueList().size());
|
||||
for (const auto &v : value.ValueList()) {
|
||||
auto maybe_value = ToBoltValue(v, shard_request_manager, view);
|
||||
if (maybe_value.HasError()) return maybe_value.GetError();
|
||||
values.emplace_back(std::move(*maybe_value));
|
||||
auto value = ToBoltValue(v, shard_request_manager, view);
|
||||
values.emplace_back(std::move(value));
|
||||
}
|
||||
return Value(std::move(values));
|
||||
}
|
||||
case query::v2::TypedValue::Type::Map: {
|
||||
std::map<std::string, Value> map;
|
||||
for (const auto &kv : value.ValueMap()) {
|
||||
auto maybe_value = ToBoltValue(kv.second, shard_request_manager, view);
|
||||
if (maybe_value.HasError()) return maybe_value.GetError();
|
||||
map.emplace(kv.first, std::move(*maybe_value));
|
||||
auto value = ToBoltValue(kv.second, shard_request_manager, view);
|
||||
map.emplace(kv.first, std::move(value));
|
||||
}
|
||||
return Value(std::move(map));
|
||||
}
|
||||
case query::v2::TypedValue::Type::Vertex: {
|
||||
auto maybe_vertex = ToBoltVertex(value.ValueVertex(), shard_request_manager, view);
|
||||
if (maybe_vertex.HasError()) return maybe_vertex.GetError();
|
||||
return Value(std::move(*maybe_vertex));
|
||||
auto vertex = ToBoltVertex(value.ValueVertex(), shard_request_manager, view);
|
||||
return Value(std::move(vertex));
|
||||
}
|
||||
case query::v2::TypedValue::Type::Edge: {
|
||||
auto maybe_edge = ToBoltEdge(value.ValueEdge(), shard_request_manager, view);
|
||||
if (maybe_edge.HasError()) return maybe_edge.GetError();
|
||||
return Value(std::move(*maybe_edge));
|
||||
auto edge = ToBoltEdge(value.ValueEdge(), shard_request_manager, view);
|
||||
return Value(std::move(edge));
|
||||
}
|
||||
case query::v2::TypedValue::Type::Path: {
|
||||
auto maybe_path = ToBoltPath(value.ValuePath(), shard_request_manager, view);
|
||||
if (maybe_path.HasError()) return maybe_path.GetError();
|
||||
return Value(std::move(*maybe_path));
|
||||
auto path = ToBoltPath(value.ValuePath(), shard_request_manager, view);
|
||||
return Value(std::move(path));
|
||||
}
|
||||
case query::v2::TypedValue::Type::Date:
|
||||
return Value(value.ValueDate());
|
||||
|
@ -30,45 +30,42 @@ class VertexAccessor;
|
||||
|
||||
namespace memgraph::glue::v2 {
|
||||
|
||||
template <class TValue>
|
||||
using BoltResult = utils::BasicResult<storage::v3::ShardError, TValue>;
|
||||
|
||||
/// @param storage::v3::VertexAccessor for converting to
|
||||
/// communication::bolt::Vertex.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager getting label and property names.
|
||||
/// @param storage::v3::View for deciding which vertex attributes are visible.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
BoltResult<communication::bolt::Vertex> ToBoltVertex(const storage::v3::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Vertex ToBoltVertex(const storage::v3::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param storage::v3::EdgeAccessor for converting to communication::bolt::Edge.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager getting edge type and property names.
|
||||
/// @param storage::v3::View for deciding which edge attributes are visible.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
BoltResult<communication::bolt::Edge> ToBoltEdge(const storage::v3::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Edge ToBoltEdge(const storage::v3::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param query::v2::Path for converting to communication::bolt::Path.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager ToBoltVertex and ToBoltEdge.
|
||||
/// @param storage::v3::View for ToBoltVertex and ToBoltEdge.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
BoltResult<communication::bolt::Path> ToBoltPath(const query::v2::accessors::Path &path,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Path ToBoltPath(const query::v2::accessors::Path &path,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param query::v2::TypedValue for converting to communication::bolt::Value.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager ToBoltVertex and ToBoltEdge.
|
||||
/// @param storage::v3::View for ToBoltVertex and ToBoltEdge.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
BoltResult<communication::bolt::Value> ToBoltValue(const query::v2::TypedValue &value,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Value ToBoltValue(const query::v2::TypedValue &value,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
query::v2::TypedValue ToTypedValue(const communication::bolt::Value &value);
|
||||
|
||||
|
@ -481,27 +481,9 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
const auto &summary = interpreter_.Pull(&stream, n, qid);
|
||||
std::map<std::string, memgraph::communication::bolt::Value> decoded_summary;
|
||||
for (const auto &kv : summary) {
|
||||
auto maybe_value = memgraph::glue::v2::ToBoltValue(kv.second, interpreter_.GetShardRequestManager(),
|
||||
memgraph::storage::v3::View::NEW);
|
||||
if (maybe_value.HasError()) {
|
||||
switch (maybe_value.GetError().code) {
|
||||
case memgraph::common::ErrorCode::DELETED_OBJECT:
|
||||
case memgraph::common::ErrorCode::SERIALIZATION_ERROR:
|
||||
case memgraph::common::ErrorCode::VERTEX_HAS_EDGES:
|
||||
case memgraph::common::ErrorCode::PROPERTIES_DISABLED:
|
||||
case memgraph::common::ErrorCode::NONEXISTENT_OBJECT:
|
||||
case memgraph::common::ErrorCode::VERTEX_ALREADY_INSERTED:
|
||||
case memgraph::common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
|
||||
case memgraph::common::ErrorCode::OBJECT_NOT_FOUND:
|
||||
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming summary.");
|
||||
}
|
||||
}
|
||||
decoded_summary.emplace(kv.first, std::move(*maybe_value));
|
||||
auto bolt_value = memgraph::glue::v2::ToBoltValue(kv.second, interpreter_.GetShardRequestManager(),
|
||||
memgraph::storage::v3::View::NEW);
|
||||
decoded_summary.emplace(kv.first, std::move(bolt_value));
|
||||
}
|
||||
return decoded_summary;
|
||||
} catch (const memgraph::query::v2::QueryException &e) {
|
||||
@ -522,28 +504,8 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
std::vector<memgraph::communication::bolt::Value> decoded_values;
|
||||
decoded_values.reserve(values.size());
|
||||
for (const auto &v : values) {
|
||||
auto maybe_value = memgraph::glue::v2::ToBoltValue(v, shard_request_manager_, memgraph::storage::v3::View::NEW);
|
||||
if (maybe_value.HasError()) {
|
||||
switch (maybe_value.GetError().code) {
|
||||
case memgraph::common::ErrorCode::DELETED_OBJECT:
|
||||
throw memgraph::communication::bolt::ClientError("Returning a deleted object as a result.");
|
||||
case memgraph::common::ErrorCode::NONEXISTENT_OBJECT:
|
||||
case memgraph::common::ErrorCode::OBJECT_NOT_FOUND:
|
||||
throw memgraph::communication::bolt::ClientError("Returning a nonexistent object as a result.");
|
||||
case memgraph::common::ErrorCode::VERTEX_HAS_EDGES:
|
||||
case memgraph::common::ErrorCode::SERIALIZATION_ERROR:
|
||||
case memgraph::common::ErrorCode::PROPERTIES_DISABLED:
|
||||
case memgraph::common::ErrorCode::VERTEX_ALREADY_INSERTED:
|
||||
case memgraph::common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
|
||||
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
|
||||
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming results.");
|
||||
}
|
||||
}
|
||||
decoded_values.emplace_back(std::move(*maybe_value));
|
||||
auto bolt_value = memgraph::glue::v2::ToBoltValue(v, shard_request_manager_, memgraph::storage::v3::View::NEW);
|
||||
decoded_values.emplace_back(std::move(bolt_value));
|
||||
}
|
||||
encoder_->MessageRecord(decoded_values);
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "utils/logging.hpp"
|
||||
#include "utils/skip_list.hpp"
|
||||
|
||||
|
@ -32,7 +32,6 @@ struct ShardError {
|
||||
: code{code}, source{fmt::format("{}:{}", location.file_name(), location.line())} {}
|
||||
|
||||
common::ErrorCode code;
|
||||
// TODO Maybe add category
|
||||
std::string message;
|
||||
std::string source;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user