Remove boost from the codebase

Summary:
Since we switched to Cap'n Proto serialization there's no need for
keeping boost around anymore.

Reviewers: mtomic, mferencevic, buda

Reviewed By: mtomic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1515
This commit is contained in:
Teon Banek 2018-07-30 13:48:22 +02:00
parent 8d934ed801
commit f7f7ccde60
27 changed files with 157 additions and 2666 deletions

5
init
View File

@ -1,16 +1,11 @@
#!/bin/bash -e
# TODO: Consider putting boost library in libs/setup.sh, since the license
# allows source modification and static compilation. Unfortunately, it is quite
# a pain to set up the boost build process.
required_pkgs=(git arcanist # source code control
cmake clang-3.9 llvm-3.9 pkg-config # build system
curl wget # for downloading libs
uuid-dev default-jre-headless # required by antlr
libreadline-dev # for memgraph console
libssl-dev
libboost-iostreams-dev
libboost-serialization-dev
python3 python-virtualenv python3-pip # for qa, macro_benchmark and stress tests
uuid-dev # mg-utils
libcurl4-openssl-dev # mg-requests

View File

@ -190,8 +190,6 @@ string(TOLOWER ${CMAKE_BUILD_TYPE} lower_build_type)
# memgraph_lib depend on these libraries
set(MEMGRAPH_ALL_LIBS stdc++fs Threads::Threads fmt cppitertools
antlr_opencypher_parser_lib dl glog gflags capnp kj
${Boost_IOSTREAMS_LIBRARY_RELEASE}
${Boost_SERIALIZATION_LIBRARY_RELEASE}
mg-utils mg-io mg-integrations mg-requests mg-communication mg-auth)
if (USE_LTALLOC)

View File

@ -40,7 +40,7 @@ cpp<#
(lambda (reader member)
(declare (ignore member))
#>cpp
vertex_output = LoadVertex<const capnp::Vertex::Reader>(${reader});
vertex_output = LoadVertex(${reader});
cpp<#))
(worker-id :int64_t :save-fun "" :load-fun "" :capnp-save :dont-save)
(vertex-output "std::unique_ptr<Vertex>" :initarg nil
@ -62,7 +62,7 @@ cpp<#
(lambda (reader member)
(declare (ignore member))
#>cpp
edge_output = LoadEdge<const capnp::Edge::Reader>(${reader});
edge_output = LoadEdge(${reader});
cpp<#))
(worker-id :int64_t :save-fun "" :load-fun "" :capnp-save :dont-save)
(edge-output "std::unique_ptr<Edge>" :initarg nil

View File

@ -1,9 +1,6 @@
#>cpp
#pragma once
#include "boost/serialization/access.hpp"
#include "boost/serialization/base_object.hpp"
#include "communication/rpc/messages.hpp"
#include "distributed/durability_rpc_messages.capnp.h"
#include "durability/recovery.hpp"

View File

@ -378,13 +378,11 @@ void PullResData::LoadGraphElement(
storage::VertexAddress global_address(vertex_reader.getAddress());
auto old_record =
vertex_reader.hasOld()
? distributed::LoadVertex<const distributed::capnp::Vertex::Reader>(
vertex_reader.getOld())
? distributed::LoadVertex(vertex_reader.getOld())
: nullptr;
auto new_record =
vertex_reader.hasNew()
? distributed::LoadVertex<const distributed::capnp::Vertex::Reader>(
vertex_reader.getNew())
? distributed::LoadVertex(vertex_reader.getNew())
: nullptr;
data_manager->Elements<Vertex>(dba->transaction_id())
.emplace(global_address.gid(), std::move(old_record),
@ -395,13 +393,11 @@ void PullResData::LoadGraphElement(
storage::EdgeAddress global_address(edge_reader.getAddress());
auto old_record =
edge_reader.hasOld()
? distributed::LoadEdge<const distributed::capnp::Edge::Reader>(
edge_reader.getOld())
? distributed::LoadEdge(edge_reader.getOld())
: nullptr;
auto new_record =
edge_reader.hasNew()
? distributed::LoadEdge<const distributed::capnp::Edge::Reader>(
edge_reader.getNew())
? distributed::LoadEdge(edge_reader.getNew())
: nullptr;
data_manager->Elements<Edge>(dba->transaction_id())
.emplace(global_address.gid(), std::move(old_record),

View File

@ -1,5 +1,7 @@
#include "distributed/serialization.hpp"
#include "utils/serialization.hpp"
namespace {
template <class TAddress>
@ -74,7 +76,6 @@ void SaveVertex(const Vertex &vertex, capnp::Vertex::Builder *builder,
SaveProperties(vertex.properties_, &properties_builder);
}
template <>
std::unique_ptr<Vertex> LoadVertex(const capnp::Vertex::Reader &reader) {
auto vertex = std::make_unique<Vertex>();
auto load_edges = [](const auto &edges_reader) {
@ -107,7 +108,6 @@ void SaveEdge(const Edge &edge, capnp::Edge::Builder *builder,
SaveProperties(edge.properties_, &properties_builder);
}
template <>
std::unique_ptr<Edge> LoadEdge(const capnp::Edge::Reader &reader) {
auto from = LoadVertexAddress(reader.getFrom());
auto to = LoadVertexAddress(reader.getTo());

View File

@ -2,208 +2,33 @@
#include <cstdint>
#include <memory>
#include <vector>
#include "distributed/serialization.capnp.h"
#include "storage/address_types.hpp"
#include "storage/edge.hpp"
#include "storage/types.hpp"
#include "storage/vertex.hpp"
#include "utils/serialization.hpp"
namespace distributed {
namespace impl {
// Saves the given address into the given archive. Converts a local address to a
// global one, using the given worker_id.
template <typename TArchive, typename TAddress>
void SaveAddress(TArchive &ar, TAddress address, int worker_id) {
if (address.is_local()) {
ar << address.local()->gid_;
ar << worker_id;
} else {
ar << address.gid();
ar << address.worker_id();
}
};
// Saves the given properties into the given archive.
template <typename TArchive>
void SaveProperties(TArchive &ar, const PropertyValueStore &props) {
ar << props.size();
for (auto &kv : props) {
ar << kv.first.Id();
utils::SaveTypedValue(ar, kv.second);
}
}
} // namespace impl
void SaveVertex(const Vertex &vertex, capnp::Vertex::Builder *builder,
int16_t worker_id);
/**
* Saves the given vertex into the given Boost archive.
*
* @param ar - Archive into which to serialize.
* @param vertex - Getting serialized.
* @param worker_id - ID of the worker this is happening on. Necessary for local
* to global address conversion.
* @tparam TArchive - type of archive.
*/
template <typename TArchive>
void SaveVertex(TArchive &ar, const Vertex &vertex, int worker_id) {
auto save_edges = [&ar, worker_id](auto &edges) {
ar << edges.size();
for (auto &edge_struct : edges) {
impl::SaveAddress(ar, edge_struct.vertex, worker_id);
impl::SaveAddress(ar, edge_struct.edge, worker_id);
ar << edge_struct.edge_type.Id();
}
};
save_edges(vertex.out_);
save_edges(vertex.in_);
ar << vertex.labels_.size();
for (auto &label : vertex.labels_) {
ar << label.Id();
}
impl::SaveProperties(ar, vertex.properties_);
}
void SaveEdge(const Edge &edge, capnp::Edge::Builder *builder,
int16_t worker_id);
/**
* Saves the given edge into the given Boost archive.
*
* @param - Archive into which to serialize.
* @param edge - Getting serialized.
* @param worker_id - ID of the worker this is happening on. Necessary for local
* to global address conversion.
* @tparam TArchive - type of archive.
*/
template <typename TArchive>
void SaveEdge(TArchive &ar, const Edge &edge, int worker_id) {
impl::SaveAddress(ar, edge.from_, worker_id);
impl::SaveAddress(ar, edge.to_, worker_id);
ar << edge.edge_type_.Id();
impl::SaveProperties(ar, edge.properties_);
}
/// Alias for `SaveEdge` allowing for param type resolution.
inline void SaveElement(const Edge &record, capnp::Edge::Builder *builder,
int16_t worker_id) {
int16_t worker_id) {
return SaveEdge(record, builder, worker_id);
}
/// Alias for `SaveVertex` allowing for param type resolution.
inline void SaveElement(const Vertex &record, capnp::Vertex::Builder *builder,
int16_t worker_id) {
int16_t worker_id) {
return SaveVertex(record, builder, worker_id);
}
/// Alias for `SaveEdge` allowing for param type resolution.
template <typename TArchive>
void SaveElement(TArchive &ar, const Edge &record, int worker_id) {
return SaveEdge(ar, record, worker_id);
}
/// Alias for `SaveVertex` allowing for param type resolution.
template <typename TArchive>
void SaveElement(TArchive &ar, const Vertex &record, int worker_id) {
return SaveVertex(ar, record, worker_id);
}
namespace impl {
template <typename TArchive>
storage::VertexAddress LoadVertexAddress(TArchive &ar) {
gid::Gid vertex_id;
ar >> vertex_id;
int worker_id;
ar >> worker_id;
return {vertex_id, worker_id};
}
template <typename TArchive>
void LoadProperties(TArchive &ar, PropertyValueStore &store) {
size_t count;
ar >> count;
for (size_t i = 0; i < count; ++i) {
storage::Property::IdT prop;
ar >> prop;
query::TypedValue value;
utils::LoadTypedValue(ar, value);
store.set(storage::Property(prop), static_cast<PropertyValue>(value));
}
}
} // namespace impl
/**
* Loads a Vertex from the given archive and returns it.
*
* @param ar - The archive to load from.
* @tparam TArchive - archive type.
*/
template <typename TArchive>
std::unique_ptr<Vertex> LoadVertex(TArchive &ar) {
auto vertex = std::make_unique<Vertex>();
auto decode_edges = [&ar](Edges &edges) {
size_t count;
ar >> count;
for (size_t i = 0; i < count; ++i) {
auto vertex_address = impl::LoadVertexAddress(ar);
storage::EdgeType::IdT edge_type;
gid::Gid edge_id;
ar >> edge_id;
int edge_worker_id;
ar >> edge_worker_id;
ar >> edge_type;
edges.emplace(vertex_address, {edge_id, edge_worker_id},
storage::EdgeType(edge_type));
}
};
decode_edges(vertex->out_);
decode_edges(vertex->in_);
size_t count;
ar >> count;
for (size_t i = 0; i < count; ++i) {
storage::Label::IdT label;
ar >> label;
vertex->labels_.emplace_back(label);
}
impl::LoadProperties(ar, vertex->properties_);
return vertex;
}
template <>
std::unique_ptr<Vertex> LoadVertex(const capnp::Vertex::Reader &reader);
/**
* Loads an Edge from the given archive and returns it.
*
* @param ar - The archive to load from.
* @tparam TArchive - archive type.
*/
template <typename TArchive>
std::unique_ptr<Edge> LoadEdge(TArchive &ar) {
auto from = impl::LoadVertexAddress(ar);
auto to = impl::LoadVertexAddress(ar);
storage::EdgeType::IdT edge_type;
ar >> edge_type;
auto edge = std::make_unique<Edge>(from, to, storage::EdgeType{edge_type});
impl::LoadProperties(ar, edge->properties_);
return edge;
}
template <>
std::unique_ptr<Edge> LoadEdge(const capnp::Edge::Reader &reader);
} // namespace distributed

View File

@ -58,7 +58,7 @@ cpp<#
:capnp-save (lcp:capnp-save-enum "capnp::UpdateResult" "UpdateResult")
:capnp-load (lcp:capnp-load-enum "capnp::UpdateResult" "UpdateResult"))
(gid "gid::Gid" :documentation "Only valid if creation was successful."))
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-struct create-vertex-req-data ()
((tx-id "tx::TransactionId")

View File

@ -41,15 +41,6 @@ struct RecoveryInfo {
auto list_reader = reader.getWalRecovered();
utils::LoadVector(&wal_recovered, list_reader);
}
private:
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, unsigned int) {
ar &snapshot_tx_id;
ar &wal_recovered;
}
};
// A data structure for exchanging info between main recovery function and
@ -109,17 +100,6 @@ struct RecoveryData {
});
}
}
private:
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, unsigned int) {
ar &snapshooter_tx_id;
ar &wal_tx_to_recover;
ar &snapshooter_tx_snapshot;
ar &indexes;
}
};
/** Reads snapshot metadata from the end of the file without messing up the

View File

@ -472,72 +472,6 @@ which generate the corresponding C++ keywords."
until (or (not char) (and stop-position (> pos stop-position)))
when (char= #\Newline char) count it))
(defun boost-serialization (cpp-class)
"Add boost serialization code to `CPP-CLASS'."
(labels ((get-serialize-code (member-name serialize-fun)
(if serialize-fun
;; Invoke or use serialize-fun
(ctypecase serialize-fun
((or string raw-cpp) serialize-fun)
(function
(let ((res (funcall serialize-fun "ar" member-name)))
(check-type res (or raw-cpp string))
res)))
;; Else use the default serialization
#>cpp
ar & ${member-name};
cpp<#))
(save-member (member)
(get-serialize-code
(cpp-member-name member :struct (cpp-class-structp cpp-class))
(cpp-member-save-fun member)))
(load-member (member)
(get-serialize-code
(cpp-member-name member :struct (cpp-class-structp cpp-class))
(cpp-member-load-fun member))))
(let* ((members (cpp-class-members cpp-class))
(split-serialization (some (lambda (m) (or (cpp-member-save-fun m)
(cpp-member-load-fun m)))
members))
(serialize-declaration
(cond
(split-serialization
#>cpp
BOOST_SERIALIZATION_SPLIT_MEMBER();
template <class TArchive>
void save(TArchive &ar, const unsigned int) const {
cpp<#)
(t ;; otherwise a single serialization function for save + load
#>cpp
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
cpp<#)))
(serialize-bases
(when (cpp-class-super-classes cpp-class)
(make-raw-cpp
:string (format nil "~{ar & boost::serialization::base_object<~A>(*this);~^~%~}"
(mapcar #'cpp-type-name (cpp-class-super-classes cpp-class)))))))
(append (list
(make-raw-cpp
:string (format nil "~%friend class boost::serialization::access;"))
serialize-declaration
;; save
serialize-bases)
(mapcar #'save-member members)
(when split-serialization
;; load
(cons
#>cpp
}
template <class TArchive>
void load(TArchive &ar, const unsigned int) {
cpp<#
(cons serialize-bases
(mapcar #'load-member members))))
(list #>cpp } cpp<#)))))
;;; Cap'n Proto schema and C++ serialization code generation
;;; Schema generation
@ -1393,18 +1327,16 @@ Currently supported class-options are:
* :public -- additional C++ code in public scope.
* :protected -- additional C++ code in protected scope.
* :private -- additional C++ code in private scope.
* :serialize -- only :boost and :capnp are valid values. Setting :boost
will generate boost serialization code for the class members. Setting
:capnp will generate the Cap'n Proto serialization code for the class
members. You may specifiy additional options after :capnp to fill the
`CAPNP-OPTS' slots.
* :serialize -- only :capnp is a valid value. Setting :capnp will generate
the Cap'n Proto serialization code for the class members. You may
specifiy additional options after :capnp to fill the `CAPNP-OPTS' slots.
Larger example:
;; (lcp:define-class derived (base)
;; ((val :int :reader t :initval 42))
;; (:public #>cpp void set_val(int new_val) { val_ = new_val; } cpp<#)
;; (:serialize :boost))
;; (:serialize :capnp))
Generates C++:
@ -1413,14 +1345,11 @@ Generates C++:
;; void set_val(int new_val) { val_ = new_val; }
;; auto val() { return val_; } // autogenerated from :reader t
;;
;; private:
;; friend class boost::serialization::access;
;; template <class TArchive>
;; void serialize(TArchive &ar, unsigned int) {
;; ar & boost::serialization::base_object<Base>(*this);
;; ar & val_;
;; }
;; void Save(capnp::Base::Builder *builder) const;
;; static std::unique_ptr<Derived> Construct(const capnp::Base::Reader &reader);
;; void Load(const capnp::Base::Reader &reader);
;;
;; private:
;; int val_ = 42; // :initval is assigned
;; };"
(let ((structp (second (assoc :structp options))))
@ -1462,10 +1391,7 @@ Generates C++:
(push ,class *cpp-classes*)
;; Set the parent's inner types
(push ,class *cpp-inner-types*)
(setf (cpp-type-enclosing-class ,class) *cpp-enclosing-class*)
,(when (eq :boost (car serialize))
`(setf (cpp-class-private ,class)
(append (cpp-class-private ,class) (boost-serialization ,class))))))))))
(setf (cpp-type-enclosing-class ,class) *cpp-enclosing-class*)))))))
(defmacro define-struct (name super-classes slots &rest options)
`(define-class ,name ,super-classes ,slots (:structp t) ,@options))

View File

@ -215,31 +215,9 @@ void ReconstructTypedValue(TypedValue &value) {
}
}
bool TypedValueVectorCompare::operator()(
const std::vector<TypedValue> &c1,
const std::vector<TypedValue> &c2) const {
// ordering is invalid if there are more elements in the collections
// then there are in the ordering_ vector
DCHECK(c1.size() <= ordering_.size() && c2.size() <= ordering_.size())
<< "Collections contain more elements then there are orderings";
namespace {
auto c1_it = c1.begin();
auto c2_it = c2.begin();
auto ordering_it = ordering_.begin();
for (; c1_it != c1.end() && c2_it != c2.end();
c1_it++, c2_it++, ordering_it++) {
if (TypedValueCompare(*c1_it, *c2_it)) return *ordering_it == Ordering::ASC;
if (TypedValueCompare(*c2_it, *c1_it))
return *ordering_it == Ordering::DESC;
}
// at least one collection is exhausted
// c1 is less then c2 iff c1 reached the end but c2 didn't
return (c1_it == c1.end()) && (c2_it != c2.end());
}
bool TypedValueVectorCompare::TypedValueCompare(const TypedValue &a,
const TypedValue &b) const {
bool TypedValueCompare(const TypedValue &a, const TypedValue &b) {
// in ordering null comes after everything else
// at the same time Null is not less that null
// first deal with Null < Whatever case
@ -281,6 +259,31 @@ bool TypedValueVectorCompare::TypedValueCompare(const TypedValue &a,
}
}
} // namespace
bool TypedValueVectorCompare::operator()(
const std::vector<TypedValue> &c1,
const std::vector<TypedValue> &c2) const {
// ordering is invalid if there are more elements in the collections
// then there are in the ordering_ vector
DCHECK(c1.size() <= ordering_.size() && c2.size() <= ordering_.size())
<< "Collections contain more elements then there are orderings";
auto c1_it = c1.begin();
auto c2_it = c2.begin();
auto ordering_it = ordering_.begin();
for (; c1_it != c1.end() && c2_it != c2.end();
c1_it++, c2_it++, ordering_it++) {
if (TypedValueCompare(*c1_it, *c2_it)) return *ordering_it == Ordering::ASC;
if (TypedValueCompare(*c2_it, *c1_it))
return *ordering_it == Ordering::DESC;
}
// at least one collection is exhausted
// c1 is less then c2 iff c1 reached the end but c2 didn't
return (c1_it == c1.end()) && (c2_it != c2.end());
}
void TypedValueVectorCompare::Save(
capnp::TypedValueVectorCompare::Builder *builder) const {
auto ordering_builder = builder->initOrdering(ordering_.size());

View File

@ -3,7 +3,6 @@
#include <cstdint>
#include <string>
#include "boost/serialization/serialization.hpp"
#include "query/frontend/ast/ast.hpp"
#include "query/typed_value.hpp"
@ -54,20 +53,6 @@ class TypedValueVectorCompare final {
private:
std::vector<Ordering> ordering_;
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &ordering_;
}
// Custom comparison for TypedValue objects.
//
// Behaves generally like Neo's ORDER BY comparison operator:
// - null is greater than anything else
// - primitives compare naturally, only implicit cast is int->double
// - (list, map, path, vertex, edge) can't compare to anything
bool TypedValueCompare(const TypedValue &a, const TypedValue &b) const;
};
// Switch the given [Vertex/Edge]Accessor to the desired state.

View File

@ -1,27 +1,11 @@
#include "query/frontend/ast/ast.hpp"
#include <algorithm>
// Include archives before registering most derived types.
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/serialization/export.hpp"
#include "utils/serialization.capnp.h"
namespace query {
// Id for boost's archive get_helper needs to be unique among all ids. If it
// isn't unique, then different instances (even across different types!) will
// replace the previous helper. The documentation recommends to take an address
// of a function, which should be unique in the produced binary.
// It might seem logical to take an address of a AstStorage constructor, but
// according to c++ standard, the constructor function need not have an address.
// Additionally, pointers to member functions are not required to contain the
// address of the function
// (https://isocpp.org/wiki/faq/pointers-to-members#addr-of-memfn). So, to be
// safe, use a regular top-level function.
void *const AstStorage::kHelperId = (void *)CloneReturnBody;
AstStorage::AstStorage() { storage_.emplace_back(new Query(next_uid_++)); }
Query *AstStorage::query() const {
@ -2651,69 +2635,5 @@ SingleQuery *SingleQuery::Construct(const capnp::SingleQuery::Reader &reader,
AstStorage *storage) {
return storage->Create<SingleQuery>();
}
} // namespace query
BOOST_CLASS_EXPORT_IMPLEMENT(query::Query);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SingleQuery);
BOOST_CLASS_EXPORT_IMPLEMENT(query::CypherUnion);
BOOST_CLASS_EXPORT_IMPLEMENT(query::NamedExpression);
BOOST_CLASS_EXPORT_IMPLEMENT(query::OrOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::XorOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::AndOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::NotOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::AdditionOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SubtractionOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::MultiplicationOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::DivisionOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ModOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::NotEqualOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::EqualOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::LessOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::GreaterOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::LessEqualOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::GreaterEqualOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::InListOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SubscriptOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ListSlicingOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::IfOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::UnaryPlusOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::UnaryMinusOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::IsNullOperator);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ListLiteral);
BOOST_CLASS_EXPORT_IMPLEMENT(query::MapLiteral);
BOOST_CLASS_EXPORT_IMPLEMENT(query::PropertyLookup);
BOOST_CLASS_EXPORT_IMPLEMENT(query::LabelsTest);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Aggregation);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Function);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Reduce);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Extract);
BOOST_CLASS_EXPORT_IMPLEMENT(query::All);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Single);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ParameterLookup);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Create);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Match);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Return);
BOOST_CLASS_EXPORT_IMPLEMENT(query::With);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Pattern);
BOOST_CLASS_EXPORT_IMPLEMENT(query::NodeAtom);
BOOST_CLASS_EXPORT_IMPLEMENT(query::EdgeAtom);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Delete);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Where);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SetProperty);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SetProperties);
BOOST_CLASS_EXPORT_IMPLEMENT(query::SetLabels);
BOOST_CLASS_EXPORT_IMPLEMENT(query::RemoveProperty);
BOOST_CLASS_EXPORT_IMPLEMENT(query::RemoveLabels);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Merge);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Unwind);
BOOST_CLASS_EXPORT_IMPLEMENT(query::Identifier);
BOOST_CLASS_EXPORT_IMPLEMENT(query::PrimitiveLiteral);
BOOST_CLASS_EXPORT_IMPLEMENT(query::CreateIndex);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ModifyUser);
BOOST_CLASS_EXPORT_IMPLEMENT(query::DropUser);
BOOST_CLASS_EXPORT_IMPLEMENT(query::CreateStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::DropStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::ShowStreams);
BOOST_CLASS_EXPORT_IMPLEMENT(query::StartStopStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::StartStopAllStreams);
BOOST_CLASS_EXPORT_IMPLEMENT(query::TestStream);
} // namespace query

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,6 @@
#include <string>
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/string.hpp"
#include "symbol.capnp.h"
namespace query {
@ -102,17 +99,6 @@ class Symbol {
bool user_declared_ = true;
Type type_ = Type::Any;
int token_position_ = -1;
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar & name_;
ar & position_;
ar & user_declared_;
ar & type_;
ar & token_position_;
}
};
} // namespace query

View File

@ -3,9 +3,6 @@
#include <map>
#include <string>
#include "boost/serialization/map.hpp"
#include "boost/serialization/serialization.hpp"
#include "query/frontend/ast/ast.hpp"
#include "query/frontend/semantic/symbol.capnp.h"
#include "query/frontend/semantic/symbol.hpp"
@ -57,14 +54,6 @@ class SymbolTable final {
private:
int position_{0};
std::map<int, Symbol> table_;
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &position_;
ar &table_;
}
};
} // namespace query

View File

@ -2,11 +2,9 @@
#include <memory>
// TODO: Remove these includes for hacked cloning of logical operators via boost
// TODO: Remove these includes for hacked cloning of logical operators via
// serialization when proper cloning is added.
#include <sstream>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include <capnp/message.h>
#include "query/plan/operator.hpp"
#include "query/plan/preprocess.hpp"
@ -19,17 +17,17 @@ namespace {
std::pair<std::unique_ptr<LogicalOperator>, AstStorage> Clone(
const LogicalOperator &original_plan) {
// TODO: Add a proper Clone method to LogicalOperator
std::stringstream stream;
::capnp::MallocMessageBuilder message;
{
boost::archive::binary_oarchive out_archive(stream);
out_archive << &original_plan;
auto builder = message.initRoot<query::plan::capnp::LogicalOperator>();
LogicalOperator::SaveHelper helper;
original_plan.Save(&builder, &helper);
}
boost::archive::binary_iarchive in_archive(stream);
LogicalOperator *plan_copy = nullptr;
in_archive >> plan_copy;
return {std::unique_ptr<LogicalOperator>(plan_copy),
std::move(in_archive.template get_helper<AstStorage>(
AstStorage::kHelperId))};
auto reader = message.getRoot<query::plan::capnp::LogicalOperator>();
auto plan_copy = LogicalOperator::Construct(reader);
LogicalOperator::LoadHelper helper;
plan_copy->Load(reader, &helper);
return std::make_pair(std::move(plan_copy), std::move(helper.ast_storage));
}
int64_t AddWorkerPlan(DistributedPlan &distributed_plan,

View File

@ -11,9 +11,6 @@
#include <unordered_set>
#include <utility>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/serialization/export.hpp"
#include "glog/logging.h"
#include "auth/auth.hpp"
@ -4333,48 +4330,3 @@ std::unique_ptr<Cursor> TestStream::MakeCursor(
}
} // namespace query::plan
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Once);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::CreateNode);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::CreateExpand);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ScanAll);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ScanAllByLabel);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ScanAllByLabelPropertyRange);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ScanAllByLabelPropertyValue);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Expand);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ExpandVariable);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Filter);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Produce);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ConstructNamedPath);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Delete);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::SetProperty);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::SetProperties);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::SetLabels);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::RemoveProperty);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::RemoveLabels);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ExpandUniquenessFilter<EdgeAccessor>);
BOOST_CLASS_EXPORT_IMPLEMENT(
query::plan::ExpandUniquenessFilter<VertexAccessor>);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Accumulate);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Aggregate);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Skip);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Limit);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::OrderBy);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Merge);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Optional);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Unwind);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Distinct);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::CreateIndex);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Union);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::PullRemote);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Synchronize);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::Cartesian);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::PullRemoteOrderBy);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ModifyUser);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::DropUser);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::CreateStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::DropStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::ShowStreams);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::StartStopStream);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::StartStopAllStreams);
BOOST_CLASS_EXPORT_IMPLEMENT(query::plan::TestStream);

View File

@ -10,13 +10,6 @@
#include <utility>
#include <vector>
#include <boost/serialization/shared_ptr_helper.hpp>
#include "boost/serialization/base_object.hpp"
#include "boost/serialization/export.hpp"
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/shared_ptr.hpp"
#include "boost/serialization/unique_ptr.hpp"
#include "distributed/pull_produce_rpc_messages.hpp"
#include "query/common.hpp"
#include "query/frontend/ast/ast.hpp"
@ -243,48 +236,10 @@ can serve as inputs to others and thus a sequence of operations is formed.")
loaded_ops;
};
cpp<#)
(:private
#>cpp
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &, const unsigned int) {}
cpp<#)
(:serialize :capnp :base t
:save-args '((helper "SaveHelper *"))
:load-args '((helper "LoadHelper *"))))
#>cpp
template <class TArchive>
std::pair<std::unique_ptr<LogicalOperator>, AstStorage> LoadPlan(
TArchive &ar) {
std::unique_ptr<LogicalOperator> root;
ar >> root;
return {std::move(root), std::move(ar.template get_helper<AstStorage>(
AstStorage::kHelperId))};
}
cpp<#
(defun save-pointer (archive member-name)
#>cpp
SavePointer(${archive}, ${member-name});
cpp<#)
(defun load-pointer (archive member-name)
#>cpp
LoadPointer(${archive}, ${member-name});
cpp<#)
(defun save-pointers (archive member-name)
#>cpp
SavePointers(${archive}, ${member-name});
cpp<#)
(defun load-pointers (archive member-name)
#>cpp
LoadPointers(${archive}, ${member-name});
cpp<#)
(defun save-ast-pointer (builder member)
(let ((member-getter (remove #\_ (string-capitalize member))))
#>cpp
@ -367,7 +322,7 @@ and false on every following Pull.")
bool did_pull_{false};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class create-node (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -375,8 +330,7 @@ and false on every following Pull.")
:capnp-load #'load-operator-pointer)
(node-atom "NodeAtom *" :initval "nullptr" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "NodeAtom *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "NodeAtom *"))
(on-random-worker :bool :initval "false"))
(:documentation
"Operator for creating a node.
@ -429,17 +383,15 @@ a preceeding `MATCH`), or multiple nodes (`MATCH ... CREATE` or
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class create-expand (logical-operator)
(
;; info on what's getting expanded
(node-atom "NodeAtom *" :reader t
:save-fun #'save-pointer :load-fun #'load-pointer
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "NodeAtom *"))
(edge-atom "EdgeAtom *" :reader t
:save-fun #'save-pointer :load-fun #'load-pointer
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "EdgeAtom *"))
;; the input op and the symbol under which the op's result
@ -523,7 +475,7 @@ chained in cases when longer paths need creating.
ExpressionEvaluator &evaluator);
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class scan-all (logical-operator)
((input "std::shared_ptr<LogicalOperator>" :scope :protected
@ -575,7 +527,7 @@ with a constructor argument.
}
cpp<#)
(:protected #>cpp ScanAll() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class scan-all-by-label (scan-all)
((label "storage::Label" :reader t))
@ -596,7 +548,7 @@ given label.
database::GraphDbAccessor &db) const override;
cpp<#)
(:private #>cpp ScanAllByLabel() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(defun save-optional-bound (builder member)
(let ((save-bound
@ -628,44 +580,10 @@ given label.
(property "storage::Property" :reader t)
(lower-bound "std::experimental::optional<Bound>" :reader t
:capnp-type "Utils.Optional(Utils.Bound(Ast.Tree))"
:capnp-save #'save-optional-bound :capnp-load #'load-optional-bound
:save-fun
#>cpp
auto save_bound = [&ar](auto &maybe_bound) {
if (!maybe_bound) {
ar & false;
return;
}
ar & true;
auto &bound = *maybe_bound;
ar &bound.type();
SavePointer(ar, bound.value());
};
save_bound(lower_bound_);
cpp<#
:load-fun
#>cpp
auto load_bound = [&ar](auto &maybe_bound) {
bool has_bound = false;
ar &has_bound;
if (!has_bound) {
maybe_bound = std::experimental::nullopt;
return;
}
utils::BoundType type;
ar &type;
Expression *value;
LoadPointer(ar, value);
maybe_bound = std::experimental::make_optional(Bound(value, type));
};
load_bound(lower_bound_);
cpp<#)
:capnp-save #'save-optional-bound :capnp-load #'load-optional-bound)
(upper-bound "std::experimental::optional<Bound>" :reader t
:capnp-save #'save-optional-bound :capnp-load #'load-optional-bound
:capnp-type "Utils.Optional(Utils.Bound(Ast.Tree))"
:save-fun #>cpp save_bound(upper_bound_); cpp<#
:load-fun #>cpp load_bound(upper_bound_); cpp<#
))
:capnp-type "Utils.Optional(Utils.Bound(Ast.Tree))"))
(:documentation
"Behaves like @c ScanAll, but produces only vertices with given label and
property value which is inside a range (inclusive or exlusive).
@ -703,15 +621,14 @@ property value which is inside a range (inclusive or exlusive).
database::GraphDbAccessor &db) const override;
cpp<#)
(:private #>cpp ScanAllByLabelPropertyRange() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class scan-all-by-label-property-value (scan-all)
((label "storage::Label" :reader t)
(property "storage::Property" :reader t)
(expression "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:documentation
"Behaves like @c ScanAll, but produces only vertices with given label and
property value.
@ -742,7 +659,7 @@ property value.
database::GraphDbAccessor &db) const override;
cpp<#)
(:private #>cpp ScanAllByLabelPropertyValue() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class expand-common ()
(
@ -838,7 +755,7 @@ expansion")
ExpandCommon() {}
cpp<#)
(:serialize :boost :capnp
(:serialize :capnp
:save-args '((helper "LogicalOperator::SaveHelper *"))
:load-args '((helper "LogicalOperator::LoadHelper *"))))
@ -910,7 +827,7 @@ pulled.")
bool InitEdges(Frame &, Context &);
};
cpp<#)
(:serialize :boost :capnp :inherit-compose '(expand-common)))
(:serialize :capnp :inherit-compose '(expand-common)))
(lcp:define-class expand-variable (logical-operator expand-common)
((type "EdgeAtom::Type" :reader t :capnp-type "Ast.EdgeAtom.Type"
@ -922,12 +839,10 @@ pulled.")
(is-reverse :bool :documentation
"True if the path should be written as expanding from node_symbol to input_symbol.")
(lower-bound "Expression *" :reader t
:save-fun #'save-pointer :load-fun #'load-pointer
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:documentation "Optional lower bound of the variable length expansion, defaults are (1, inf)")
(upper-bound "Expression *" :reader t
:save-fun #'save-pointer :load-fun #'load-pointer
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:documentation "Optional upper bound of the variable length expansion, defaults are (1, inf)")
@ -965,11 +880,10 @@ pulled.")
(inner-node-symbol "Symbol" :documentation "Currently expanded node symbol.")
(expression "Expression *" :documentation "Expression used in lambda during expansion."
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
(:serialize :boost :capnp
:save-args '((helper "LogicalOperator::SaveHelper *"))
:load-args '((helper "LogicalOperator::LoadHelper *"))))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:serialize :capnp
:save-args '((helper "LogicalOperator::SaveHelper *"))
:load-args '((helper "LogicalOperator::LoadHelper *"))))
#>cpp
/**
* Creates a variable-length expansion. Most params are forwarded
@ -1028,7 +942,7 @@ pulled.")
ExpandVariable() {}
cpp<#)
(:serialize :boost :capnp :inherit-compose '(expand-common)))
(:serialize :capnp :inherit-compose '(expand-common)))
(lcp:define-class construct-named-path (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1061,7 +975,7 @@ pulled.")
cpp<#)
(:private
#>cpp ConstructNamedPath() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class filter (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1069,8 +983,7 @@ pulled.")
:capnp-load #'load-operator-pointer)
(expression "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:documentation
"Filter whose Pull returns true only when the given expression
evaluates into true.
@ -1107,7 +1020,7 @@ a boolean value.")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class produce (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1116,8 +1029,7 @@ a boolean value.")
(named-expressions "std::vector<NamedExpression *>" :reader t
:capnp-type "List(Ast.Tree)"
:capnp-save (save-ast-vector "NamedExpression *")
:capnp-load (load-ast-vector "NamedExpression *")
:save-fun #'save-pointers :load-fun #'load-pointers))
:capnp-load (load-ast-vector "NamedExpression *")))
(:documentation
"A logical operator that places an arbitrary number
if named expressions on the frame (the logical operator
@ -1159,7 +1071,7 @@ RETURN clause) the Produce's pull succeeds exactly once.")
Produce() {}
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class delete (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1168,8 +1080,7 @@ RETURN clause) the Produce's pull succeeds exactly once.")
(expressions "std::vector<Expression *>" :reader t
:capnp-type "List(Ast.Tree)"
:capnp-save (save-ast-vector "Expression *")
:capnp-load (load-ast-vector "Expression *")
:save-fun #'save-pointers :load-fun #'load-pointers)
:capnp-load (load-ast-vector "Expression *"))
(detach :bool :documentation
"if the vertex should be detached before deletion if not detached,
and has connections, an error is raised ignored when deleting edges"))
@ -1208,7 +1119,7 @@ Has a flag for using DETACH DELETE when deleting vertices.")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class set-property (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1216,12 +1127,10 @@ Has a flag for using DETACH DELETE when deleting vertices.")
:capnp-load #'load-operator-pointer)
(lhs "PropertyLookup *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "PropertyLookup *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "PropertyLookup *"))
(rhs "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:documentation
"Logical Op for setting a single property on a single vertex or edge.
@ -1257,7 +1166,7 @@ can be stored (a TypedValue that can be converted to PropertyValue).")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class set-properties (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1266,8 +1175,7 @@ can be stored (a TypedValue that can be converted to PropertyValue).")
(input-symbol "Symbol" :reader t)
(rhs "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *"))
(op "Op" :capnp-init nil
:capnp-save (lcp:capnp-save-enum "capnp::SetProperties::Op" "Op")
:capnp-load (lcp:capnp-load-enum "capnp::SetProperties::Op" "Op")))
@ -1328,7 +1236,7 @@ that the old props are discarded and replaced with new ones.")
void Set(TRecordAccessor &record, const TypedValue &rhs) const;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class set-labels (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1372,7 +1280,7 @@ It does NOT remove labels that are already set on that Vertex.")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class remove-property (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1380,8 +1288,7 @@ It does NOT remove labels that are already set on that Vertex.")
:capnp-load #'load-operator-pointer)
(lhs "PropertyLookup *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "PropertyLookup *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "PropertyLookup *")))
(:documentation
"Logical op for removing a property from an edge or a vertex.")
(:public
@ -1415,7 +1322,7 @@ It does NOT remove labels that are already set on that Vertex.")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class remove-labels (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1459,7 +1366,7 @@ If a label does not exist on a Vertex, nothing happens.")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class (expand-uniqueness-filter t-accessor) (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1523,7 +1430,7 @@ between edges and an edge lists).")
const std::unique_ptr<Cursor> input_cursor_;
};
cpp<#)
(:serialize :boost :capnp :type-args '(vertex-accessor edge-accessor)))
(:serialize :capnp :type-args '(vertex-accessor edge-accessor)))
(lcp:define-class accumulate (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1594,7 +1501,7 @@ has been cached will be reconstructed before Pull returns.
bool pulled_all_input_{false};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
#>cpp
/**
@ -1621,8 +1528,7 @@ cpp<#
(group-by "std::vector<Expression *>" :reader t
:capnp-type "List(Ast.Tree)"
:capnp-save (save-ast-vector "Expression *")
:capnp-load (load-ast-vector "Expression *")
:save-fun #'save-pointers :load-fun #'load-pointers)
:capnp-load (load-ast-vector "Expression *"))
(remember "std::vector<Symbol>" :reader t
:capnp-save (lcp:capnp-save-vector "::query::capnp::Symbol" "Symbol")
:capnp-load (lcp:capnp-load-vector "::query::capnp::Symbol" "Symbol")))
@ -1644,12 +1550,10 @@ elements are in an undefined state after aggregation.")
(lcp:define-struct element ()
((value "Expression *"
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *"))
(key "Expression *"
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *"))
(op "Aggregation::Op" :capnp-type "Ast.Aggregation.Op"
:capnp-init nil :capnp-save (lcp:capnp-save-enum "::query::capnp::Aggregation::Op" "Aggregation::Op"
'(count min max sum avg collect-list collect-map))
@ -1660,9 +1564,9 @@ elements are in an undefined state after aggregation.")
"An aggregation element, contains:
(input data expression, key expression - only used in COLLECT_MAP, type of
aggregation, output symbol).")
(:serialize :boost :capnp
:save-args '((helper "LogicalOperator::SaveHelper *"))
:load-args '((helper "LogicalOperator::LoadHelper *"))))
(:serialize :capnp
:save-args '((helper "LogicalOperator::SaveHelper *"))
:load-args '((helper "LogicalOperator::LoadHelper *"))))
#>cpp
Aggregate(const std::shared_ptr<LogicalOperator> &input,
const std::vector<Element> &aggregations,
@ -1762,7 +1666,7 @@ elements are in an undefined state after aggregation.")
void EnsureOkForAvgSum(const TypedValue &value) const;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class skip (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1770,8 +1674,7 @@ elements are in an undefined state after aggregation.")
:capnp-load #'load-operator-pointer)
(expression "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:documentation
"Skips a number of Pulls from the input op.
@ -1818,7 +1721,7 @@ operator's implementation does not expect this.")
int skipped_{0};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class limit (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1826,8 +1729,7 @@ operator's implementation does not expect this.")
:capnp-load #'load-operator-pointer)
(expression "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer))
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")))
(:documentation
"Limits the number of Pulls from the input op.
@ -1877,7 +1779,7 @@ input should be performed).")
int pulled_{0};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class order-by (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -1888,8 +1790,7 @@ input should be performed).")
(order-by "std::vector<Expression *>" :reader t
:capnp-type "List(Ast.Tree)"
:capnp-save (save-ast-vector "Expression *")
:capnp-load (load-ast-vector "Expression *")
:save-fun #'save-pointers :load-fun #'load-pointers)
:capnp-load (load-ast-vector "Expression *"))
(output-symbols "std::vector<Symbol>" :reader t
:capnp-save (lcp:capnp-save-vector "::query::capnp::Symbol" "Symbol")
:capnp-load (lcp:capnp-load-vector "::query::capnp::Symbol" "Symbol")))
@ -1945,7 +1846,7 @@ are valid for usage after the OrderBy operator.")
decltype(cache_.begin()) cache_it_ = cache_.begin();
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class merge (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2011,7 +1912,7 @@ documentation.")
bool pull_input_{true};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class optional (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2068,7 +1969,7 @@ and returns true, once.")
bool pull_input_{true};
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class unwind (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2076,8 +1977,7 @@ and returns true, once.")
:capnp-load #'load-operator-pointer)
(input-expression "Expression *" :reader t
:capnp-type "Ast.Tree" :capnp-init nil
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *")
:save-fun #'save-pointer :load-fun #'load-pointer)
:capnp-save #'save-ast-pointer :capnp-load (load-ast-pointer "Expression *"))
(output-symbol "Symbol"))
(:documentation
"Takes a list TypedValue as it's input and yields each
@ -2119,7 +2019,7 @@ Input is optional (unwind can be the first clause in a query).")
std::vector<TypedValue>::iterator input_value_it_ = input_value_.end();
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class distinct (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2175,7 +2075,7 @@ This implementation maintains input ordering.")
seen_rows_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class create-index (logical-operator)
((label "storage::Label" :reader t)
@ -2202,7 +2102,7 @@ case the index already exists, nothing happens.")
void set_input(std::shared_ptr<LogicalOperator>) override;
cpp<#)
(:private #>cpp CreateIndex() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class union (logical-operator)
((left-op "std::shared_ptr<LogicalOperator>" :reader t
@ -2258,7 +2158,7 @@ vectors of symbols used by each of the inputs.")
const std::unique_ptr<Cursor> left_cursor_, right_cursor_;
};
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class pull-remote (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2293,7 +2193,7 @@ time on data transfer. It gives no guarantees on result order.")
}
cpp<#)
(:private #>cpp PullRemote() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(defun load-pull-remote (reader member-name)
#>cpp
@ -2357,7 +2257,7 @@ Logic of the synchronize operator is:
}
cpp<#)
(:private #>cpp Synchronize() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class cartesian (logical-operator)
((left-op "std::shared_ptr<LogicalOperator>" :reader t
@ -2396,7 +2296,7 @@ Logic of the synchronize operator is:
void set_input(std::shared_ptr<LogicalOperator>) override;
cpp<#)
(:private #>cpp Cartesian() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class pull-remote-order-by (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2409,8 +2309,7 @@ Logic of the synchronize operator is:
(order-by "std::vector<Expression *>" :reader t
:capnp-type "List(Ast.Tree)"
:capnp-save (save-ast-vector "Expression *")
:capnp-load (load-ast-vector "Expression *")
:save-fun #'save-pointers :load-fun #'load-pointers)
:capnp-load (load-ast-vector "Expression *"))
(compare "TypedValueVectorCompare" :reader t
:capnp-type "Common.TypedValueVectorCompare"))
(:documentation
@ -2439,7 +2338,7 @@ by having only one result from each worker.")
}
cpp<#)
(:private #>cpp PullRemoteOrderBy() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class modify-user (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2447,8 +2346,6 @@ by having only one result from each worker.")
:capnp-load #'load-operator-pointer)
(username "std::string" :reader t)
(password "Expression *" :reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
@ -2474,11 +2371,9 @@ by having only one result from each worker.")
cpp<#)
(:private
#>cpp
friend class boost::serialization::access;
ModifyUser() {}
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class drop-user (logical-operator)
((input "std::shared_ptr<LogicalOperator>"
@ -2505,49 +2400,38 @@ by having only one result from each worker.")
cpp<#)
(:private
#>cpp
friend class boost::serialization::access;
DropUser() {}
cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class create-stream (logical-operator)
((stream-name "std::string" :reader t)
(stream-uri "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
:capnp-load (load-ast-pointer "Expression *"))
(stream-topic "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
:capnp-load (load-ast-pointer "Expression *"))
(transform-uri "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
:capnp-load (load-ast-pointer "Expression *"))
(batch-interval-in-ms "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
:capnp-load (load-ast-pointer "Expression *"))
(batch-size "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
@ -2572,7 +2456,7 @@ by having only one result from each worker.")
cpp<#)
(:private
#>cpp CreateStream() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class drop-stream (logical-operator)
((stream-name "std::string" :reader t))
@ -2594,7 +2478,7 @@ by having only one result from each worker.")
cpp<#)
(:private
#>cpp DropStream() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class show-streams (logical-operator)
((name-symbol "Symbol" :reader t)
@ -2622,15 +2506,13 @@ by having only one result from each worker.")
cpp<#)
(:private
#>cpp ShowStreams() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class start-stop-stream (logical-operator)
((stream-name "std::string" :reader t)
(is-start :bool :reader t)
(limit-batches "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
@ -2657,7 +2539,7 @@ stream is importing.")
cpp<#)
(:private
#>cpp StartStopStream() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class start-stop-all-streams (logical-operator)
((stream-name "std::string" :reader t)
@ -2680,14 +2562,12 @@ stream is importing.")
cpp<#)
(:private
#>cpp StartStopAllStreams() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:define-class test-stream (logical-operator)
((stream-name "std::string" :reader t)
(limit-batches "Expression *"
:reader t
:save-fun #'save-pointer
:load-fun #'load-pointer
:capnp-type "Ast.Tree"
:capnp-init nil
:capnp-save #'save-ast-pointer
@ -2714,54 +2594,8 @@ in the db.")
cpp<#)
(:private
#>cpp TestStream() {} cpp<#)
(:serialize :boost :capnp))
(:serialize :capnp))
(lcp:pop-namespace) ;; plan
(lcp:pop-namespace) ;; query
#>cpp
BOOST_CLASS_EXPORT_KEY(query::plan::Once);
BOOST_CLASS_EXPORT_KEY(query::plan::CreateNode);
BOOST_CLASS_EXPORT_KEY(query::plan::CreateExpand);
BOOST_CLASS_EXPORT_KEY(query::plan::ScanAll);
BOOST_CLASS_EXPORT_KEY(query::plan::ScanAllByLabel);
BOOST_CLASS_EXPORT_KEY(query::plan::ScanAllByLabelPropertyRange);
BOOST_CLASS_EXPORT_KEY(query::plan::ScanAllByLabelPropertyValue);
BOOST_CLASS_EXPORT_KEY(query::plan::Expand);
BOOST_CLASS_EXPORT_KEY(query::plan::ExpandVariable);
BOOST_CLASS_EXPORT_KEY(query::plan::Filter);
BOOST_CLASS_EXPORT_KEY(query::plan::Produce);
BOOST_CLASS_EXPORT_KEY(query::plan::ConstructNamedPath);
BOOST_CLASS_EXPORT_KEY(query::plan::Delete);
BOOST_CLASS_EXPORT_KEY(query::plan::SetProperty);
BOOST_CLASS_EXPORT_KEY(query::plan::SetProperties);
BOOST_CLASS_EXPORT_KEY(query::plan::SetLabels);
BOOST_CLASS_EXPORT_KEY(query::plan::RemoveProperty);
BOOST_CLASS_EXPORT_KEY(query::plan::RemoveLabels);
BOOST_CLASS_EXPORT_KEY(query::plan::ExpandUniquenessFilter<EdgeAccessor>);
BOOST_CLASS_EXPORT_KEY(query::plan::ExpandUniquenessFilter<VertexAccessor>);
BOOST_CLASS_EXPORT_KEY(query::plan::Accumulate);
BOOST_CLASS_EXPORT_KEY(query::plan::Aggregate);
BOOST_CLASS_EXPORT_KEY(query::plan::Skip);
BOOST_CLASS_EXPORT_KEY(query::plan::Limit);
BOOST_CLASS_EXPORT_KEY(query::plan::OrderBy);
BOOST_CLASS_EXPORT_KEY(query::plan::Merge);
BOOST_CLASS_EXPORT_KEY(query::plan::Optional);
BOOST_CLASS_EXPORT_KEY(query::plan::Unwind);
BOOST_CLASS_EXPORT_KEY(query::plan::Distinct);
BOOST_CLASS_EXPORT_KEY(query::plan::CreateIndex);
BOOST_CLASS_EXPORT_KEY(query::plan::Union);
BOOST_CLASS_EXPORT_KEY(query::plan::PullRemote);
BOOST_CLASS_EXPORT_KEY(query::plan::Synchronize);
BOOST_CLASS_EXPORT_KEY(query::plan::Cartesian);
BOOST_CLASS_EXPORT_KEY(query::plan::PullRemoteOrderBy);
BOOST_CLASS_EXPORT_KEY(query::plan::ModifyUser);
BOOST_CLASS_EXPORT_KEY(query::plan::DropUser);
BOOST_CLASS_EXPORT_KEY(query::plan::CreateStream);
BOOST_CLASS_EXPORT_KEY(query::plan::DropStream);
BOOST_CLASS_EXPORT_KEY(query::plan::ShowStreams);
BOOST_CLASS_EXPORT_KEY(query::plan::StartStopStream);
BOOST_CLASS_EXPORT_KEY(query::plan::StartStopAllStreams);
BOOST_CLASS_EXPORT_KEY(query::plan::TestStream);
cpp<#

View File

@ -4,7 +4,6 @@
#include <functional>
#include <limits>
#include "boost/serialization/base_object.hpp"
#include "glog/logging.h"
#include "storage/serialization.capnp.h"
@ -37,7 +36,6 @@ class Common : public utils::TotalOrdering<TSpecificType> {
// TODO implement throw and error handling
CHECK(id <= Mask) << "Number of used ids overflowed!";
}
virtual ~Common() {}
friend bool operator==(const TSpecificType &a, const TSpecificType &b) {
return a.Id() == b.Id();
@ -56,63 +54,37 @@ class Common : public utils::TotalOrdering<TSpecificType> {
size_t operator()(const TSpecificType &t) const { return hash(t.id_); }
};
virtual void Save(capnp::Common::Builder *builder) const {
void Save(capnp::Common::Builder *builder) const {
builder->setStorage(id_);
}
virtual void Load(const capnp::Common::Reader &reader) {
void Load(const capnp::Common::Reader &reader) {
id_ = reader.getStorage();
}
protected:
~Common() {}
private:
static constexpr IdT Mask = std::numeric_limits<IdT>::max() >> 1;
static constexpr IdT NotMask = ~Mask;
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &id_;
}
IdT id_{0};
};
class Label : public Common<Label> {
class Label final : public Common<Label> {
using Common::Common;
private:
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &boost::serialization::base_object<Common<Label>>(*this);
}
};
class EdgeType : public Common<EdgeType> {
class EdgeType final : public Common<EdgeType> {
using Common::Common;
private:
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &boost::serialization::base_object<Common<EdgeType>>(*this);
}
};
class Property : public Common<Property> {
class Property final : public Common<Property> {
using Common::Common;
private:
friend class boost::serialization::access;
template <class TArchive>
void serialize(TArchive &ar, const unsigned int) {
ar &boost::serialization::base_object<Common<Property>>(*this);
}
};
}; // namespace storage
} // namespace storage
namespace std {

View File

@ -2,10 +2,6 @@
#include <experimental/optional>
#include "boost/serialization/optional.hpp"
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/split_free.hpp"
#include "distributed/serialization.capnp.h"
#include "query/typed_value.hpp"
#include "storage/edge.hpp"
@ -13,57 +9,6 @@
#include "utils/exceptions.hpp"
#include "utils/serialization.capnp.h"
namespace boost::serialization {
namespace {
template <size_t idx, class TArchive, class... Elements>
void tuple_serialization_helper(TArchive &ar, std::tuple<Elements...> &tup) {
if constexpr (idx < sizeof...(Elements)) {
ar &std::get<idx>(tup);
tuple_serialization_helper<idx + 1, TArchive, Elements...>(ar, tup);
}
}
} // namespace
template <class TArchive, class... Elements>
inline void serialize(TArchive &ar, std::tuple<Elements...> &tup,
unsigned int) {
tuple_serialization_helper<0, TArchive, Elements...>(ar, tup);
}
template <class TArchive, class T>
inline void serialize(TArchive &ar, std::experimental::optional<T> &opt,
unsigned int version) {
split_free(ar, opt, version);
}
template <class TArchive, class T>
void save(TArchive &ar, const std::experimental::optional<T> &opt,
unsigned int) {
ar << static_cast<bool>(opt);
if (opt) {
ar << *opt;
}
}
template <class TArchive, class T>
void load(TArchive &ar, std::experimental::optional<T> &opt,
unsigned int version) {
bool has_value;
ar >> has_value;
if (has_value) {
detail::stack_construct<TArchive, T> tmp(ar, version);
ar >> tmp.reference();
opt = std::move(tmp.reference());
} else {
opt = std::experimental::nullopt;
}
}
} // namespace boost::serialization
namespace utils {
inline void SaveCapnpTypedValue(
@ -204,7 +149,8 @@ inline void LoadVector(
std::vector<std::string> *data,
const typename ::capnp::List<::capnp::Text>::Reader &list_reader) {
for (const auto e : list_reader) {
data->emplace_back(e); }
data->emplace_back(e);
}
}
template <typename TCapnp, typename T>
@ -298,7 +244,7 @@ inline void SaveUniquePtr(
template <typename TCapnp, typename T>
inline std::unique_ptr<T> LoadUniquePtr(
const typename capnp::UniquePtr<TCapnp>::Reader &reader,
const std::function<T*(const typename TCapnp::Reader &reader)> &load) {
const std::function<T *(const typename TCapnp::Reader &reader)> &load) {
switch (reader.which()) {
case capnp::UniquePtr<TCapnp>::NULLPTR:
return nullptr;
@ -356,134 +302,4 @@ std::shared_ptr<T> LoadSharedPtr(
return ret;
}
/**
* Saves the given value into the given Boost archive. The optional
* `save_graph_element` function is called if the given `value` is a
* [Vertex|Edge|Path]. If that function is not provided, and `value` is one of
* those, an exception is thrown.
*/
template <class TArchive>
void SaveTypedValue(
TArchive &ar, const query::TypedValue &value,
std::function<void(TArchive &ar, const query::TypedValue &value)>
save_graph_element = nullptr) {
ar << value.type();
switch (value.type()) {
case query::TypedValue::Type::Null:
return;
case query::TypedValue::Type::Bool:
ar << value.Value<bool>();
return;
case query::TypedValue::Type::Int:
ar << value.Value<int64_t>();
return;
case query::TypedValue::Type::Double:
ar << value.Value<double>();
return;
case query::TypedValue::Type::String:
ar << value.Value<std::string>();
return;
case query::TypedValue::Type::List: {
const auto &values = value.Value<std::vector<query::TypedValue>>();
ar << values.size();
for (const auto &v : values) {
SaveTypedValue(ar, v, save_graph_element);
}
return;
}
case query::TypedValue::Type::Map: {
const auto &map = value.Value<std::map<std::string, query::TypedValue>>();
ar << map.size();
for (const auto &key_value : map) {
ar << key_value.first;
SaveTypedValue(ar, key_value.second, save_graph_element);
}
return;
}
case query::TypedValue::Type::Vertex:
case query::TypedValue::Type::Edge:
case query::TypedValue::Type::Path:
if (save_graph_element) {
save_graph_element(ar, value);
} else {
throw utils::BasicException("Unable to archive TypedValue of type: {}",
value.type());
}
}
}
/** Loads a typed value into the given reference from the given archive. The
* optional `load_graph_element` function is called if a [Vertex|Edge|Path]
* TypedValue should be unarchived. If that function is not provided, and
* `value` is one of those, an exception is thrown.
*/
template <class TArchive>
void LoadTypedValue(TArchive &ar, query::TypedValue &value,
std::function<void(TArchive &ar, query::TypedValue::Type,
query::TypedValue &)>
load_graph_element = nullptr) {
query::TypedValue::Type type = query::TypedValue::Type::Null;
ar >> type;
switch (type) {
case query::TypedValue::Type::Null:
return;
case query::TypedValue::Type::Bool: {
bool v;
ar >> v;
value = v;
return;
}
case query::TypedValue::Type::Int: {
int64_t v;
ar >> v;
value = v;
return;
}
case query::TypedValue::Type::Double: {
double v;
ar >> v;
value = v;
return;
}
case query::TypedValue::Type::String: {
std::string v;
ar >> v;
value = v;
return;
}
case query::TypedValue::Type::List: {
value = std::vector<query::TypedValue>{};
auto &list = value.ValueList();
size_t size;
ar >> size;
list.reserve(size);
for (size_t i = 0; i < size; ++i) {
list.emplace_back();
LoadTypedValue(ar, list.back(), load_graph_element);
}
return;
}
case query::TypedValue::Type::Map: {
value = std::map<std::string, query::TypedValue>{};
auto &map = value.ValueMap();
size_t size;
ar >> size;
for (size_t i = 0; i < size; ++i) {
std::string key;
ar >> key;
LoadTypedValue(ar, map[key], load_graph_element);
}
return;
}
case query::TypedValue::Type::Vertex:
case query::TypedValue::Type::Edge:
case query::TypedValue::Type::Path:
if (load_graph_element) {
load_graph_element(ar, type, value);
} else {
throw utils::BasicException(
"Unexpected TypedValue type '{}' when loading from archive", type);
}
}
}
} // namespace utils

View File

@ -3,10 +3,6 @@
#include <benchmark/benchmark.h>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/serialization/vector.hpp"
#include <capnp/serialize.h>
#include <kj/std/iostream.h>
@ -33,39 +29,6 @@ class SymbolVectorFixture : public benchmark::Fixture {
void TearDown(const benchmark::State &) override { symbols_.clear(); }
};
BENCHMARK_DEFINE_F(SymbolVectorFixture, BoostSerial)(benchmark::State &state) {
while (state.KeepRunning()) {
std::stringstream stream(std::ios_base::out | std::ios_base::binary);
{
boost::archive::binary_oarchive archive(stream);
archive << symbols_;
}
}
}
BENCHMARK_DEFINE_F(SymbolVectorFixture, BoostDeserial)
(benchmark::State &state) {
auto serialize = [this]() {
std::stringstream stream(std::ios_base::in | std::ios_base::out |
std::ios_base::binary);
{
boost::archive::binary_oarchive archive(stream);
archive << symbols_;
}
return stream;
};
while (state.KeepRunning()) {
state.PauseTiming();
auto stream = serialize();
state.ResumeTiming();
std::vector<query::Symbol> symbols;
{
boost::archive::binary_iarchive archive(stream);
archive >> symbols;
}
}
}
void SymbolVectorToCapnpMessage(const std::vector<query::Symbol> &symbols,
capnp::MessageBuilder &message) {
auto symbols_builder =
@ -120,21 +83,11 @@ BENCHMARK_DEFINE_F(SymbolVectorFixture, CapnpDeserial)
}
}
BENCHMARK_REGISTER_F(SymbolVectorFixture, BoostSerial)
->RangeMultiplier(4)
->Range(4, 1 << 12)
->Unit(benchmark::kNanosecond);
BENCHMARK_REGISTER_F(SymbolVectorFixture, CapnpSerial)
->RangeMultiplier(4)
->Range(4, 1 << 12)
->Unit(benchmark::kNanosecond);
BENCHMARK_REGISTER_F(SymbolVectorFixture, BoostDeserial)
->RangeMultiplier(4)
->Range(4, 1 << 12)
->Unit(benchmark::kNanosecond);
BENCHMARK_REGISTER_F(SymbolVectorFixture, CapnpDeserial)
->RangeMultiplier(4)
->Range(4, 1 << 12)

View File

@ -6,8 +6,6 @@
#include <vector>
#include "antlr4-runtime.h"
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@ -113,33 +111,6 @@ class CachedAstGenerator : public Base {
Query *query_;
};
// This generator serializes the parsed ast and uses the deserialized one.
class SerializedAstGenerator : public Base {
public:
SerializedAstGenerator(const std::string &query)
: Base(query),
storage_([&]() {
::frontend::opencypher::Parser parser(query);
CypherMainVisitor visitor(context_);
visitor.visit(parser.tree());
std::stringstream stream;
{
boost::archive::binary_oarchive out_archive(stream);
out_archive << *visitor.query();
}
AstStorage new_ast;
{
boost::archive::binary_iarchive in_archive(stream);
new_ast.Load(in_archive);
}
return new_ast;
}()),
query_(storage_.query()) {}
AstStorage storage_;
Query *query_;
};
class CapnpAstGenerator : public Base {
public:
CapnpAstGenerator(const std::string &query)
@ -177,7 +148,7 @@ class CypherMainVisitorTest : public ::testing::Test {};
typedef ::testing::Types<AstGenerator, OriginalAfterCloningAstGenerator,
ClonedAstGenerator, CachedAstGenerator,
SerializedAstGenerator, CapnpAstGenerator>
CapnpAstGenerator>
AstGeneratorTypes;
TYPED_TEST_CASE(CypherMainVisitorTest, AstGeneratorTypes);

View File

@ -1,8 +1,7 @@
#include <gtest/gtest.h>
#include <sstream>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include <capnp/message.h>
#include "distributed/serialization.hpp"
#include "mvcc/version_list.hpp"
@ -69,15 +68,14 @@ bool CheckEdge(const Edge &e1, int w1, const Edge &e2, int w2) {
#undef CHECK_RETURN
#define SAVE_AND_LOAD(type, name, element) \
std::unique_ptr<type> name; \
{ \
std::ostringstream ostream; \
boost::archive::binary_oarchive oar{ostream}; \
distributed::Save##type(oar, element, 0); \
std::istringstream istream{ostream.str()}; \
boost::archive::binary_iarchive iar{istream}; \
name = distributed::Load##type(iar); \
#define SAVE_AND_LOAD(type, name, element) \
std::unique_ptr<type> name; \
{ \
::capnp::MallocMessageBuilder message; \
auto builder = message.initRoot<distributed::capnp::type>(); \
distributed::Save##type(element, &builder, 0); \
auto reader = message.getRoot<distributed::capnp::type>(); \
name = distributed::Load##type(reader); \
}
TEST(DistributedSerialization, Empty) {

View File

@ -5,10 +5,8 @@
#include <typeinfo>
#include <unordered_set>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "query/frontend/ast/ast.hpp"
#include "query/frontend/semantic/symbol_generator.hpp"
@ -17,7 +15,7 @@
#include "query/plan/operator.hpp"
#include "query/plan/planner.hpp"
#include "capnp/message.h"
#include <capnp/message.h>
#include "query/plan/operator.capnp.h"
#include "query_common.hpp"
@ -655,31 +653,6 @@ class ExpectDropUser : public OpChecker<DropUser> {
std::vector<std::string> usernames_;
};
class SerializedPlanner {
public:
template <class TDbAccessor>
SerializedPlanner(std::vector<SingleQueryPart> single_query_parts,
PlanningContext<TDbAccessor> &context) {
std::stringstream stream;
{
auto original_plan = MakeLogicalPlanForSingleQuery<RuleBasedPlanner>(
single_query_parts, context);
boost::archive::binary_oarchive out_archive(stream);
out_archive << original_plan;
}
{
boost::archive::binary_iarchive in_archive(stream);
std::tie(plan_, ast_storage_) = LoadPlan(in_archive);
}
}
auto &plan() { return *plan_; }
private:
AstStorage ast_storage_;
std::unique_ptr<LogicalOperator> plan_;
};
void SavePlan(const LogicalOperator &plan, ::capnp::MessageBuilder *message) {
auto builder = message->initRoot<query::plan::capnp::LogicalOperator>();
LogicalOperator::SaveHelper helper;
@ -928,7 +901,7 @@ ExpectedDistributedPlan ExpectDistributed(
template <class T>
class TestPlanner : public ::testing::Test {};
using PlannerTypes = ::testing::Types<Planner, SerializedPlanner, CapnpPlanner>;
using PlannerTypes = ::testing::Types<Planner, CapnpPlanner>;
TYPED_TEST_CASE(TestPlanner, PlannerTypes);

View File

@ -1,8 +1,6 @@
#include <memory>
#include <sstream>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "gtest/gtest.h"
#include "database/graph_db.hpp"
@ -1116,25 +1114,3 @@ TEST_F(TestSymbolGenerator, MatchUnion) {
query->Accept(symbol_generator);
EXPECT_EQ(symbol_table.max_position(), 8);
}
TEST(TestSymbolTable, Serialization) {
SymbolTable original_table;
SymbolGenerator symbol_generator{original_table};
AstStorage storage;
auto ident_a = IDENT("a");
auto sym_a = original_table.CreateSymbol("a", true, Symbol::Type::Vertex, 0);
original_table[*ident_a] = sym_a;
auto ident_b = IDENT("b");
auto sym_b = original_table.CreateSymbol("b", false, Symbol::Type::Edge, 1);
original_table[*ident_b] = sym_b;
std::stringstream stream;
{
boost::archive::binary_oarchive out_archive(stream);
out_archive << original_table;
}
SymbolTable serialized_table;
boost::archive::binary_iarchive in_archive(stream);
in_archive >> serialized_table;
EXPECT_EQ(serialized_table.max_position(), original_table.max_position());
EXPECT_EQ(serialized_table.table(), original_table.table());
}

View File

@ -3,67 +3,12 @@
#include "gtest/gtest.h"
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "capnp/message.h"
#include "utils/serialization.hpp"
using std::experimental::optional;
using std::string_literals::operator""s;
TEST(Serialization, Optional) {
std::stringstream ss;
optional<int> x1 = {};
optional<int> x2 = 42;
optional<int> y1, y2;
{
boost::archive::binary_oarchive ar(ss);
ar << x1;
ar << x2;
}
{
boost::archive::binary_iarchive ar(ss);
ar >> y1;
ar >> y2;
}
EXPECT_EQ(x1, y1);
EXPECT_EQ(x2, y2);
}
TEST(Serialization, Tuple) {
std::stringstream ss;
auto x1 = std::make_tuple("foo"s, 42, std::experimental::make_optional(3.14));
auto x2 = std::make_tuple();
auto x3 = std::make_tuple(1, 2, 3, 4, 5);
decltype(x1) y1;
decltype(x2) y2;
decltype(x3) y3;
{
boost::archive::binary_oarchive ar(ss);
ar << x1;
ar << x2;
ar << x3;
}
{
boost::archive::binary_iarchive ar(ss);
ar >> y1;
ar >> y2;
ar >> y3;
}
EXPECT_EQ(x1, y1);
EXPECT_EQ(x2, y2);
EXPECT_EQ(x3, y3);
}
void CheckOptionalInt(const std::experimental::optional<int> &x1) {
::capnp::MallocMessageBuilder message;
std::experimental::optional<int> y1;