Rename bolt::DecodedValue to bolt::Value

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1506
This commit is contained in:
Matej Ferencevic 2018-07-24 15:11:18 +02:00
parent 5c13c2d22c
commit e28fd2025d
35 changed files with 563 additions and 580 deletions

View File

@ -1,5 +1,5 @@
set(communication_src_files
bolt/v1/decoder/decoded_value.cpp
bolt/v1/value.cpp
buffer.cpp
client.cpp
context.cpp

View File

@ -29,8 +29,8 @@ class ClientQueryException : public utils::BasicException {
struct QueryData {
std::vector<std::string> fields;
std::vector<std::vector<DecodedValue>> records;
std::map<std::string, DecodedValue> metadata;
std::vector<std::vector<Value>> records;
std::map<std::string, Value> metadata;
};
class Client final {
@ -79,7 +79,7 @@ class Client final {
}
Signature signature;
DecodedValue metadata;
Value metadata;
if (!ReadMessage(&signature, &metadata)) {
LOG(ERROR) << "Couldn't read init message response!";
return false;
@ -95,7 +95,7 @@ class Client final {
}
QueryData Execute(const std::string &query,
const std::map<std::string, DecodedValue> &parameters) {
const std::map<std::string, Value> &parameters) {
DLOG(INFO) << "Sending run message with statement: '" << query
<< "'; parameters: " << parameters;
@ -104,11 +104,11 @@ class Client final {
DLOG(INFO) << "Reading run message response";
Signature signature;
DecodedValue fields;
Value fields;
if (!ReadMessage(&signature, &fields)) {
throw ClientFatalException();
}
if (fields.type() != DecodedValue::Type::Map) {
if (fields.type() != Value::Type::Map) {
throw ClientFatalException();
}
@ -126,8 +126,8 @@ class Client final {
DLOG(INFO) << "Reading pull_all message response";
Marker marker;
DecodedValue metadata;
std::vector<std::vector<DecodedValue>> records;
Value metadata;
std::vector<std::vector<Value>> records;
while (true) {
if (!GetMessage()) {
throw ClientFatalException();
@ -136,8 +136,8 @@ class Client final {
throw ClientFatalException();
}
if (signature == Signature::Record) {
DecodedValue record;
if (!decoder_.ReadValue(&record, DecodedValue::Type::List)) {
Value record;
if (!decoder_.ReadValue(&record, Value::Type::List)) {
throw ClientFatalException();
}
records.push_back(record.ValueList());
@ -147,7 +147,7 @@ class Client final {
}
break;
} else if (signature == Signature::Failure) {
DecodedValue data;
Value data;
if (!decoder_.ReadValue(&data)) {
throw ClientFatalException();
}
@ -163,7 +163,7 @@ class Client final {
}
}
if (metadata.type() != DecodedValue::Type::Map) {
if (metadata.type() != Value::Type::Map) {
throw ClientFatalException();
}
@ -173,13 +173,13 @@ class Client final {
if (header.find("fields") == header.end()) {
throw ClientFatalException();
}
if (header["fields"].type() != DecodedValue::Type::List) {
if (header["fields"].type() != Value::Type::List) {
throw ClientFatalException();
}
auto &field_vector = header["fields"].ValueList();
for (auto &field_item : field_vector) {
if (field_item.type() != DecodedValue::Type::String) {
if (field_item.type() != Value::Type::String) {
throw ClientFatalException();
}
ret.fields.push_back(field_item.ValueString());
@ -208,16 +208,16 @@ class Client final {
return true;
}
bool ReadMessage(Signature *signature, DecodedValue *ret) {
bool ReadMessage(Signature *signature, Value *ret) {
Marker marker;
if (!GetMessage()) return false;
if (!decoder_.ReadMessageHeader(signature, &marker)) return false;
return ReadMessageData(marker, ret);
}
bool ReadMessageData(Marker marker, DecodedValue *ret) {
bool ReadMessageData(Marker marker, Value *ret) {
if (marker == Marker::TinyStruct) {
*ret = DecodedValue();
*ret = Value();
return true;
} else if (marker == Marker::TinyStruct1) {
return decoder_.ReadValue(ret);
@ -231,7 +231,7 @@ class Client final {
}
while (true) {
Signature signature;
DecodedValue data;
Value data;
if (!ReadMessage(&signature, &data)) {
throw ClientFatalException();
}

View File

@ -5,7 +5,7 @@
#include <glog/logging.h>
#include "communication/bolt/v1/codes.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/bswap.hpp"
#include "utils/cast.hpp"
@ -23,14 +23,14 @@ class Decoder {
explicit Decoder(Buffer &buffer) : buffer_(buffer) {}
/**
* Reads a DecodedValue from the available data in the buffer.
* This function tries to read a DecodedValue from the available data.
* Reads a Value from the available data in the buffer.
* This function tries to read a Value from the available data.
*
* @param data pointer to a DecodedValue where the read data should be stored
* @param data pointer to a Value where the read data should be stored
* @returns true if data has been written to the data pointer,
* false otherwise
*/
bool ReadValue(DecodedValue *data) {
bool ReadValue(Value *data) {
uint8_t value;
if (!buffer_.Read(&value, 1)) {
@ -109,15 +109,15 @@ class Decoder {
}
/**
* Reads a DecodedValue from the available data in the buffer and checks
* Reads a Value from the available data in the buffer and checks
* whether the read data type matches the supplied data type.
*
* @param data pointer to a DecodedValue where the read data should be stored
* @param data pointer to a Value where the read data should be stored
* @param type the expected type that should be read
* @returns true if data has been written to the data pointer and the type
* matches the expected type, false otherwise
*/
bool ReadValue(DecodedValue *data, DecodedValue::Type type) {
bool ReadValue(Value *data, Value::Type type) {
if (!ReadValue(data)) {
return false;
}
@ -152,24 +152,24 @@ class Decoder {
Buffer &buffer_;
private:
bool ReadNull(const Marker &marker, DecodedValue *data) {
bool ReadNull(const Marker &marker, Value *data) {
DCHECK(marker == Marker::Null) << "Received invalid marker!";
*data = DecodedValue();
*data = Value();
return true;
}
bool ReadBool(const Marker &marker, DecodedValue *data) {
bool ReadBool(const Marker &marker, Value *data) {
DCHECK(marker == Marker::False || marker == Marker::True)
<< "Received invalid marker!";
if (marker == Marker::False) {
*data = DecodedValue(false);
*data = Value(false);
} else {
*data = DecodedValue(true);
*data = Value(true);
}
return true;
}
bool ReadInt(const Marker &marker, DecodedValue *data) {
bool ReadInt(const Marker &marker, Value *data) {
uint8_t value = utils::UnderlyingCast(marker);
int64_t ret;
if (value >= 240 || value <= 127) {
@ -201,11 +201,11 @@ class Decoder {
} else {
return false;
}
*data = DecodedValue(ret);
*data = Value(ret);
return true;
}
bool ReadDouble(const Marker marker, DecodedValue *data) {
bool ReadDouble(const Marker marker, Value *data) {
uint64_t value;
double ret;
DCHECK(marker == Marker::Float64) << "Received invalid marker!";
@ -215,7 +215,7 @@ class Decoder {
value = utils::Bswap(value);
// cppcheck-suppress invalidPointerCast
ret = *reinterpret_cast<double *>(&value);
*data = DecodedValue(ret);
*data = Value(ret);
return true;
}
@ -248,7 +248,7 @@ class Decoder {
}
}
bool ReadString(const Marker &marker, DecodedValue *data) {
bool ReadString(const Marker &marker, Value *data) {
const int kMaxStackBuffer = 8192;
uint8_t buffer[kMaxStackBuffer];
auto size = ReadTypeSize(marker, MarkerString);
@ -261,55 +261,54 @@ class Decoder {
// way we allocate a temporary buffer only when the string is large. This
// wouldn't be necessary if we had full C++17 support. In C++17 we could
// preallocate the `buffer[size]` in the destination string `*data =
// DecodedValue(std::string('\0', size))` and just call
// Value(std::string('\0', size))` and just call
// `buffer_.Read(data->ValueString().data())`.
if (size < kMaxStackBuffer) {
if (!buffer_.Read(buffer, size)) {
DLOG(WARNING) << "[ReadString] Missing data!";
return false;
}
*data = DecodedValue(std::string(reinterpret_cast<char *>(buffer), size));
*data = Value(std::string(reinterpret_cast<char *>(buffer), size));
} else {
std::unique_ptr<uint8_t[]> ret(new uint8_t[size]);
if (!buffer_.Read(ret.get(), size)) {
DLOG(WARNING) << "[ReadString] Missing data!";
return false;
}
*data =
DecodedValue(std::string(reinterpret_cast<char *>(ret.get()), size));
*data = Value(std::string(reinterpret_cast<char *>(ret.get()), size));
}
return true;
}
bool ReadList(const Marker &marker, DecodedValue *data) {
bool ReadList(const Marker &marker, Value *data) {
auto size = ReadTypeSize(marker, MarkerList);
if (size == -1) {
return false;
}
std::vector<DecodedValue> ret(size);
std::vector<Value> ret(size);
for (int64_t i = 0; i < size; ++i) {
if (!ReadValue(&ret[i])) {
return false;
}
}
*data = DecodedValue(ret);
*data = Value(ret);
return true;
}
bool ReadMap(const Marker &marker, DecodedValue *data) {
bool ReadMap(const Marker &marker, Value *data) {
auto size = ReadTypeSize(marker, MarkerMap);
if (size == -1) {
return false;
}
DecodedValue dv;
Value dv;
std::string str;
std::map<std::string, DecodedValue> ret;
std::map<std::string, Value> ret;
for (int64_t i = 0; i < size; ++i) {
if (!ReadValue(&dv)) {
return false;
}
if (dv.type() != DecodedValue::Type::String) {
if (dv.type() != Value::Type::String) {
return false;
}
str = dv.ValueString();
@ -323,48 +322,48 @@ class Decoder {
return false;
}
*data = DecodedValue(ret);
*data = Value(ret);
return true;
}
bool ReadVertex(DecodedValue *data) {
DecodedValue dv;
DecodedVertex vertex;
bool ReadVertex(Value *data) {
Value dv;
Vertex vertex;
// read ID
if (!ReadValue(&dv, DecodedValue::Type::Int)) {
if (!ReadValue(&dv, Value::Type::Int)) {
return false;
}
vertex.id = Id::FromInt(dv.ValueInt());
// read labels
if (!ReadValue(&dv, DecodedValue::Type::List)) {
if (!ReadValue(&dv, Value::Type::List)) {
return false;
}
auto &labels = dv.ValueList();
vertex.labels.resize(labels.size());
for (size_t i = 0; i < labels.size(); ++i) {
if (labels[i].type() != DecodedValue::Type::String) {
if (labels[i].type() != Value::Type::String) {
return false;
}
vertex.labels[i] = labels[i].ValueString();
}
// read properties
if (!ReadValue(&dv, DecodedValue::Type::Map)) {
if (!ReadValue(&dv, Value::Type::Map)) {
return false;
}
vertex.properties = dv.ValueMap();
*data = DecodedValue(vertex);
*data = Value(vertex);
return true;
}
bool ReadEdge(const Marker &marker, DecodedValue *data) {
bool ReadEdge(const Marker &marker, Value *data) {
uint8_t value;
DecodedValue dv;
DecodedEdge edge;
Value dv;
Edge edge;
if (!buffer_.Read(&value, 1)) {
return false;
@ -379,105 +378,105 @@ class Decoder {
}
// read ID
if (!ReadValue(&dv, DecodedValue::Type::Int)) {
if (!ReadValue(&dv, Value::Type::Int)) {
return false;
}
edge.id = Id::FromInt(dv.ValueInt());
// read from
if (!ReadValue(&dv, DecodedValue::Type::Int)) {
if (!ReadValue(&dv, Value::Type::Int)) {
return false;
}
edge.from = Id::FromInt(dv.ValueInt());
// read to
if (!ReadValue(&dv, DecodedValue::Type::Int)) {
if (!ReadValue(&dv, Value::Type::Int)) {
return false;
}
edge.to = Id::FromInt(dv.ValueInt());
// read type
if (!ReadValue(&dv, DecodedValue::Type::String)) {
if (!ReadValue(&dv, Value::Type::String)) {
return false;
}
edge.type = dv.ValueString();
// read properties
if (!ReadValue(&dv, DecodedValue::Type::Map)) {
if (!ReadValue(&dv, Value::Type::Map)) {
return false;
}
edge.properties = dv.ValueMap();
*data = DecodedValue(edge);
*data = Value(edge);
return true;
}
bool ReadUnboundedEdge(DecodedValue *data) {
DecodedValue dv;
DecodedUnboundedEdge edge;
bool ReadUnboundedEdge(Value *data) {
Value dv;
UnboundedEdge edge;
// read ID
if (!ReadValue(&dv, DecodedValue::Type::Int)) {
if (!ReadValue(&dv, Value::Type::Int)) {
return false;
}
edge.id = Id::FromInt(dv.ValueInt());
// read type
if (!ReadValue(&dv, DecodedValue::Type::String)) {
if (!ReadValue(&dv, Value::Type::String)) {
return false;
}
edge.type = dv.ValueString();
// read properties
if (!ReadValue(&dv, DecodedValue::Type::Map)) {
if (!ReadValue(&dv, Value::Type::Map)) {
return false;
}
edge.properties = dv.ValueMap();
*data = DecodedValue(edge);
*data = Value(edge);
return true;
}
bool ReadPath(DecodedValue *data) {
DecodedValue dv;
DecodedPath path;
bool ReadPath(Value *data) {
Value dv;
Path path;
// vertices
if (!ReadValue(&dv, DecodedValue::Type::List)) {
if (!ReadValue(&dv, Value::Type::List)) {
return false;
}
for (const auto &vertex : dv.ValueList()) {
if (vertex.type() != DecodedValue::Type::Vertex) {
if (vertex.type() != Value::Type::Vertex) {
return false;
}
path.vertices.emplace_back(vertex.ValueVertex());
}
// edges
if (!ReadValue(&dv, DecodedValue::Type::List)) {
if (!ReadValue(&dv, Value::Type::List)) {
return false;
}
for (const auto &edge : dv.ValueList()) {
if (edge.type() != DecodedValue::Type::UnboundedEdge) {
if (edge.type() != Value::Type::UnboundedEdge) {
return false;
}
path.edges.emplace_back(edge.ValueUnboundedEdge());
}
// indices
if (!ReadValue(&dv, DecodedValue::Type::List)) {
if (!ReadValue(&dv, Value::Type::List)) {
return false;
}
for (const auto &index : dv.ValueList()) {
if (index.type() != DecodedValue::Type::Int) {
if (index.type() != Value::Type::Int) {
return false;
}
path.indices.emplace_back(index.ValueInt());
}
*data = DecodedValue(path);
*data = Value(path);
return true;
}

View File

@ -1,14 +1,14 @@
#pragma once
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/encoder/primitive_encoder.hpp"
#include "communication/bolt/v1/value.hpp"
namespace communication::bolt {
/**
* Bolt BaseEncoder. Subclass of PrimitiveEncoder. Extends it with the
* capability to encode DecodedValues (as well as lists and maps of
* DecodedValues), Edges, Vertices and Paths.
* capability to encode Values (as well as lists and maps of Values), Edges,
* Vertices and Paths.
*
* @tparam Buffer the output buffer that should be used
*/
@ -17,26 +17,26 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
public:
explicit BaseEncoder(Buffer &buffer) : PrimitiveEncoder<Buffer>(buffer) {}
void WriteList(const std::vector<DecodedValue> &value) {
void WriteList(const std::vector<Value> &value) {
this->WriteTypeSize(value.size(), MarkerList);
for (auto &x : value) WriteDecodedValue(x);
for (auto &x : value) WriteValue(x);
}
/**
* Writes a map value.
*
* @tparam TMap - an iterable of (std::string, DecodedValue) pairs.
* @tparam TMap - an iterable of (std::string, Value) pairs.
*/
template <typename TMap>
void WriteMap(const TMap &value) {
this->WriteTypeSize(value.size(), MarkerMap);
for (auto &x : value) {
this->WriteString(x.first);
WriteDecodedValue(x.second);
WriteValue(x.second);
}
}
void WriteVertex(const DecodedVertex &vertex) {
void WriteVertex(const Vertex &vertex) {
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) + 3);
this->WriteRAW(utils::UnderlyingCast(Signature::Node));
this->WriteInt(vertex.id.AsInt());
@ -51,11 +51,11 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
this->WriteTypeSize(props.size(), MarkerMap);
for (const auto &prop : props) {
this->WriteString(prop.first);
WriteDecodedValue(prop.second);
WriteValue(prop.second);
}
}
void WriteEdge(const DecodedEdge &edge, bool unbound = false) {
void WriteEdge(const Edge &edge, bool unbound = false) {
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) +
(unbound ? 3 : 5));
this->WriteRAW(utils::UnderlyingCast(
@ -73,11 +73,11 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
this->WriteTypeSize(props.size(), MarkerMap);
for (const auto &prop : props) {
this->WriteString(prop.first);
WriteDecodedValue(prop.second);
WriteValue(prop.second);
}
}
void WriteEdge(const DecodedUnboundedEdge &edge) {
void WriteEdge(const UnboundedEdge &edge) {
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) + 3);
this->WriteRAW(utils::UnderlyingCast(Signature::UnboundRelationship));
@ -89,11 +89,11 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
this->WriteTypeSize(props.size(), MarkerMap);
for (const auto &prop : props) {
this->WriteString(prop.first);
WriteDecodedValue(prop.second);
WriteValue(prop.second);
}
}
void WritePath(const DecodedPath &path) {
void WritePath(const Path &path) {
this->WriteRAW(utils::UnderlyingCast(Marker::TinyStruct) + 3);
this->WriteRAW(utils::UnderlyingCast(Signature::Path));
this->WriteTypeSize(path.vertices.size(), MarkerList);
@ -104,39 +104,39 @@ class BaseEncoder : public PrimitiveEncoder<Buffer> {
for (auto &i : path.indices) this->WriteInt(i);
}
void WriteDecodedValue(const DecodedValue &value) {
void WriteValue(const Value &value) {
switch (value.type()) {
case DecodedValue::Type::Null:
case Value::Type::Null:
this->WriteNull();
break;
case DecodedValue::Type::Bool:
case Value::Type::Bool:
this->WriteBool(value.ValueBool());
break;
case DecodedValue::Type::Int:
case Value::Type::Int:
this->WriteInt(value.ValueInt());
break;
case DecodedValue::Type::Double:
case Value::Type::Double:
this->WriteDouble(value.ValueDouble());
break;
case DecodedValue::Type::String:
case Value::Type::String:
this->WriteString(value.ValueString());
break;
case DecodedValue::Type::List:
case Value::Type::List:
WriteList(value.ValueList());
break;
case DecodedValue::Type::Map:
case Value::Type::Map:
WriteMap(value.ValueMap());
break;
case DecodedValue::Type::Vertex:
case Value::Type::Vertex:
WriteVertex(value.ValueVertex());
break;
case DecodedValue::Type::Edge:
case Value::Type::Edge:
WriteEdge(value.ValueEdge());
break;
case DecodedValue::Type::UnboundedEdge:
case Value::Type::UnboundedEdge:
WriteEdge(value.ValueUnboundedEdge());
break;
case DecodedValue::Type::Path:
case Value::Type::Path:
WritePath(value.ValuePath());
break;
}

View File

@ -39,7 +39,7 @@ class ClientEncoder : private BaseEncoder<Buffer> {
* when flushing, false otherwise
*/
bool MessageInit(const std::string client_name,
const std::map<std::string, DecodedValue> &auth_token) {
const std::map<std::string, Value> &auth_token) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct2));
WriteRAW(utils::UnderlyingCast(Signature::Init));
WriteString(client_name);
@ -66,7 +66,7 @@ class ClientEncoder : private BaseEncoder<Buffer> {
* when flushing, false otherwise
*/
bool MessageRun(const std::string &statement,
const std::map<std::string, DecodedValue> &parameters,
const std::map<std::string, Value> &parameters,
bool have_more = true) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct2));
WriteRAW(utils::UnderlyingCast(Signature::Run));

View File

@ -33,7 +33,7 @@ class Encoder : private BaseEncoder<Buffer> {
*
* @param values the fields list object that should be sent
*/
bool MessageRecord(const std::vector<DecodedValue> &values) {
bool MessageRecord(const std::vector<Value> &values) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
WriteRAW(utils::UnderlyingCast(Signature::Record));
WriteList(values);
@ -59,7 +59,7 @@ class Encoder : private BaseEncoder<Buffer> {
* @returns true if the data was successfully sent to the client
* when flushing, false otherwise
*/
bool MessageSuccess(const std::map<std::string, DecodedValue> &metadata) {
bool MessageSuccess(const std::map<std::string, Value> &metadata) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
WriteRAW(utils::UnderlyingCast(Signature::Success));
WriteMap(metadata);
@ -79,7 +79,7 @@ class Encoder : private BaseEncoder<Buffer> {
* false otherwise
*/
bool MessageSuccess() {
std::map<std::string, DecodedValue> metadata;
std::map<std::string, Value> metadata;
return MessageSuccess(metadata);
}
@ -95,7 +95,7 @@ class Encoder : private BaseEncoder<Buffer> {
* @returns true if the data was successfully sent to the client,
* false otherwise
*/
bool MessageFailure(const std::map<std::string, DecodedValue> &metadata) {
bool MessageFailure(const std::map<std::string, Value> &metadata) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
WriteRAW(utils::UnderlyingCast(Signature::Failure));
WriteMap(metadata);
@ -118,7 +118,7 @@ class Encoder : private BaseEncoder<Buffer> {
* @returns true if the data was successfully sent to the client,
* false otherwise
*/
bool MessageIgnored(const std::map<std::string, DecodedValue> &metadata) {
bool MessageIgnored(const std::map<std::string, Value> &metadata) {
WriteRAW(utils::UnderlyingCast(Marker::TinyStruct1));
WriteRAW(utils::UnderlyingCast(Signature::Ignored));
WriteMap(metadata);

View File

@ -49,13 +49,13 @@ class Session {
/**
* Process the given `query` with `params`.
*/
virtual std::vector<std::string> Interpret(const std::string &query,
const std::map<std::string, DecodedValue> &params) = 0;
virtual std::vector<std::string> Interpret(
const std::string &query, const std::map<std::string, Value> &params) = 0;
/**
* Put results of the processed query in the `encoder`.
*/
virtual std::map<std::string, DecodedValue> PullAll(TEncoder *encoder) = 0;
virtual std::map<std::string, Value> PullAll(TEncoder *encoder) = 0;
/** Aborts currently running query. */
virtual void Abort() = 0;

View File

@ -4,8 +4,8 @@
#include <glog/logging.h>
#include "communication/bolt/v1/codes.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/state.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/cast.hpp"
namespace communication::bolt {
@ -60,7 +60,7 @@ State StateErrorRun(TSession &session, State state) {
// We need to clean up all parameters from this command.
value &= 0x0F; // The length is stored in the lower nibble.
DecodedValue dv;
Value dv;
for (int i = 0; i < value; ++i) {
if (!session.decoder_.ReadValue(&dv)) {
DLOG(WARNING) << fmt::format("Couldn't clean up parameter {} / {}!", i,

View File

@ -7,8 +7,8 @@
#include <glog/logging.h>
#include "communication/bolt/v1/codes.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/state.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/exceptions.hpp"
namespace communication::bolt {
@ -71,8 +71,8 @@ inline std::pair<std::string, std::string> ExceptionToErrorMessage(
template <typename TSession>
State HandleRun(TSession &session, State state, Marker marker) {
const std::map<std::string, DecodedValue> kEmptyFields = {
{"fields", std::vector<DecodedValue>{}}};
const std::map<std::string, Value> kEmptyFields = {
{"fields", std::vector<Value>{}}};
if (marker != Marker::TinyStruct2) {
DLOG(WARNING) << fmt::format(
@ -81,13 +81,13 @@ State HandleRun(TSession &session, State state, Marker marker) {
return State::Close;
}
DecodedValue query, params;
if (!session.decoder_.ReadValue(&query, DecodedValue::Type::String)) {
Value query, params;
if (!session.decoder_.ReadValue(&query, Value::Type::String)) {
DLOG(WARNING) << "Couldn't read query string!";
return State::Close;
}
if (!session.decoder_.ReadValue(&params, DecodedValue::Type::Map)) {
if (!session.decoder_.ReadValue(&params, Value::Type::Map)) {
DLOG(WARNING) << "Couldn't read parameters!";
return State::Close;
}
@ -108,12 +108,12 @@ State HandleRun(TSession &session, State state, Marker marker) {
try {
// Interpret can throw.
auto header = session.Interpret(query.ValueString(), params.ValueMap());
// Convert std::string to DecodedValue
std::vector<DecodedValue> vec;
std::map<std::string, DecodedValue> data;
// Convert std::string to Value
std::vector<Value> vec;
std::map<std::string, Value> data;
vec.reserve(header.size());
for (auto &i : header) vec.push_back(DecodedValue(i));
data.insert(std::make_pair(std::string("fields"), DecodedValue(vec)));
for (auto &i : header) vec.push_back(Value(i));
data.insert(std::make_pair(std::string("fields"), Value(vec)));
// Send the header.
if (!session.encoder_.MessageSuccess(data)) {
DLOG(WARNING) << "Couldn't send query header!";

View File

@ -4,8 +4,8 @@
#include <glog/logging.h>
#include "communication/bolt/v1/codes.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/state.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/likely.hpp"
namespace communication::bolt {
@ -44,14 +44,14 @@ State StateInitRun(Session &session) {
// return State::Close;
}
DecodedValue client_name;
if (!session.decoder_.ReadValue(&client_name, DecodedValue::Type::String)) {
Value client_name;
if (!session.decoder_.ReadValue(&client_name, Value::Type::String)) {
DLOG(WARNING) << "Couldn't read client name!";
return State::Close;
}
DecodedValue metadata;
if (!session.decoder_.ReadValue(&metadata, DecodedValue::Type::Map)) {
Value metadata;
if (!session.decoder_.ReadValue(&metadata, Value::Type::Map)) {
DLOG(WARNING) << "Couldn't read metadata!";
return State::Close;
}

View File

@ -1,4 +1,4 @@
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include <glog/logging.h>
@ -6,14 +6,14 @@
namespace communication::bolt {
#define DEF_GETTER_BY_VAL(type, value_type, field) \
value_type &DecodedValue::Value##type() { \
if (type_ != Type::type) throw DecodedValueException(); \
return field; \
} \
value_type DecodedValue::Value##type() const { \
if (type_ != Type::type) throw DecodedValueException(); \
return field; \
#define DEF_GETTER_BY_VAL(type, value_type, field) \
value_type &Value::Value##type() { \
if (type_ != Type::type) throw ValueException(); \
return field; \
} \
value_type Value::Value##type() const { \
if (type_ != Type::type) throw ValueException(); \
return field; \
}
DEF_GETTER_BY_VAL(Bool, bool, bool_v)
@ -22,28 +22,28 @@ DEF_GETTER_BY_VAL(Double, double, double_v)
#undef DEF_GETTER_BY_VAL
#define DEF_GETTER_BY_REF(type, value_type, field) \
value_type &DecodedValue::Value##type() { \
if (type_ != Type::type) throw DecodedValueException(); \
return field; \
} \
const value_type &DecodedValue::Value##type() const { \
if (type_ != Type::type) throw DecodedValueException(); \
return field; \
#define DEF_GETTER_BY_REF(type, value_type, field) \
value_type &Value::Value##type() { \
if (type_ != Type::type) throw ValueException(); \
return field; \
} \
const value_type &Value::Value##type() const { \
if (type_ != Type::type) throw ValueException(); \
return field; \
}
DEF_GETTER_BY_REF(String, std::string, string_v)
DEF_GETTER_BY_REF(List, std::vector<DecodedValue>, list_v)
using map_t = std::map<std::string, DecodedValue>;
DEF_GETTER_BY_REF(List, std::vector<Value>, list_v)
using map_t = std::map<std::string, Value>;
DEF_GETTER_BY_REF(Map, map_t, map_v)
DEF_GETTER_BY_REF(Vertex, DecodedVertex, vertex_v)
DEF_GETTER_BY_REF(Edge, DecodedEdge, edge_v)
DEF_GETTER_BY_REF(UnboundedEdge, DecodedUnboundedEdge, unbounded_edge_v)
DEF_GETTER_BY_REF(Path, DecodedPath, path_v)
DEF_GETTER_BY_REF(Vertex, Vertex, vertex_v)
DEF_GETTER_BY_REF(Edge, Edge, edge_v)
DEF_GETTER_BY_REF(UnboundedEdge, UnboundedEdge, unbounded_edge_v)
DEF_GETTER_BY_REF(Path, Path, path_v)
#undef DEF_GETTER_BY_REF
DecodedValue::DecodedValue(const DecodedValue &other) : type_(other.type_) {
Value::Value(const Value &other) : type_(other.type_) {
switch (other.type_) {
case Type::Null:
return;
@ -60,30 +60,30 @@ DecodedValue::DecodedValue(const DecodedValue &other) : type_(other.type_) {
new (&string_v) std::string(other.string_v);
return;
case Type::List:
new (&list_v) std::vector<DecodedValue>(other.list_v);
new (&list_v) std::vector<Value>(other.list_v);
return;
case Type::Map:
new (&map_v) std::map<std::string, DecodedValue>(other.map_v);
new (&map_v) std::map<std::string, Value>(other.map_v);
return;
case Type::Vertex:
new (&vertex_v) DecodedVertex(other.vertex_v);
new (&vertex_v) Vertex(other.vertex_v);
return;
case Type::Edge:
new (&edge_v) DecodedEdge(other.edge_v);
new (&edge_v) Edge(other.edge_v);
return;
case Type::UnboundedEdge:
new (&unbounded_edge_v) DecodedUnboundedEdge(other.unbounded_edge_v);
new (&unbounded_edge_v) UnboundedEdge(other.unbounded_edge_v);
return;
case Type::Path:
new (&path_v) DecodedPath(other.path_v);
new (&path_v) Path(other.path_v);
return;
}
LOG(FATAL) << "Unsupported DecodedValue::Type";
LOG(FATAL) << "Unsupported Value::Type";
}
DecodedValue &DecodedValue::operator=(const DecodedValue &other) {
Value &Value::operator=(const Value &other) {
if (this != &other) {
this->~DecodedValue();
this->~Value();
// set the type of this
type_ = other.type_;
@ -103,30 +103,30 @@ DecodedValue &DecodedValue::operator=(const DecodedValue &other) {
new (&string_v) std::string(other.string_v);
return *this;
case Type::List:
new (&list_v) std::vector<DecodedValue>(other.list_v);
new (&list_v) std::vector<Value>(other.list_v);
return *this;
case Type::Map:
new (&map_v) std::map<std::string, DecodedValue>(other.map_v);
new (&map_v) std::map<std::string, Value>(other.map_v);
return *this;
case Type::Vertex:
new (&vertex_v) DecodedVertex(other.vertex_v);
new (&vertex_v) Vertex(other.vertex_v);
return *this;
case Type::Edge:
new (&edge_v) DecodedEdge(other.edge_v);
new (&edge_v) Edge(other.edge_v);
return *this;
case Type::UnboundedEdge:
new (&unbounded_edge_v) DecodedUnboundedEdge(other.unbounded_edge_v);
new (&unbounded_edge_v) UnboundedEdge(other.unbounded_edge_v);
return *this;
case Type::Path:
new (&path_v) DecodedPath(other.path_v);
new (&path_v) Path(other.path_v);
return *this;
}
LOG(FATAL) << "Unsupported DecodedValue::Type";
LOG(FATAL) << "Unsupported Value::Type";
}
return *this;
}
DecodedValue::~DecodedValue() {
Value::~Value() {
switch (type_) {
// destructor for primitive types does nothing
case Type::Null:
@ -145,29 +145,29 @@ DecodedValue::~DecodedValue() {
return;
case Type::List:
using namespace std;
list_v.~vector<DecodedValue>();
list_v.~vector<Value>();
return;
case Type::Map:
using namespace std;
map_v.~map<std::string, DecodedValue>();
map_v.~map<std::string, Value>();
return;
case Type::Vertex:
vertex_v.~DecodedVertex();
vertex_v.~Vertex();
return;
case Type::Edge:
edge_v.~DecodedEdge();
edge_v.~Edge();
return;
case Type::UnboundedEdge:
unbounded_edge_v.~DecodedUnboundedEdge();
unbounded_edge_v.~UnboundedEdge();
return;
case Type::Path:
path_v.~DecodedPath();
path_v.~Path();
return;
}
LOG(FATAL) << "Unsupported DecodedValue::Type";
LOG(FATAL) << "Unsupported Value::Type";
}
std::ostream &operator<<(std::ostream &os, const DecodedVertex &vertex) {
std::ostream &operator<<(std::ostream &os, const Vertex &vertex) {
os << "V(";
utils::PrintIterable(os, vertex.labels, ":",
[&](auto &stream, auto label) { stream << label; });
@ -179,7 +179,7 @@ std::ostream &operator<<(std::ostream &os, const DecodedVertex &vertex) {
return os << "})";
}
std::ostream &operator<<(std::ostream &os, const DecodedEdge &edge) {
std::ostream &operator<<(std::ostream &os, const Edge &edge) {
os << "E[" << edge.type;
os << " {";
utils::PrintIterable(os, edge.properties, ", ",
@ -189,7 +189,7 @@ std::ostream &operator<<(std::ostream &os, const DecodedEdge &edge) {
return os << "}]";
}
std::ostream &operator<<(std::ostream &os, const DecodedUnboundedEdge &edge) {
std::ostream &operator<<(std::ostream &os, const UnboundedEdge &edge) {
os << "E[" << edge.type;
os << " {";
utils::PrintIterable(os, edge.properties, ", ",
@ -199,7 +199,7 @@ std::ostream &operator<<(std::ostream &os, const DecodedUnboundedEdge &edge) {
return os << "}]";
}
std::ostream &operator<<(std::ostream &os, const DecodedPath &path) {
std::ostream &operator<<(std::ostream &os, const Path &path) {
os << path.vertices[0];
DCHECK(path.indices.size() % 2 == 0) << "Must have even number of indices";
for (auto it = path.indices.begin(); it != path.indices.end();) {
@ -220,66 +220,66 @@ std::ostream &operator<<(std::ostream &os, const DecodedPath &path) {
return os;
}
std::ostream &operator<<(std::ostream &os, const DecodedValue &value) {
std::ostream &operator<<(std::ostream &os, const Value &value) {
switch (value.type_) {
case DecodedValue::Type::Null:
case Value::Type::Null:
return os << "Null";
case DecodedValue::Type::Bool:
case Value::Type::Bool:
return os << (value.ValueBool() ? "true" : "false");
case DecodedValue::Type::Int:
case Value::Type::Int:
return os << value.ValueInt();
case DecodedValue::Type::Double:
case Value::Type::Double:
return os << value.ValueDouble();
case DecodedValue::Type::String:
case Value::Type::String:
return os << value.ValueString();
case DecodedValue::Type::List:
case Value::Type::List:
os << "[";
utils::PrintIterable(os, value.ValueList());
return os << "]";
case DecodedValue::Type::Map:
case Value::Type::Map:
os << "{";
utils::PrintIterable(os, value.ValueMap(), ", ",
[](auto &stream, const auto &pair) {
stream << pair.first << ": " << pair.second;
});
return os << "}";
case DecodedValue::Type::Vertex:
case Value::Type::Vertex:
return os << value.ValueVertex();
case DecodedValue::Type::Edge:
case Value::Type::Edge:
return os << value.ValueEdge();
case DecodedValue::Type::UnboundedEdge:
case Value::Type::UnboundedEdge:
return os << value.ValueUnboundedEdge();
case DecodedValue::Type::Path:
case Value::Type::Path:
return os << value.ValuePath();
}
LOG(FATAL) << "Unsupported DecodedValue::Type";
LOG(FATAL) << "Unsupported Value::Type";
}
std::ostream &operator<<(std::ostream &os, const DecodedValue::Type type) {
std::ostream &operator<<(std::ostream &os, const Value::Type type) {
switch (type) {
case DecodedValue::Type::Null:
case Value::Type::Null:
return os << "null";
case DecodedValue::Type::Bool:
case Value::Type::Bool:
return os << "bool";
case DecodedValue::Type::Int:
case Value::Type::Int:
return os << "int";
case DecodedValue::Type::Double:
case Value::Type::Double:
return os << "double";
case DecodedValue::Type::String:
case Value::Type::String:
return os << "string";
case DecodedValue::Type::List:
case Value::Type::List:
return os << "list";
case DecodedValue::Type::Map:
case Value::Type::Map:
return os << "map";
case DecodedValue::Type::Vertex:
case Value::Type::Vertex:
return os << "vertex";
case DecodedValue::Type::Edge:
case Value::Type::Edge:
return os << "edge";
case DecodedValue::Type::UnboundedEdge:
case Value::Type::UnboundedEdge:
return os << "unbounded_edge";
case DecodedValue::Type::Path:
case Value::Type::Path:
return os << "path";
}
LOG(FATAL) << "Unsupported DecodedValue::Type";
LOG(FATAL) << "Unsupported Value::Type";
}
}

View File

@ -10,8 +10,8 @@
namespace communication::bolt {
/** Forward declaration of DecodedValue class. */
class DecodedValue;
/** Forward declaration of Value class. */
class Value;
/** Wraps int64_t to prevent dangerous implicit conversions. */
class Id {
@ -43,43 +43,42 @@ inline bool operator!=(const Id &id1, const Id &id2) { return !(id1 == id2); }
* Structure used when reading a Vertex with the decoder.
* The decoder writes data into this structure.
*/
struct DecodedVertex {
struct Vertex {
Id id;
std::vector<std::string> labels;
std::map<std::string, DecodedValue> properties;
std::map<std::string, Value> properties;
};
/**
* Structure used when reading an Edge with the decoder.
* The decoder writes data into this structure.
*/
struct DecodedEdge {
struct Edge {
Id id;
Id from;
Id to;
std::string type;
std::map<std::string, DecodedValue> properties;
std::map<std::string, Value> properties;
};
/**
* Structure used when reading an UnboundEdge with the decoder.
* The decoder writes data into this structure.
*/
struct DecodedUnboundedEdge {
struct UnboundedEdge {
Id id;
std::string type;
std::map<std::string, DecodedValue> properties;
std::map<std::string, Value> properties;
};
/**
* Structure used when reading a Path with the decoder.
* The decoder writes data into this structure.
*/
struct DecodedPath {
DecodedPath() {}
struct Path {
Path() {}
DecodedPath(const std::vector<DecodedVertex> &vertices,
const std::vector<DecodedEdge> &edges) {
Path(const std::vector<Vertex> &vertices, const std::vector<Edge> &edges) {
// Helper function. Looks for the given element in the collection. If found,
// puts its index into `indices`. Otherwise emplaces the given element
// into the collection and puts that index into `indices`. A multiplier is
@ -101,16 +100,16 @@ struct DecodedPath {
for (uint i = 0; i < edges.size(); i++) {
const auto &e = edges[i];
const auto &v = vertices[i + 1];
DecodedUnboundedEdge unbounded_edge{e.id, e.type, e.properties};
UnboundedEdge unbounded_edge{e.id, e.type, e.properties};
add_element(this->edges, unbounded_edge, e.to == v.id ? 1 : -1, 1);
add_element(this->vertices, v, 1, 0);
}
}
/** Unique vertices in the path. */
std::vector<DecodedVertex> vertices;
std::vector<Vertex> vertices;
/** Unique edges in the path. */
std::vector<DecodedUnboundedEdge> edges;
std::vector<UnboundedEdge> edges;
/**
* Indices that map path positions to vertices/edges.
* Positive indices for left-to-right directionality and negative for
@ -119,13 +118,13 @@ struct DecodedPath {
std::vector<int64_t> indices;
};
/** DecodedValue represents supported values in the Bolt protocol. */
class DecodedValue {
/** Value represents supported values in the Bolt protocol. */
class Value {
public:
/** Default constructor, makes Null */
DecodedValue() : type_(Type::Null) {}
Value() : type_(Type::Null) {}
/** Types that can be stored in a DecodedValue. */
/** Types that can be stored in a Value. */
enum class Type : unsigned {
Null,
Bool,
@ -141,39 +140,34 @@ class DecodedValue {
};
// constructors for primitive types
DecodedValue(bool value) : type_(Type::Bool) { bool_v = value; }
DecodedValue(int value) : type_(Type::Int) { int_v = value; }
DecodedValue(int64_t value) : type_(Type::Int) { int_v = value; }
DecodedValue(double value) : type_(Type::Double) { double_v = value; }
Value(bool value) : type_(Type::Bool) { bool_v = value; }
Value(int value) : type_(Type::Int) { int_v = value; }
Value(int64_t value) : type_(Type::Int) { int_v = value; }
Value(double value) : type_(Type::Double) { double_v = value; }
// constructors for non-primitive types
DecodedValue(const std::string &value) : type_(Type::String) {
Value(const std::string &value) : type_(Type::String) {
new (&string_v) std::string(value);
}
DecodedValue(const char *value) : DecodedValue(std::string(value)) {}
DecodedValue(const std::vector<DecodedValue> &value) : type_(Type::List) {
new (&list_v) std::vector<DecodedValue>(value);
Value(const char *value) : Value(std::string(value)) {}
Value(const std::vector<Value> &value) : type_(Type::List) {
new (&list_v) std::vector<Value>(value);
}
DecodedValue(const std::map<std::string, DecodedValue> &value)
: type_(Type::Map) {
new (&map_v) std::map<std::string, DecodedValue>(value);
Value(const std::map<std::string, Value> &value) : type_(Type::Map) {
new (&map_v) std::map<std::string, Value>(value);
}
DecodedValue(const DecodedVertex &value) : type_(Type::Vertex) {
new (&vertex_v) DecodedVertex(value);
Value(const Vertex &value) : type_(Type::Vertex) {
new (&vertex_v) Vertex(value);
}
DecodedValue(const DecodedEdge &value) : type_(Type::Edge) {
new (&edge_v) DecodedEdge(value);
}
DecodedValue(const DecodedUnboundedEdge &value) : type_(Type::UnboundedEdge) {
new (&unbounded_edge_v) DecodedUnboundedEdge(value);
}
DecodedValue(const DecodedPath &value) : type_(Type::Path) {
new (&path_v) DecodedPath(value);
Value(const Edge &value) : type_(Type::Edge) { new (&edge_v) Edge(value); }
Value(const UnboundedEdge &value) : type_(Type::UnboundedEdge) {
new (&unbounded_edge_v) UnboundedEdge(value);
}
Value(const Path &value) : type_(Type::Path) { new (&path_v) Path(value); }
DecodedValue &operator=(const DecodedValue &other);
DecodedValue(const DecodedValue &other);
~DecodedValue();
Value &operator=(const Value &other);
Value(const Value &other);
~Value();
Type type() const { return type_; }
@ -192,13 +186,13 @@ class DecodedValue {
const value_type &Value##type() const;
DECL_GETTER_BY_REFERENCE(String, std::string)
DECL_GETTER_BY_REFERENCE(List, std::vector<DecodedValue>)
using map_t = std::map<std::string, DecodedValue>;
DECL_GETTER_BY_REFERENCE(List, std::vector<Value>)
using map_t = std::map<std::string, Value>;
DECL_GETTER_BY_REFERENCE(Map, map_t)
DECL_GETTER_BY_REFERENCE(Vertex, DecodedVertex)
DECL_GETTER_BY_REFERENCE(Edge, DecodedEdge)
DECL_GETTER_BY_REFERENCE(UnboundedEdge, DecodedUnboundedEdge)
DECL_GETTER_BY_REFERENCE(Path, DecodedPath)
DECL_GETTER_BY_REFERENCE(Vertex, Vertex)
DECL_GETTER_BY_REFERENCE(Edge, Edge)
DECL_GETTER_BY_REFERENCE(UnboundedEdge, UnboundedEdge)
DECL_GETTER_BY_REFERENCE(Path, Path)
#undef DECL_GETTER_BY_REFERNCE
@ -218,7 +212,7 @@ class DecodedValue {
#undef TYPE_CHECKER
friend std::ostream &operator<<(std::ostream &os, const DecodedValue &value);
friend std::ostream &operator<<(std::ostream &os, const Value &value);
private:
Type type_;
@ -229,32 +223,31 @@ class DecodedValue {
int64_t int_v;
double double_v;
std::string string_v;
std::vector<DecodedValue> list_v;
std::map<std::string, DecodedValue> map_v;
DecodedVertex vertex_v;
DecodedEdge edge_v;
DecodedUnboundedEdge unbounded_edge_v;
DecodedPath path_v;
std::vector<Value> list_v;
std::map<std::string, Value> map_v;
Vertex vertex_v;
Edge edge_v;
UnboundedEdge unbounded_edge_v;
Path path_v;
};
};
/**
* An exception raised by the DecodedValue system.
* An exception raised by the Value system.
*/
class DecodedValueException : public utils::BasicException {
class ValueException : public utils::BasicException {
public:
using utils::BasicException::BasicException;
DecodedValueException()
: BasicException("Incompatible template param and type!") {}
ValueException() : BasicException("Incompatible template param and type!") {}
};
/**
* Output operators.
*/
std::ostream &operator<<(std::ostream &os, const DecodedVertex &vertex);
std::ostream &operator<<(std::ostream &os, const DecodedEdge &edge);
std::ostream &operator<<(std::ostream &os, const DecodedUnboundedEdge &edge);
std::ostream &operator<<(std::ostream &os, const DecodedPath &path);
std::ostream &operator<<(std::ostream &os, const DecodedValue &value);
std::ostream &operator<<(std::ostream &os, const DecodedValue::Type type);
std::ostream &operator<<(std::ostream &os, const Vertex &vertex);
std::ostream &operator<<(std::ostream &os, const Edge &edge);
std::ostream &operator<<(std::ostream &os, const UnboundedEdge &edge);
std::ostream &operator<<(std::ostream &os, const Path &path);
std::ostream &operator<<(std::ostream &os, const Value &value);
std::ostream &operator<<(std::ostream &os, const Value::Type type);
} // namespace communication::bolt

View File

@ -4,7 +4,7 @@
#include "glog/logging.h"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/algorithm.hpp"
// TODO: Why is this here?! It's only used in tests and query/repl.cpp
@ -15,7 +15,7 @@
* sent to it in an acceptable order, and tracks
* the content of those messages.
*/
template <class TResultValue = communication::bolt::DecodedValue>
template <class TResultValue = communication::bolt::Value>
class ResultStreamFaker {
public:
ResultStreamFaker() = default;

View File

@ -2,7 +2,7 @@
#include <string>
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "database/graph_db_accessor.hpp"
#include "glue/conversion.hpp"
@ -208,13 +208,13 @@ void StateDelta::Encode(
encoder.WriteInt(vertex_id);
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteDecodedValue(glue::ToDecodedValue(value));
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::SET_PROPERTY_EDGE:
encoder.WriteInt(edge_id);
encoder.WriteInt(property.Id());
encoder.WriteString(property_name);
encoder.WriteDecodedValue(glue::ToDecodedValue(value));
encoder.WriteValue(glue::ToBoltValue(value));
break;
case Type::ADD_LABEL:
case Type::REMOVE_LABEL:
@ -254,7 +254,7 @@ std::experimental::optional<StateDelta> StateDelta::Decode(
StateDelta r_val;
// The decoded value used as a temporary while decoding.
communication::bolt::DecodedValue dv;
communication::bolt::Value dv;
try {
if (!decoder.ReadValue(&dv)) return nullopt;
@ -339,7 +339,7 @@ std::experimental::optional<StateDelta> StateDelta::Decode(
if (decoder_hash != encoded_hash) return nullopt;
return r_val;
} catch (communication::bolt::DecodedValueException &) {
} catch (communication::bolt::ValueException &) {
return nullopt;
} catch (std::ifstream::failure &) {
return nullopt;

View File

@ -8,8 +8,8 @@
#include "database/indexes/label_property_index.hpp"
#include "durability/hashed_file_reader.hpp"
#include "durability/paths.hpp"
#include "durability/snapshot_decoded_value.hpp"
#include "durability/snapshot_decoder.hpp"
#include "durability/snapshot_value.hpp"
#include "durability/version.hpp"
#include "durability/wal.hpp"
#include "glue/conversion.hpp"
@ -35,7 +35,7 @@ bool ReadSnapshotSummary(HashedFileReader &buffer, int64_t &vertex_count,
}
namespace {
using communication::bolt::DecodedValue;
using communication::bolt::Value;
#define RETURN_IF_NOT(condition) \
if (!(condition)) { \
@ -61,36 +61,36 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
RETURN_IF_NOT(
durability::ReadSnapshotSummary(reader, vertex_count, edge_count, hash));
DecodedValue dv;
Value dv;
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::Int) &&
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::Int) &&
dv.ValueInt() == durability::kVersion);
// Checks worker id was set correctly
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::Int) &&
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::Int) &&
dv.ValueInt() == db->WorkerId());
// Vertex and edge generator ids
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::Int));
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::Int));
uint64_t vertex_generator_cnt = dv.ValueInt();
db->storage().VertexGenerator().SetId(std::max(
db->storage().VertexGenerator().LocalCount(), vertex_generator_cnt));
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::Int));
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::Int));
uint64_t edge_generator_cnt = dv.ValueInt();
db->storage().EdgeGenerator().SetId(
std::max(db->storage().EdgeGenerator().LocalCount(), edge_generator_cnt));
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::Int));
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::Int));
recovery_data->snapshooter_tx_id = dv.ValueInt();
// Transaction snapshot of the transaction that created the snapshot.
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::List));
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::List));
for (const auto &value : dv.ValueList()) {
RETURN_IF_NOT(value.IsInt());
recovery_data->snapshooter_tx_snapshot.emplace_back(value.ValueInt());
}
// A list of label+property indexes.
RETURN_IF_NOT(decoder.ReadValue(&dv, DecodedValue::Type::List));
RETURN_IF_NOT(decoder.ReadValue(&dv, Value::Type::List));
auto index_value = dv.ValueList();
for (auto it = index_value.begin(); it != index_value.end();) {
auto label = *it++;
@ -155,16 +155,16 @@ bool RecoverSnapshot(const fs::path &snapshot_file, database::GraphDb *db,
}
};
DecodedValue dv_cypher_id;
Value dv_cypher_id;
for (int64_t i = 0; i < edge_count; ++i) {
RETURN_IF_NOT(
decoder.ReadValue(&dv, communication::bolt::DecodedValue::Type::Edge));
decoder.ReadValue(&dv, communication::bolt::Value::Type::Edge));
auto &edge = dv.ValueEdge();
// Read cypher_id
RETURN_IF_NOT(decoder.ReadValue(
&dv_cypher_id, communication::bolt::DecodedValue::Type::Int));
RETURN_IF_NOT(decoder.ReadValue(&dv_cypher_id,
communication::bolt::Value::Type::Int));
auto cypher_id = dv_cypher_id.ValueInt();
// We have to take full edge endpoints from vertices since the endpoints

View File

@ -46,7 +46,7 @@ bool Encode(const fs::path &snapshot_file, database::GraphDb &db,
// Write the transaction snapshot into the snapshot. It's used when
// recovering from the combination of snapshot and write-ahead-log.
{
std::vector<communication::bolt::DecodedValue> tx_snapshot;
std::vector<communication::bolt::Value> tx_snapshot;
for (int64_t tx : dba.transaction().snapshot())
tx_snapshot.emplace_back(tx);
encoder.WriteList(tx_snapshot);
@ -54,7 +54,7 @@ bool Encode(const fs::path &snapshot_file, database::GraphDb &db,
// Write label+property indexes as list ["label", "property", ...]
{
std::vector<communication::bolt::DecodedValue> index_vec;
std::vector<communication::bolt::Value> index_vec;
for (const auto &key : dba.GetIndicesKeys()) {
index_vec.emplace_back(dba.LabelName(key.label_));
index_vec.emplace_back(dba.PropertyName(key.property_));
@ -67,7 +67,7 @@ bool Encode(const fs::path &snapshot_file, database::GraphDb &db,
vertex_num++;
}
for (const auto &edge : dba.Edges(false)) {
encoder.WriteEdge(glue::ToDecodedEdge(edge));
encoder.WriteEdge(glue::ToBoltEdge(edge));
encoder.WriteInt(edge.cypher_id());
edge_num++;
}

View File

@ -3,7 +3,7 @@
#include <experimental/optional>
#include "communication/bolt/v1/decoder/decoder.hpp"
#include "durability/snapshot_decoded_value.hpp"
#include "durability/snapshot_value.hpp"
namespace durability {
@ -13,13 +13,13 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
explicit SnapshotDecoder(Buffer &buffer)
: communication::bolt::Decoder<Buffer>(buffer) {}
std::experimental::optional<DecodedSnapshotVertex> ReadSnapshotVertex() {
communication::bolt::DecodedValue dv;
DecodedSnapshotVertex vertex;
std::experimental::optional<SnapshotVertex> ReadSnapshotVertex() {
communication::bolt::Value dv;
SnapshotVertex vertex;
// Read global id, labels and properties of the vertex
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Vertex)) {
&dv, communication::bolt::Value::Type::Vertex)) {
DLOG(WARNING) << "Unable to read snapshot vertex";
return std::experimental::nullopt;
}
@ -30,7 +30,7 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
// Read cypher_id
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Int)) {
&dv, communication::bolt::Value::Type::Int)) {
DLOG(WARNING) << "Unable to read vertex cypher_id";
return std::experimental::nullopt;
}
@ -38,7 +38,7 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
// Read in edges
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Int)) {
&dv, communication::bolt::Value::Type::Int)) {
DLOG(WARNING) << "[ReadSnapshotVertex] Couldn't read number of in "
"edges in vertex!";
return std::experimental::nullopt;
@ -51,7 +51,7 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
// Read out edges
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Int)) {
&dv, communication::bolt::Value::Type::Int)) {
DLOG(WARNING) << "[ReadSnapshotVertex] Couldn't read number of out "
"edges in vertex!";
return std::experimental::nullopt;
@ -67,15 +67,15 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
}
private:
std::experimental::optional<DecodedInlinedVertexEdge> ReadSnapshotEdge() {
communication::bolt::DecodedValue dv;
DecodedInlinedVertexEdge edge;
std::experimental::optional<InlinedVertexEdge> ReadSnapshotEdge() {
communication::bolt::Value dv;
InlinedVertexEdge edge;
VLOG(20) << "[ReadSnapshotEdge] Start";
// Read global id of this edge
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Int)) {
&dv, communication::bolt::Value::Type::Int)) {
DLOG(WARNING) << "[ReadSnapshotEdge] Couldn't read Global ID!";
return std::experimental::nullopt;
}
@ -84,7 +84,7 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
// Read global vertex id of the other side of the edge
// (global id of from/to vertexes).
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::Int)) {
&dv, communication::bolt::Value::Type::Int)) {
DLOG(WARNING) << "[ReadSnapshotEdge] Couldn't read from/to address!";
return std::experimental::nullopt;
}
@ -92,7 +92,7 @@ class SnapshotDecoder : public communication::bolt::Decoder<Buffer> {
// Read edge type
if (!communication::bolt::Decoder<Buffer>::ReadValue(
&dv, communication::bolt::DecodedValue::Type::String)) {
&dv, communication::bolt::Value::Type::String)) {
DLOG(WARNING) << "[ReadSnapshotEdge] Couldn't read type!";
return std::experimental::nullopt;
}

View File

@ -14,7 +14,7 @@ class SnapshotEncoder : public communication::bolt::BaseEncoder<Buffer> {
: communication::bolt::BaseEncoder<Buffer>(buffer) {}
void WriteSnapshotVertex(const VertexAccessor &vertex) {
communication::bolt::BaseEncoder<Buffer>::WriteVertex(
glue::ToDecodedVertex(vertex));
glue::ToBoltVertex(vertex));
// Write cypher_id
this->WriteInt(vertex.cypher_id());

View File

@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "query/typed_value.hpp"
#include "storage/address_types.hpp"
#include "storage/property_value.hpp"
@ -13,28 +13,28 @@
namespace durability {
/** Forward declartion of DecodedSnapshotEdge. */
struct DecodedInlinedVertexEdge;
/** Forward declartion of SnapshotEdge. */
struct InlinedVertexEdge;
/**
* Structure used when reading a Vertex with the decoder.
* The decoder writes data into this structure.
*/
struct DecodedSnapshotVertex {
struct SnapshotVertex {
gid::Gid gid;
int64_t cypher_id;
std::vector<std::string> labels;
std::map<std::string, communication::bolt::DecodedValue> properties;
std::map<std::string, communication::bolt::Value> properties;
// Vector of edges without properties
std::vector<DecodedInlinedVertexEdge> in;
std::vector<DecodedInlinedVertexEdge> out;
std::vector<InlinedVertexEdge> in;
std::vector<InlinedVertexEdge> out;
};
/**
* Structure used when reading an Edge with the snapshot decoder.
* The decoder writes data into this structure.
*/
struct DecodedInlinedVertexEdge {
struct InlinedVertexEdge {
// Addresses down below must always be global_address and never direct
// pointers to a record.
storage::EdgeAddress address;

View File

@ -6,185 +6,184 @@
#include "database/graph_db_accessor.hpp"
using communication::bolt::DecodedValue;
using communication::bolt::Value;
namespace glue {
query::TypedValue ToTypedValue(const DecodedValue &value) {
query::TypedValue ToTypedValue(const Value &value) {
switch (value.type()) {
case DecodedValue::Type::Null:
case Value::Type::Null:
return query::TypedValue::Null;
case DecodedValue::Type::Bool:
case Value::Type::Bool:
return query::TypedValue(value.ValueBool());
case DecodedValue::Type::Int:
case Value::Type::Int:
return query::TypedValue(value.ValueInt());
case DecodedValue::Type::Double:
case Value::Type::Double:
return query::TypedValue(value.ValueDouble());
case DecodedValue::Type::String:
case Value::Type::String:
return query::TypedValue(value.ValueString());
case DecodedValue::Type::List: {
case Value::Type::List: {
std::vector<query::TypedValue> list;
list.reserve(value.ValueList().size());
for (const auto &v : value.ValueList()) list.push_back(ToTypedValue(v));
return query::TypedValue(list);
}
case DecodedValue::Type::Map: {
case Value::Type::Map: {
std::map<std::string, query::TypedValue> map;
for (const auto &kv : value.ValueMap())
map.emplace(kv.first, ToTypedValue(kv.second));
return query::TypedValue(map);
}
case DecodedValue::Type::Vertex:
case DecodedValue::Type::Edge:
case DecodedValue::Type::UnboundedEdge:
case DecodedValue::Type::Path:
throw communication::bolt::DecodedValueException(
"Unsupported conversion from DecodedValue to TypedValue");
case Value::Type::Vertex:
case Value::Type::Edge:
case Value::Type::UnboundedEdge:
case Value::Type::Path:
throw communication::bolt::ValueException(
"Unsupported conversion from Value to TypedValue");
}
}
DecodedValue ToDecodedValue(const query::TypedValue &value) {
Value ToBoltValue(const query::TypedValue &value) {
switch (value.type()) {
case query::TypedValue::Type::Null:
return DecodedValue();
return Value();
case query::TypedValue::Type::Bool:
return DecodedValue(value.ValueBool());
return Value(value.ValueBool());
case query::TypedValue::Type::Int:
return DecodedValue(value.ValueInt());
return Value(value.ValueInt());
case query::TypedValue::Type::Double:
return DecodedValue(value.ValueDouble());
return Value(value.ValueDouble());
case query::TypedValue::Type::String:
return DecodedValue(value.ValueString());
return Value(value.ValueString());
case query::TypedValue::Type::List: {
std::vector<DecodedValue> values;
std::vector<Value> values;
values.reserve(value.ValueList().size());
for (const auto &v : value.ValueList()) {
values.push_back(ToDecodedValue(v));
values.push_back(ToBoltValue(v));
}
return DecodedValue(values);
return Value(values);
}
case query::TypedValue::Type::Map: {
std::map<std::string, DecodedValue> map;
std::map<std::string, Value> map;
for (const auto &kv : value.ValueMap()) {
map.emplace(kv.first, ToDecodedValue(kv.second));
map.emplace(kv.first, ToBoltValue(kv.second));
}
return DecodedValue(map);
return Value(map);
}
case query::TypedValue::Type::Vertex:
return DecodedValue(ToDecodedVertex(value.ValueVertex()));
return Value(ToBoltVertex(value.ValueVertex()));
case query::TypedValue::Type::Edge:
return DecodedValue(ToDecodedEdge(value.ValueEdge()));
return Value(ToBoltEdge(value.ValueEdge()));
case query::TypedValue::Type::Path:
return DecodedValue(ToDecodedPath(value.ValuePath()));
return Value(ToBoltPath(value.ValuePath()));
}
}
communication::bolt::DecodedVertex ToDecodedVertex(
const VertexAccessor &vertex) {
communication::bolt::Vertex ToBoltVertex(const VertexAccessor &vertex) {
auto id = communication::bolt::Id::FromUint(vertex.gid());
std::vector<std::string> labels;
labels.reserve(vertex.labels().size());
for (const auto &label : vertex.labels()) {
labels.push_back(vertex.db_accessor().LabelName(label));
}
std::map<std::string, DecodedValue> properties;
std::map<std::string, Value> properties;
for (const auto &prop : vertex.Properties()) {
properties[vertex.db_accessor().PropertyName(prop.first)] =
ToDecodedValue(prop.second);
ToBoltValue(prop.second);
}
return communication::bolt::DecodedVertex{id, labels, properties};
return communication::bolt::Vertex{id, labels, properties};
}
communication::bolt::DecodedEdge ToDecodedEdge(const EdgeAccessor &edge) {
communication::bolt::Edge ToBoltEdge(const EdgeAccessor &edge) {
auto id = communication::bolt::Id::FromUint(edge.gid());
auto from = communication::bolt::Id::FromUint(edge.from().gid());
auto to = communication::bolt::Id::FromUint(edge.to().gid());
auto type = edge.db_accessor().EdgeTypeName(edge.EdgeType());
std::map<std::string, DecodedValue> properties;
std::map<std::string, Value> properties;
for (const auto &prop : edge.Properties()) {
properties[edge.db_accessor().PropertyName(prop.first)] =
ToDecodedValue(prop.second);
ToBoltValue(prop.second);
}
return communication::bolt::DecodedEdge{id, from, to, type, properties};
return communication::bolt::Edge{id, from, to, type, properties};
}
communication::bolt::DecodedPath ToDecodedPath(const query::Path &path) {
std::vector<communication::bolt::DecodedVertex> vertices;
communication::bolt::Path ToBoltPath(const query::Path &path) {
std::vector<communication::bolt::Vertex> vertices;
vertices.reserve(path.vertices().size());
for (const auto &v : path.vertices()) {
vertices.push_back(ToDecodedVertex(v));
vertices.push_back(ToBoltVertex(v));
}
std::vector<communication::bolt::DecodedEdge> edges;
std::vector<communication::bolt::Edge> edges;
edges.reserve(path.edges().size());
for (const auto &e : path.edges()) {
edges.push_back(ToDecodedEdge(e));
edges.push_back(ToBoltEdge(e));
}
return communication::bolt::DecodedPath(vertices, edges);
return communication::bolt::Path(vertices, edges);
}
PropertyValue ToPropertyValue(const DecodedValue &value) {
PropertyValue ToPropertyValue(const Value &value) {
switch (value.type()) {
case DecodedValue::Type::Null:
case Value::Type::Null:
return PropertyValue::Null;
case DecodedValue::Type::Bool:
case Value::Type::Bool:
return PropertyValue(value.ValueBool());
case DecodedValue::Type::Int:
case Value::Type::Int:
return PropertyValue(value.ValueInt());
case DecodedValue::Type::Double:
case Value::Type::Double:
return PropertyValue(value.ValueDouble());
case DecodedValue::Type::String:
case Value::Type::String:
return PropertyValue(value.ValueString());
case DecodedValue::Type::List: {
case Value::Type::List: {
std::vector<PropertyValue> vec;
vec.reserve(value.ValueList().size());
for (const auto &value : value.ValueList())
vec.emplace_back(ToPropertyValue(value));
return PropertyValue(std::move(vec));
}
case DecodedValue::Type::Map: {
case Value::Type::Map: {
std::map<std::string, PropertyValue> map;
for (const auto &kv : value.ValueMap())
map.emplace(kv.first, ToPropertyValue(kv.second));
return PropertyValue(std::move(map));
}
case DecodedValue::Type::Vertex:
case DecodedValue::Type::Edge:
case DecodedValue::Type::UnboundedEdge:
case DecodedValue::Type::Path:
throw communication::bolt::DecodedValueException(
"Unsupported conversion from DecodedValue to PropertyValue");
case Value::Type::Vertex:
case Value::Type::Edge:
case Value::Type::UnboundedEdge:
case Value::Type::Path:
throw communication::bolt::ValueException(
"Unsupported conversion from Value to PropertyValue");
}
}
DecodedValue ToDecodedValue(const PropertyValue &value) {
Value ToBoltValue(const PropertyValue &value) {
switch (value.type()) {
case PropertyValue::Type::Null:
return DecodedValue();
return Value();
case PropertyValue::Type::Bool:
return DecodedValue(value.Value<bool>());
return Value(value.Value<bool>());
case PropertyValue::Type::Int:
return DecodedValue(value.Value<int64_t>());
return Value(value.Value<int64_t>());
break;
case PropertyValue::Type::Double:
return DecodedValue(value.Value<double>());
return Value(value.Value<double>());
case PropertyValue::Type::String:
return DecodedValue(value.Value<std::string>());
return Value(value.Value<std::string>());
case PropertyValue::Type::List: {
const auto &values = value.Value<std::vector<PropertyValue>>();
std::vector<DecodedValue> vec;
std::vector<Value> vec;
vec.reserve(values.size());
for (const auto &v : values) {
vec.push_back(ToDecodedValue(v));
vec.push_back(ToBoltValue(v));
}
return DecodedValue(vec);
return Value(vec);
}
case PropertyValue::Type::Map: {
const auto &map = value.Value<std::map<std::string, PropertyValue>>();
std::map<std::string, DecodedValue> dv_map;
std::map<std::string, Value> dv_map;
for (const auto &kv : map) {
dv_map.emplace(kv.first, ToDecodedValue(kv.second));
dv_map.emplace(kv.first, ToBoltValue(kv.second));
}
return DecodedValue(dv_map);
return Value(dv_map);
}
}
}

View File

@ -1,26 +1,24 @@
/// @file Conversion functions between DecodedValue and other memgraph types.
/// @file Conversion functions between Value and other memgraph types.
#pragma once
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "query/typed_value.hpp"
#include "storage/property_value.hpp"
namespace glue {
communication::bolt::DecodedVertex ToDecodedVertex(
const VertexAccessor &vertex);
communication::bolt::Vertex ToBoltVertex(const VertexAccessor &vertex);
communication::bolt::DecodedEdge ToDecodedEdge(const EdgeAccessor &edge);
communication::bolt::Edge ToBoltEdge(const EdgeAccessor &edge);
communication::bolt::DecodedPath ToDecodedPath(const query::Path &path);
communication::bolt::Path ToBoltPath(const query::Path &path);
communication::bolt::DecodedValue ToDecodedValue(
const query::TypedValue &value);
communication::bolt::Value ToBoltValue(const query::TypedValue &value);
query::TypedValue ToTypedValue(const communication::bolt::DecodedValue &value);
query::TypedValue ToTypedValue(const communication::bolt::Value &value);
communication::bolt::DecodedValue ToDecodedValue(const PropertyValue &value);
communication::bolt::Value ToBoltValue(const PropertyValue &value);
PropertyValue ToPropertyValue(const communication::bolt::DecodedValue &value);
PropertyValue ToPropertyValue(const communication::bolt::Value &value);
} // namespace glue

View File

@ -85,7 +85,7 @@ class BoltSession final
std::vector<std::string> Interpret(
const std::string &query,
const std::map<std::string, communication::bolt::DecodedValue> &params)
const std::map<std::string, communication::bolt::Value> &params)
override {
std::map<std::string, query::TypedValue> params_tv;
for (const auto &kv : params)
@ -99,14 +99,14 @@ class BoltSession final
}
}
std::map<std::string, communication::bolt::DecodedValue> PullAll(
std::map<std::string, communication::bolt::Value> PullAll(
TEncoder *encoder) override {
try {
TypedValueResultStream stream(encoder);
const auto &summary = transaction_engine_.PullAll(&stream);
std::map<std::string, communication::bolt::DecodedValue> decoded_summary;
std::map<std::string, communication::bolt::Value> decoded_summary;
for (const auto &kv : summary) {
decoded_summary.emplace(kv.first, glue::ToDecodedValue(kv.second));
decoded_summary.emplace(kv.first, glue::ToBoltValue(kv.second));
}
return decoded_summary;
} catch (const query::QueryException &e) {
@ -119,17 +119,17 @@ class BoltSession final
void Abort() override { transaction_engine_.Abort(); }
private:
// Wrapper around TEncoder which converts TypedValue to DecodedValue
// Wrapper around TEncoder which converts TypedValue to Value
// before forwarding the calls to original TEncoder.
class TypedValueResultStream {
public:
TypedValueResultStream(TEncoder *encoder) : encoder_(encoder) {}
void Result(const std::vector<query::TypedValue> &values) {
std::vector<communication::bolt::DecodedValue> decoded_values;
std::vector<communication::bolt::Value> decoded_values;
decoded_values.reserve(values.size());
for (const auto &v : values) {
decoded_values.push_back(glue::ToDecodedValue(v));
decoded_values.push_back(glue::ToBoltValue(v));
}
encoder_->MessageRecord(decoded_values);
}

View File

@ -214,7 +214,7 @@ PropertyValueStore::iterator PropertyValueStore::end() const {
std::string PropertyValueStore::SerializeProp(const PropertyValue &prop) const {
storage::PODBuffer pod_buffer;
BaseEncoder<storage::PODBuffer> encoder{pod_buffer};
encoder.WriteDecodedValue(glue::ToDecodedValue(prop));
encoder.WriteValue(glue::ToBoltValue(prop));
return std::string(reinterpret_cast<char *>(pod_buffer.buffer.data()),
pod_buffer.buffer.size());
}
@ -224,7 +224,7 @@ PropertyValue PropertyValueStore::DeserializeProp(
storage::PODBuffer pod_buffer{serialized_prop};
communication::bolt::Decoder<storage::PODBuffer> decoder{pod_buffer};
DecodedValue dv;
Value dv;
if (!decoder.ReadValue(&dv)) {
DLOG(WARNING) << "Unable to read property value";
return PropertyValue::Null;

View File

@ -6,14 +6,14 @@
#include <glog/logging.h>
#include "communication/bolt/client.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "io/network/endpoint.hpp"
using EndpointT = io::network::Endpoint;
using ContextT = communication::ClientContext;
using ClientT = communication::bolt::Client;
using QueryDataT = communication::bolt::QueryData;
using communication::bolt::DecodedValue;
using communication::bolt::Value;
class BoltClient {
public:
@ -29,7 +29,7 @@ class BoltClient {
}
QueryDataT Execute(const std::string &query,
const std::map<std::string, DecodedValue> &parameters) {
const std::map<std::string, Value> &parameters) {
return client_.Execute(query, parameters);
}

View File

@ -7,7 +7,7 @@
#include <string>
#include "communication/bolt/client.hpp"
#include "communication/bolt/v1/decoder/decoded_value.hpp"
#include "communication/bolt/v1/value.hpp"
#include "utils/algorithm.hpp"
#include "utils/exceptions.hpp"
#include "utils/thread/sync.hpp"
@ -15,41 +15,41 @@
using communication::ClientContext;
using communication::bolt::Client;
using communication::bolt::DecodedValue;
using communication::bolt::Value;
using io::network::Endpoint;
void PrintJsonDecodedValue(std::ostream &os, const DecodedValue &value) {
void PrintJsonValue(std::ostream &os, const Value &value) {
switch (value.type()) {
case DecodedValue::Type::Null:
case Value::Type::Null:
os << "null";
break;
case DecodedValue::Type::Bool:
case Value::Type::Bool:
os << (value.ValueBool() ? "true" : "false");
break;
case DecodedValue::Type::Int:
case Value::Type::Int:
os << value.ValueInt();
break;
case DecodedValue::Type::Double:
case Value::Type::Double:
os << value.ValueDouble();
break;
case DecodedValue::Type::String:
case Value::Type::String:
os << "\"" << value.ValueString() << "\"";
break;
case DecodedValue::Type::List:
case Value::Type::List:
os << "[";
utils::PrintIterable(os, value.ValueList(), ", ",
[](auto &stream, const auto &item) {
PrintJsonDecodedValue(stream, item);
PrintJsonValue(stream, item);
});
os << "]";
break;
case DecodedValue::Type::Map:
case Value::Type::Map:
os << "{";
utils::PrintIterable(os, value.ValueMap(), ", ",
[](auto &stream, const auto &pair) {
PrintJsonDecodedValue(stream, {pair.first});
PrintJsonValue(stream, {pair.first});
stream << ": ";
PrintJsonDecodedValue(stream, pair.second);
PrintJsonValue(stream, pair.second);
});
os << "}";
break;
@ -60,7 +60,7 @@ void PrintJsonDecodedValue(std::ostream &os, const DecodedValue &value) {
std::pair<communication::bolt::QueryData, int> ExecuteNTimesTillSuccess(
Client &client, const std::string &query,
const std::map<std::string, communication::bolt::DecodedValue> &params,
const std::map<std::string, communication::bolt::Value> &params,
int max_attempts) {
static thread_local std::mt19937 pseudo_rand_gen_{std::random_device{}()};
static thread_local std::uniform_int_distribution<> rand_dist_{10, 50};

View File

@ -72,8 +72,7 @@ class TestClient {
virtual void Step() = 0;
std::experimental::optional<communication::bolt::QueryData> Execute(
const std::string &query,
const std::map<std::string, DecodedValue> &params,
const std::string &query, const std::map<std::string, Value> &params,
const std::string &query_name = "") {
communication::bolt::QueryData result;
int retries;
@ -102,8 +101,7 @@ class TestClient {
}
utils::SpinLock lock_;
std::unordered_map<std::string,
std::vector<std::map<std::string, DecodedValue>>>
std::unordered_map<std::string, std::vector<std::map<std::string, Value>>>
stats_;
std::atomic<bool> keep_running_{true};
@ -134,12 +132,11 @@ void RunMultithreadedTest(std::vector<std::unique_ptr<TestClient>> &clients) {
}
LOG(INFO) << "Starting test with " << clients.size() << " workers";
while (timer.Elapsed().count() < FLAGS_duration) {
std::unordered_map<std::string, std::map<std::string, DecodedValue>>
std::unordered_map<std::string, std::map<std::string, Value>>
aggregated_stats;
using namespace std::chrono_literals;
std::unordered_map<std::string,
std::vector<std::map<std::string, DecodedValue>>>
std::unordered_map<std::string, std::vector<std::map<std::string, Value>>>
stats;
for (const auto &client : clients) {
auto client_stats = client->ConsumeStats();
@ -150,9 +147,9 @@ void RunMultithreadedTest(std::vector<std::unique_ptr<TestClient>> &clients) {
}
}
// TODO: Here we combine pure values, json and DecodedValue which is a
// TODO: Here we combine pure values, json and Value which is a
// little bit chaotic. Think about refactoring this part to only use json
// and write DecodedValue to json converter.
// and write Value to json converter.
const std::vector<std::string> fields = {
"wall_time",
"parsing_time",
@ -172,12 +169,11 @@ void RunMultithreadedTest(std::vector<std::unique_ptr<TestClient>> &clients) {
int64_t new_count = query_stats.second.size();
auto &aggregated_query_stats = aggregated_stats[query_stats.first];
aggregated_query_stats.insert({"count", DecodedValue(0)});
aggregated_query_stats.insert({"count", Value(0)});
auto old_count = aggregated_query_stats["count"].ValueInt();
aggregated_query_stats["count"].ValueInt() += new_count;
for (const auto &stat : new_aggregated_query_stats) {
auto it = aggregated_query_stats.insert({stat.first, DecodedValue(0.0)})
.first;
auto it = aggregated_query_stats.insert({stat.first, Value(0.0)}).first;
it->second = (it->second.ValueDouble() * old_count + stat.second) /
(old_count + new_count);
stats::LogStat(
@ -195,7 +191,7 @@ void RunMultithreadedTest(std::vector<std::unique_ptr<TestClient>> &clients) {
out, aggregated_stats, ", ", [](auto &stream, const auto &x) {
stream << "{\"query\": " << nlohmann::json(x.first)
<< ", \"stats\": ";
PrintJsonDecodedValue(stream, DecodedValue(x.second));
PrintJsonValue(stream, Value(x.second));
stream << "}";
});
out << "]}" << std::endl;

View File

@ -20,14 +20,14 @@
#include "long_running_common.hpp"
using communication::bolt::DecodedEdge;
using communication::bolt::DecodedValue;
using communication::bolt::DecodedVertex;
using communication::bolt::Edge;
using communication::bolt::Value;
using communication::bolt::Vertex;
struct VertexAndEdges {
DecodedVertex vertex;
std::vector<DecodedEdge> edges;
std::vector<DecodedVertex> vertices;
Vertex vertex;
std::vector<Edge> edges;
std::vector<Vertex> vertices;
};
const std::string INDEPENDENT_LABEL = "User";
@ -60,14 +60,14 @@ class PokecClient : public TestClient {
{{"id", id}});
}
auto CreateVertex(const DecodedVertex &vertex) {
auto CreateVertex(const Vertex &vertex) {
std::stringstream os;
os << "CREATE (n :";
utils::PrintIterable(os, vertex.labels, ":");
os << " {";
utils::PrintIterable(
os, vertex.properties, ", ", [&](auto &stream, const auto &pair) {
if (pair.second.type() == DecodedValue::Type::String) {
if (pair.second.type() == Value::Type::String) {
stream << pair.first << ": \"" << pair.second << "\"";
} else {
stream << pair.first << ": " << pair.second;
@ -91,9 +91,9 @@ class PokecClient : public TestClient {
{{"id", id}});
}
auto CreateEdge(const DecodedVertex &from, const std::string &from_label,
auto CreateEdge(const Vertex &from, const std::string &from_label,
int64_t from_id, const std::string &to_label, int64_t to_id,
const DecodedEdge &edge) {
const Edge &edge) {
std::stringstream os;
os << fmt::format("MATCH (n :{} {{id : {}}}) ", from_label, from_id);
os << fmt::format("MATCH (m :{} {{id : {}}}) ", to_label, to_id);
@ -106,7 +106,7 @@ class PokecClient : public TestClient {
os << "[:" << edge.type << " {";
utils::PrintIterable(
os, edge.properties, ", ", [&](auto &stream, const auto &pair) {
if (pair.second.type() == DecodedValue::Type::String) {
if (pair.second.type() == Value::Type::String) {
stream << pair.first << ": \"" << pair.second << "\"";
} else {
stream << pair.first << ": " << pair.second;
@ -141,13 +141,13 @@ class PokecClient : public TestClient {
DetachDeleteVertex(label, id);
std::vector<DecodedEdge> edges;
std::vector<Edge> edges;
edges.reserve(records.size());
for (const auto &record : records) {
edges.push_back(record[1].ValueEdge());
}
std::vector<DecodedVertex> vertices;
std::vector<Vertex> vertices;
vertices.reserve(records.size());
for (const auto &record : records) {
vertices.push_back(record[2].ValueVertex());

View File

@ -22,23 +22,22 @@ DEFINE_string(username, "", "Username for the database");
DEFINE_string(password, "", "Password for the database");
DEFINE_bool(use_ssl, false, "Set to true to connect with SSL to the server.");
using communication::bolt::DecodedValue;
using communication::bolt::Value;
const int MAX_RETRIES = 50;
void PrintJsonMetadata(
std::ostream &os,
const std::vector<std::map<std::string, DecodedValue>> &metadata) {
const std::vector<std::map<std::string, Value>> &metadata) {
os << "[";
utils::PrintIterable(os, metadata, ", ", [](auto &stream, const auto &item) {
PrintJsonDecodedValue(stream, item);
PrintJsonValue(stream, item);
});
os << "]";
}
void PrintSummary(
std::ostream &os, double duration,
const std::vector<std::map<std::string, DecodedValue>> &metadata) {
void PrintSummary(std::ostream &os, double duration,
const std::vector<std::map<std::string, Value>> &metadata) {
os << "{\"wall_time\": " << duration << ", "
<< "\"metadatas\": ";
PrintJsonMetadata(os, metadata);
@ -51,7 +50,7 @@ void ExecuteQueries(const std::vector<std::string> &queries,
utils::SpinLock spinlock;
uint64_t last = 0;
std::vector<std::map<std::string, DecodedValue>> metadata;
std::vector<std::map<std::string, Value>> metadata;
metadata.resize(queries.size());

View File

@ -27,12 +27,12 @@ class SnapshotWriter {
: worker_id_(worker_id), buffer_(path) {
encoder_.WriteRAW(durability::kMagicNumber.data(),
durability::kMagicNumber.size());
encoder_.WriteDecodedValue(durability::kVersion);
encoder_.WriteValue(durability::kVersion);
encoder_.WriteInt(worker_id_);
encoder_.WriteInt(vertex_generator_local_count);
encoder_.WriteInt(edge_generator_local_count);
encoder_.WriteInt(0);
encoder_.WriteList(std::vector<communication::bolt::DecodedValue>{});
encoder_.WriteList(std::vector<communication::bolt::Value>{});
}
// reference to `buffer_` gets broken when moving, so let's just forbid moving
@ -41,8 +41,8 @@ class SnapshotWriter {
template <typename TValue>
void WriteList(const std::vector<TValue> &list) {
encoder_.WriteList(std::vector<communication::bolt::DecodedValue>(
list.begin(), list.end()));
encoder_.WriteList(
std::vector<communication::bolt::Value>(list.begin(), list.end()));
}
storage::VertexAddress DefaultVertexAddress(gid::Gid gid) {
@ -69,9 +69,9 @@ class SnapshotWriter {
encoder_.WriteInt(node.gid);
WriteList(node.labels);
std::map<std::string, communication::bolt::DecodedValue> props;
std::map<std::string, communication::bolt::Value> props;
for (const auto &prop : node.props) {
props[prop.first] = glue::ToDecodedValue(prop.second);
props[prop.first] = glue::ToBoltValue(prop.second);
}
encoder_.WriteMap(props);
@ -100,9 +100,9 @@ class SnapshotWriter {
encoder_.WriteInt(edge.from);
encoder_.WriteInt(edge.to);
encoder_.WriteString(edge.type);
std::map<std::string, communication::bolt::DecodedValue> props;
std::map<std::string, communication::bolt::Value> props;
for (const auto &prop : edge.props) {
props[prop.first] = glue::ToDecodedValue(prop.second);
props[prop.first] = glue::ToBoltValue(prop.second);
}
encoder_.WriteMap(props);

View File

@ -15,7 +15,7 @@
using EndpointT = io::network::Endpoint;
using ClientContextT = communication::ClientContext;
using ClientT = communication::bolt::Client;
using DecodedValueT = communication::bolt::DecodedValue;
using ValueT = communication::bolt::Value;
using QueryDataT = communication::bolt::QueryData;
using ExceptionT = communication::bolt::ClientQueryException;
@ -159,7 +159,7 @@ class GraphSession {
}
// remove edge
auto &edge = record[2];
if (edge.type() == DecodedValueT::Type::Int) {
if (edge.type() == ValueT::Type::Int) {
edges_.erase(edge.ValueInt());
}
}

View File

@ -5,7 +5,7 @@
#include "communication/bolt/v1/decoder/decoder.hpp"
using communication::bolt::DecodedValue;
using communication::bolt::Value;
constexpr const int SIZE = 131072;
uint8_t data[SIZE];
@ -43,23 +43,23 @@ using DecoderT = communication::bolt::Decoder<TestDecoderBuffer>;
TEST(BoltDecoder, NullAndBool) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
// test null
buffer.Write((const uint8_t *)"\xC0", 1);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Null);
ASSERT_EQ(dv.type(), Value::Type::Null);
// test true
buffer.Write((const uint8_t *)"\xC3", 1);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Bool);
ASSERT_EQ(dv.type(), Value::Type::Bool);
ASSERT_EQ(dv.ValueBool(), true);
// test false
buffer.Write((const uint8_t *)"\xC2", 1);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Bool);
ASSERT_EQ(dv.type(), Value::Type::Bool);
ASSERT_EQ(dv.ValueBool(), false);
}
@ -67,7 +67,7 @@ TEST(BoltDecoder, Int) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
// test invalid marker
buffer.Clear();
@ -84,7 +84,7 @@ TEST(BoltDecoder, Int) {
buffer.Clear();
buffer.Write(int_encoded[i], int_encoded_len[i]);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Int);
ASSERT_EQ(dv.type(), Value::Type::Int);
ASSERT_EQ(dv.ValueInt(), int_decoded[i]);
}
}
@ -93,7 +93,7 @@ TEST(BoltDecoder, Double) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
for (int i = 0; i < 4; ++i) {
// test missing data
@ -105,7 +105,7 @@ TEST(BoltDecoder, Double) {
buffer.Clear();
buffer.Write(double_encoded[i], 9);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Double);
ASSERT_EQ(dv.type(), Value::Type::Double);
ASSERT_EQ(dv.ValueDouble(), double_decoded[i]);
}
}
@ -114,7 +114,7 @@ TEST(BoltDecoder, String) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
uint8_t headers[][6] = {"\x8F", "\xD0\x0F", "\xD1\x00\x0F",
"\xD2\x00\x00\x00\x0F"};
@ -137,7 +137,7 @@ TEST(BoltDecoder, String) {
buffer.Write(headers[i], headers_len[i]);
buffer.Write(data, 15);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::String);
ASSERT_EQ(dv.type(), Value::Type::String);
std::string &str = dv.ValueString();
for (int j = 0; j < 15; ++j) EXPECT_EQ((uint8_t)str[j], data[j]);
}
@ -146,7 +146,7 @@ TEST(BoltDecoder, String) {
TEST(BoltDecoder, StringLarge) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
uint8_t header[6] = "\xD2\x00\x01\x86\xA0";
@ -161,7 +161,7 @@ TEST(BoltDecoder, StringLarge) {
buffer.Write(header, 5);
buffer.Write(data, 100000);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::String);
ASSERT_EQ(dv.type(), Value::Type::String);
std::string &str = dv.ValueString();
for (int j = 0; j < 100000; ++j) EXPECT_EQ((uint8_t)str[j], data[j]);
}
@ -170,7 +170,7 @@ TEST(BoltDecoder, List) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
uint8_t headers[][6] = {"\x9F", "\xD4\x0F", "\xD5\x00\x0F",
"\xD6\x00\x00\x00\x0F"};
@ -193,8 +193,8 @@ TEST(BoltDecoder, List) {
buffer.Write(headers[i], headers_len[i]);
for (uint8_t j = 0; j < 15; ++j) buffer.Write(&j, 1);
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::List);
std::vector<DecodedValue> &val = dv.ValueList();
ASSERT_EQ(dv.type(), Value::Type::List);
std::vector<Value> &val = dv.ValueList();
ASSERT_EQ(val.size(), 15);
for (int j = 0; j < 15; ++j) EXPECT_EQ(val[j].ValueInt(), j);
}
@ -204,7 +204,7 @@ TEST(BoltDecoder, Map) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
uint8_t headers[][6] = {"\xAF", "\xD8\x0F", "\xD9\x00\x0F",
"\xDA\x00\x00\x00\x0F"};
@ -260,13 +260,13 @@ TEST(BoltDecoder, Map) {
buffer.Write(&j, 1);
}
ASSERT_EQ(decoder.ReadValue(&dv), true);
ASSERT_EQ(dv.type(), DecodedValue::Type::Map);
std::map<std::string, DecodedValue> &val = dv.ValueMap();
ASSERT_EQ(dv.type(), Value::Type::Map);
std::map<std::string, Value> &val = dv.ValueMap();
ASSERT_EQ(val.size(), 15);
for (int j = 0; j < 15; ++j) {
char tmp_chr = 'a' + j;
DecodedValue tmp_dv = val[std::string(1, tmp_chr)];
EXPECT_EQ(tmp_dv.type(), DecodedValue::Type::Int);
Value tmp_dv = val[std::string(1, tmp_chr)];
EXPECT_EQ(tmp_dv.type(), Value::Type::Int);
EXPECT_EQ(tmp_dv.ValueInt(), j);
}
}
@ -276,7 +276,7 @@ TEST(BoltDecoder, Vertex) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue dv;
Value dv;
uint8_t header[] = "\xB3\x4E";
uint8_t wrong_header[] = "\x00\x00";
@ -288,31 +288,31 @@ TEST(BoltDecoder, Vertex) {
// test missing signature
buffer.Clear();
buffer.Write(wrong_header, 1);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test wrong marker
buffer.Clear();
buffer.Write(wrong_header, 2);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test wrong signature
buffer.Clear();
buffer.Write(header, 1);
buffer.Write(wrong_header, 1);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test ID wrong type
buffer.Clear();
buffer.Write(header, 2);
buffer.Write(test_str, 2);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test labels wrong outer type
buffer.Clear();
buffer.Write(header, 2);
buffer.Write(test_int, 1);
buffer.Write(test_int, 1);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test labels wrong inner type
buffer.Clear();
@ -320,7 +320,7 @@ TEST(BoltDecoder, Vertex) {
buffer.Write(test_int, 1);
buffer.Write(test_list, 1);
buffer.Write(test_int, 1);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test properties wrong outer type
buffer.Clear();
@ -328,7 +328,7 @@ TEST(BoltDecoder, Vertex) {
buffer.Write(test_int, 1);
buffer.Write(test_list, 1);
buffer.Write(test_str, 2);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), false);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), false);
// test all ok
buffer.Clear();
@ -339,7 +339,7 @@ TEST(BoltDecoder, Vertex) {
buffer.Write(test_map, 1);
buffer.Write(test_str, 2);
buffer.Write(test_int, 1);
ASSERT_EQ(decoder.ReadValue(&dv, DecodedValue::Type::Vertex), true);
ASSERT_EQ(decoder.ReadValue(&dv, Value::Type::Vertex), true);
auto &vertex = dv.ValueVertex();
ASSERT_EQ(vertex.id.AsUint(), 1);
ASSERT_EQ(vertex.labels[0], std::string("a"));
@ -350,7 +350,7 @@ TEST(BoltDecoder, Edge) {
TestDecoderBuffer buffer;
DecoderT decoder(buffer);
DecodedValue de;
Value de;
uint8_t header[] = "\xB5\x52";
uint8_t wrong_header[] = "\x00\x00";
@ -363,31 +363,31 @@ TEST(BoltDecoder, Edge) {
// test missing signature
buffer.Clear();
buffer.Write(wrong_header, 1);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test wrong marker
buffer.Clear();
buffer.Write(wrong_header, 2);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test wrong signature
buffer.Clear();
buffer.Write(header, 1);
buffer.Write(wrong_header, 1);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test ID wrong type
buffer.Clear();
buffer.Write(header, 2);
buffer.Write(test_str, 2);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test from_id wrong type
buffer.Clear();
buffer.Write(header, 2);
buffer.Write(test_int1, 1);
buffer.Write(test_str, 2);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test to_id wrong type
buffer.Clear();
@ -395,7 +395,7 @@ TEST(BoltDecoder, Edge) {
buffer.Write(test_int1, 1);
buffer.Write(test_int2, 1);
buffer.Write(test_str, 2);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test type wrong type
buffer.Clear();
@ -404,7 +404,7 @@ TEST(BoltDecoder, Edge) {
buffer.Write(test_int2, 1);
buffer.Write(test_int3, 1);
buffer.Write(test_int1, 1);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test properties wrong outer type
buffer.Clear();
@ -414,7 +414,7 @@ TEST(BoltDecoder, Edge) {
buffer.Write(test_int3, 1);
buffer.Write(test_str, 2);
buffer.Write(test_int1, 1);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), false);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), false);
// test all ok
buffer.Clear();
@ -426,7 +426,7 @@ TEST(BoltDecoder, Edge) {
buffer.Write(test_map, 1);
buffer.Write(test_str, 2);
buffer.Write(test_int1, 1);
ASSERT_EQ(decoder.ReadValue(&de, DecodedValue::Type::Edge), true);
ASSERT_EQ(decoder.ReadValue(&de, Value::Type::Edge), true);
auto &edge = de.ValueEdge();
ASSERT_EQ(edge.id.AsUint(), 1);
ASSERT_EQ(edge.from.AsUint(), 2);

View File

@ -6,7 +6,7 @@
#include "database/graph_db_accessor.hpp"
#include "glue/conversion.hpp"
using communication::bolt::DecodedValue;
using communication::bolt::Value;
/**
* TODO (mferencevic): document
@ -65,10 +65,10 @@ std::vector<uint8_t> &output = output_stream.output;
TEST(BoltEncoder, NullAndBool) {
output.clear();
std::vector<DecodedValue> vals;
vals.push_back(DecodedValue());
vals.push_back(DecodedValue(true));
vals.push_back(DecodedValue(false));
std::vector<Value> vals;
vals.push_back(Value());
vals.push_back(Value(true));
vals.push_back(Value(false));
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, 3);
CheckOutput(output, (const uint8_t *)"\xC0\xC3\xC2", 3);
@ -77,8 +77,8 @@ TEST(BoltEncoder, NullAndBool) {
TEST(BoltEncoder, Int) {
int N = 28;
output.clear();
std::vector<DecodedValue> vals;
for (int i = 0; i < N; ++i) vals.push_back(DecodedValue(int_decoded[i]));
std::vector<Value> vals;
for (int i = 0; i < N; ++i) vals.push_back(Value(int_decoded[i]));
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, N);
for (int i = 0; i < N; ++i)
@ -89,8 +89,8 @@ TEST(BoltEncoder, Int) {
TEST(BoltEncoder, Double) {
int N = 4;
output.clear();
std::vector<DecodedValue> vals;
for (int i = 0; i < N; ++i) vals.push_back(DecodedValue(double_decoded[i]));
std::vector<Value> vals;
for (int i = 0; i < N; ++i) vals.push_back(Value(double_decoded[i]));
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, N);
for (int i = 0; i < N; ++i) CheckOutput(output, double_encoded[i], 9, false);
@ -99,9 +99,9 @@ TEST(BoltEncoder, Double) {
TEST(BoltEncoder, String) {
output.clear();
std::vector<DecodedValue> vals;
std::vector<Value> vals;
for (uint64_t i = 0; i < sizes_num; ++i)
vals.push_back(DecodedValue(std::string((const char *)data, sizes[i])));
vals.push_back(Value(std::string((const char *)data, sizes[i])));
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, vals.size());
for (uint64_t i = 0; i < sizes_num; ++i) {
@ -113,12 +113,12 @@ TEST(BoltEncoder, String) {
TEST(BoltEncoder, List) {
output.clear();
std::vector<DecodedValue> vals;
std::vector<Value> vals;
for (uint64_t i = 0; i < sizes_num; ++i) {
std::vector<DecodedValue> val;
std::vector<Value> val;
for (uint64_t j = 0; j < sizes[i]; ++j)
val.push_back(DecodedValue(std::string((const char *)&data[j], 1)));
vals.push_back(DecodedValue(val));
val.push_back(Value(std::string((const char *)&data[j], 1)));
vals.push_back(Value(val));
}
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, vals.size());
@ -134,16 +134,16 @@ TEST(BoltEncoder, List) {
TEST(BoltEncoder, Map) {
output.clear();
std::vector<DecodedValue> vals;
std::vector<Value> vals;
uint8_t buff[10];
for (int i = 0; i < sizes_num; ++i) {
std::map<std::string, DecodedValue> val;
std::map<std::string, Value> val;
for (int j = 0; j < sizes[i]; ++j) {
sprintf((char *)buff, "%05X", j);
std::string tmp((char *)buff, 5);
val.insert(std::make_pair(tmp, DecodedValue(tmp)));
val.insert(std::make_pair(tmp, Value(tmp)));
}
vals.push_back(DecodedValue(val));
vals.push_back(Value(val));
}
bolt_encoder.MessageRecord(vals);
CheckRecordHeader(output, vals.size());
@ -188,10 +188,10 @@ TEST(BoltEncoder, VertexAndEdge) {
ea.PropsSet(p4, pv4);
// check everything
std::vector<DecodedValue> vals;
vals.push_back(glue::ToDecodedValue(va1));
vals.push_back(glue::ToDecodedValue(va2));
vals.push_back(glue::ToDecodedValue(ea));
std::vector<Value> vals;
vals.push_back(glue::ToBoltValue(va1));
vals.push_back(glue::ToBoltValue(va2));
vals.push_back(glue::ToBoltValue(ea));
bolt_encoder.MessageRecord(vals);
// The vertexedge_encoded testdata has hardcoded zeros for IDs,
@ -214,18 +214,18 @@ TEST(BoltEncoder, BoltV1ExampleMessages) {
output.clear();
// record message
std::vector<DecodedValue> rvals;
for (int i = 1; i < 4; ++i) rvals.push_back(DecodedValue(i));
std::vector<Value> rvals;
for (int i = 1; i < 4; ++i) rvals.push_back(Value(i));
bolt_encoder.MessageRecord(rvals);
CheckOutput(output, (const uint8_t *)"\xB1\x71\x93\x01\x02\x03", 6);
// success message
std::string sv1("name"), sv2("age"), sk("fields");
std::vector<DecodedValue> svec;
svec.push_back(DecodedValue(sv1));
svec.push_back(DecodedValue(sv2));
DecodedValue slist(svec);
std::map<std::string, DecodedValue> svals;
std::vector<Value> svec;
svec.push_back(Value(sv1));
svec.push_back(Value(sv2));
Value slist(svec);
std::map<std::string, Value> svals;
svals.insert(std::make_pair(sk, slist));
bolt_encoder.MessageSuccess(svals);
CheckOutput(output,
@ -236,8 +236,8 @@ TEST(BoltEncoder, BoltV1ExampleMessages) {
std::string fv1("Neo.ClientError.Statement.SyntaxError"),
fv2("Invalid syntax.");
std::string fk1("code"), fk2("message");
DecodedValue ftv1(fv1), ftv2(fv2);
std::map<std::string, DecodedValue> fvals;
Value ftv1(fv1), ftv2(fv2);
std::map<std::string, Value> fvals;
fvals.insert(std::make_pair(fk1, ftv1));
fvals.insert(std::make_pair(fk2, ftv2));
bolt_encoder.MessageFailure(fvals);

View File

@ -5,10 +5,10 @@
#include "communication/bolt/v1/session.hpp"
using communication::bolt::ClientError;
using communication::bolt::DecodedValue;
using communication::bolt::Session;
using communication::bolt::SessionException;
using communication::bolt::State;
using communication::bolt::Value;
static const char *kInvalidQuery = "invalid query";
static const char *kQueryReturn42 = "RETURN 42";
@ -27,7 +27,7 @@ class TestSession : public Session<TestInputStream, TestOutputStream> {
std::vector<std::string> Interpret(
const std::string &query,
const std::map<std::string, DecodedValue> &params) override {
const std::map<std::string, Value> &params) override {
if (query == kQueryReturn42 || query == kQueryEmpty) {
query_ = query;
return {"result_name"};
@ -37,10 +37,9 @@ class TestSession : public Session<TestInputStream, TestOutputStream> {
}
}
std::map<std::string, DecodedValue> PullAll(
TEncoder *encoder) override {
std::map<std::string, Value> PullAll(TEncoder *encoder) override {
if (query_ == kQueryReturn42) {
encoder->MessageRecord(std::vector<DecodedValue>{42});
encoder->MessageRecord(std::vector<Value>{42});
return {};
} else if (query_ == kQueryEmpty) {
return {};

View File

@ -433,7 +433,7 @@ TEST_F(Durability, SnapshotEncoding) {
buffer.Read(magic_number.data(), magic_number.size());
ASSERT_EQ(magic_number, durability::kMagicNumber);
communication::bolt::DecodedValue dv;
communication::bolt::Value dv;
decoder.ReadValue(&dv);
ASSERT_EQ(dv.ValueInt(), durability::kVersion);
// Worker id
@ -457,7 +457,7 @@ TEST_F(Durability, SnapshotEncoding) {
EXPECT_EQ(dv.ValueList()[0].ValueString(), "l1");
EXPECT_EQ(dv.ValueList()[1].ValueString(), "p1");
std::map<gid::Gid, durability::DecodedSnapshotVertex> decoded_vertices;
std::map<gid::Gid, durability::SnapshotVertex> decoded_vertices;
// Decode vertices.
for (int i = 0; i < vertex_count; ++i) {
@ -475,17 +475,17 @@ TEST_F(Durability, SnapshotEncoding) {
EXPECT_EQ(decoded_vertices[gid2].labels.size(), 0);
EXPECT_EQ(decoded_vertices[gid2].properties.size(), 2);
std::map<gid::Gid, communication::bolt::DecodedEdge> decoded_edges;
std::map<gid::Gid, communication::bolt::Edge> decoded_edges;
// Decode edges.
for (int i = 0; i < edge_count; ++i) {
decoder.ReadValue(&dv);
ASSERT_EQ(dv.type(), communication::bolt::DecodedValue::Type::Edge);
ASSERT_EQ(dv.type(), communication::bolt::Value::Type::Edge);
auto &edge = dv.ValueEdge();
decoded_edges.emplace(edge.id.AsUint(), edge);
// Read cypher_id.
decoder.ReadValue(&dv);
ASSERT_EQ(dv.type(), communication::bolt::DecodedValue::Type::Int);
ASSERT_EQ(dv.type(), communication::bolt::Value::Type::Int);
}
EXPECT_EQ(decoded_edges.size(), 2);
EXPECT_EQ(decoded_edges[gid0].from.AsUint(), gid0);

View File

@ -13,7 +13,7 @@
#include "durability/hashed_file_writer.hpp"
#include "durability/paths.hpp"
#include "durability/snapshooter.hpp"
#include "durability/snapshot_decoded_value.hpp"
#include "durability/snapshot_value.hpp"
#include "durability/snapshot_encoder.hpp"
#include "durability/version.hpp"
#include "storage/address_types.hpp"
@ -176,12 +176,12 @@ std::vector<Field> ReadHeader(std::istream &stream) {
return fields;
}
communication::bolt::DecodedValue StringToDecodedValue(
communication::bolt::Value StringToValue(
const std::string &str, const std::string &type) {
// Empty string signifies Null.
if (str.empty()) return communication::bolt::DecodedValue();
if (str.empty()) return communication::bolt::Value();
auto convert = [](const auto &str,
const auto &type) -> communication::bolt::DecodedValue {
const auto &type) -> communication::bolt::Value {
if (type == "int" || type == "long" || type == "byte" || type == "short") {
std::istringstream ss(str);
int64_t val;
@ -195,14 +195,14 @@ communication::bolt::DecodedValue StringToDecodedValue(
return str;
}
LOG(FATAL) << "Unexpected type: " << type;
return communication::bolt::DecodedValue();
return communication::bolt::Value();
};
// Type *not* ending with '[]', signifies regular value.
if (!utils::EndsWith(type, "[]")) return convert(str, type);
// Otherwise, we have an array type.
auto elem_type = type.substr(0, type.size() - 2);
auto elems = utils::Split(str, FLAGS_array_delimiter);
std::vector<communication::bolt::DecodedValue> array;
std::vector<communication::bolt::Value> array;
array.reserve(elems.size());
for (const auto &elem : elems) {
array.push_back(convert(utils::Trim(elem), elem_type));
@ -217,13 +217,13 @@ std::string GetIdSpace(const std::string &type) {
}
void WriteNodeRow(
std::unordered_map<gid::Gid, durability::DecodedSnapshotVertex>
std::unordered_map<gid::Gid, durability::SnapshotVertex>
&partial_vertices,
const std::vector<Field> &fields, const std::vector<std::string> &row,
MemgraphNodeIdMap &node_id_map) {
std::experimental::optional<gid::Gid> id;
std::vector<std::string> labels;
std::map<std::string, communication::bolt::DecodedValue> properties;
std::map<std::string, communication::bolt::Value> properties;
for (int i = 0; i < row.size(); ++i) {
const auto &field = fields[i];
auto value = utils::Trim(row[i]);
@ -247,7 +247,7 @@ void WriteNodeRow(
labels.emplace_back(utils::Trim(label));
}
} else if (field.type != "ignore") {
properties[field.name] = StringToDecodedValue(value, field.type);
properties[field.name] = StringToValue(value, field.type);
}
}
CHECK(id) << "Node ID must be specified";
@ -255,7 +255,7 @@ void WriteNodeRow(
*id, utils::MemcpyCast<int64_t>(*id), labels, properties, {}};
}
auto PassNodes(std::unordered_map<gid::Gid, durability::DecodedSnapshotVertex>
auto PassNodes(std::unordered_map<gid::Gid, durability::SnapshotVertex>
&partial_vertices,
const std::string &nodes_path, MemgraphNodeIdMap &node_id_map) {
int64_t node_count = 0;
@ -275,13 +275,13 @@ auto PassNodes(std::unordered_map<gid::Gid, durability::DecodedSnapshotVertex>
}
void WriteRelationshipsRow(
std::unordered_map<gid::Gid, communication::bolt::DecodedEdge> &edges,
std::unordered_map<gid::Gid, communication::bolt::Edge> &edges,
const std::vector<Field> &fields, const std::vector<std::string> &row,
const MemgraphNodeIdMap &node_id_map, gid::Gid relationship_id) {
std::experimental::optional<int64_t> start_id;
std::experimental::optional<int64_t> end_id;
std::experimental::optional<std::string> relationship_type;
std::map<std::string, communication::bolt::DecodedValue> properties;
std::map<std::string, communication::bolt::Value> properties;
for (int i = 0; i < row.size(); ++i) {
const auto &field = fields[i];
auto value = utils::Trim(row[i]);
@ -302,7 +302,7 @@ void WriteRelationshipsRow(
<< "Only one relationship TYPE must be specified";
relationship_type = value;
} else if (field.type != "ignore") {
properties[field.name] = StringToDecodedValue(value, field.type);
properties[field.name] = StringToValue(value, field.type);
}
}
CHECK(start_id) << "START_ID must be set";
@ -317,7 +317,7 @@ void WriteRelationshipsRow(
}
int PassRelationships(
std::unordered_map<gid::Gid, communication::bolt::DecodedEdge> &edges,
std::unordered_map<gid::Gid, communication::bolt::Edge> &edges,
const std::string &relationships_path, const MemgraphNodeIdMap &node_id_map,
gid::Generator &relationship_id_generator) {
std::ifstream relationships_file(relationships_path);
@ -358,7 +358,7 @@ void Convert(const std::vector<std::string> &nodes,
// 7) Summary with node count, relationship count and hash digest.
encoder.WriteRAW(durability::kMagicNumber.data(),
durability::kMagicNumber.size());
encoder.WriteDecodedValue(durability::kVersion);
encoder.WriteValue(durability::kVersion);
encoder.WriteInt(0); // Worker Id - for this use case it's okay to set to 0
// since we are using a single-node version of
@ -373,8 +373,8 @@ void Convert(const std::vector<std::string> &nodes,
encoder.WriteInt(0); // Id of transaction that is snapshooting.
encoder.WriteList({}); // Transactional snapshot.
encoder.WriteList({}); // Label + property indexes.
std::unordered_map<gid::Gid, durability::DecodedSnapshotVertex> vertices;
std::unordered_map<gid::Gid, communication::bolt::DecodedEdge> edges;
std::unordered_map<gid::Gid, durability::SnapshotVertex> vertices;
std::unordered_map<gid::Gid, communication::bolt::Edge> edges;
for (const auto &nodes_file : nodes) {
node_count += PassNodes(vertices, nodes_file, node_id_map);
}
@ -402,11 +402,11 @@ void Convert(const std::vector<std::string> &nodes,
encoder.WriteInt(vertex.gid);
auto &labels = vertex.labels;
std::vector<communication::bolt::DecodedValue> transformed;
std::vector<communication::bolt::Value> transformed;
std::transform(labels.begin(), labels.end(),
std::back_inserter(transformed),
[](const std::string &str) {
return communication::bolt::DecodedValue(str);
return communication::bolt::Value(str);
});
encoder.WriteList(transformed);
encoder.WriteMap(vertex.properties);