From 2a8c64882fe140bcb0db100e9618248c4f1b9bdf Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Mon, 22 Jan 2018 11:01:20 +0100 Subject: [PATCH] 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 --- src/query/frontend/semantic/symbol_table.hpp | 13 +++++++++- tests/unit/query_semantic.cpp | 25 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/query/frontend/semantic/symbol_table.hpp b/src/query/frontend/semantic/symbol_table.hpp index cbda97475..0499d4979 100644 --- a/src/query/frontend/semantic/symbol_table.hpp +++ b/src/query/frontend/semantic/symbol_table.hpp @@ -3,12 +3,15 @@ #include #include +#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 table_; + + friend class boost::serialization::access; + + template + void serialize(TArchive &ar, const unsigned int) { + ar &position_; + ar &table_; + } }; } // namespace query diff --git a/tests/unit/query_semantic.cpp b/tests/unit/query_semantic.cpp index 3c5718ab1..4d634b1bc 100644 --- a/tests/unit/query_semantic.cpp +++ b/tests/unit/query_semantic.cpp @@ -1,5 +1,8 @@ #include +#include +#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()); +}