Serialize SymbolTable

Summary:
Other than the plan operators and the frame, we will need to pass the
generated symbol table to distributed workers.

Reviewers: florijan, msantl

Reviewed By: florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1123
This commit is contained in:
Teon Banek 2018-01-22 11:01:20 +01:00
parent 1953f3563f
commit 2a8c64882f
2 changed files with 37 additions and 1 deletions

View File

@ -3,12 +3,15 @@
#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.hpp"
namespace query {
class SymbolTable {
class SymbolTable final {
public:
SymbolTable() {}
Symbol CreateSymbol(const std::string &name, bool user_declared,
@ -30,6 +33,14 @@ class SymbolTable {
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

@ -1,5 +1,8 @@
#include <memory>
#include <sstream>
#include "boost/archive/binary_iarchive.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "gtest/gtest.h"
#include "query/frontend/ast/ast.hpp"
@ -980,3 +983,25 @@ 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};
AstTreeStorage 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());
}