Clone AST using LCP

Summary:
use newly added LCP functionality to get rid of manually written
`Clone` functions in AST.

depends on D1808

Reviewers: teon.banek, llugovic

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1815
This commit is contained in:
Marin Tomic 2019-01-17 11:43:28 +01:00
parent 903263d896
commit f9c63987c6
6 changed files with 196 additions and 458 deletions

View File

@ -27,7 +27,6 @@ set(mg_single_node_sources
glue/auth.cpp
glue/communication.cpp
query/common.cpp
query/frontend/ast/ast.cpp
query/frontend/ast/pretty_print.cpp
query/frontend/ast/cypher_main_visitor.cpp
query/frontend/semantic/required_privileges.cpp
@ -134,7 +133,6 @@ set(mg_distributed_sources
glue/auth.cpp
glue/communication.cpp
query/common.cpp
query/frontend/ast/ast.cpp
query/frontend/ast/pretty_print.cpp
query/frontend/ast/cypher_main_visitor.cpp
query/frontend/semantic/required_privileges.cpp
@ -264,7 +262,6 @@ set(mg_single_node_ha_sources
raft/coordination.cpp
raft/raft_server.cpp
query/common.cpp
query/frontend/ast/ast.cpp
query/frontend/ast/cypher_main_visitor.cpp
query/frontend/semantic/required_privileges.cpp
query/frontend/semantic/symbol_generator.cpp

View File

@ -1,23 +0,0 @@
#include "query/frontend/ast/ast.hpp"
#include <algorithm>
namespace query {
ReturnBody CloneReturnBody(AstStorage &storage, const ReturnBody &body) {
ReturnBody new_body;
new_body.distinct = body.distinct;
new_body.all_identifiers = body.all_identifiers;
for (auto *named_expr : body.named_expressions) {
new_body.named_expressions.push_back(named_expr->Clone(storage));
}
for (auto order : body.order_by) {
new_body.order_by.push_back(
SortItem{order.ordering, order.expression->Clone(storage)});
}
new_body.skip = body.skip ? body.skip->Clone(storage) : nullptr;
new_body.limit = body.limit ? body.limit->Clone(storage) : nullptr;
return new_body;
}
} // namespace query

File diff suppressed because it is too large Load Diff

View File

@ -899,7 +899,7 @@ Interpreter::ParsedQuery Interpreter::ParseQuery(
ast_storage->properties_ = ast_it->second.ast_storage.properties_;
ast_storage->labels_ = ast_it->second.ast_storage.labels_;
ast_storage->edge_types_ = ast_it->second.ast_storage.edge_types_;
return ParsedQuery{ast_it->second.query->Clone(*ast_storage),
return ParsedQuery{ast_it->second.query->Clone(ast_storage),
ast_it->second.required_privileges};
}

View File

@ -251,7 +251,8 @@ void Filters::CollectPatternFilters(Pattern &pattern, SymbolTable &symbol_table,
collector.symbols_.insert(symbol); // PropertyLookup uses the symbol.
// Now handle the post-expansion filter.
// Create a new identifier and a symbol which will be filled in All.
auto *identifier = atom->identifier_->Clone(storage);
auto *identifier = storage.Create<Identifier>(
atom->identifier_->name_, atom->identifier_->user_declared_);
symbol_table[*identifier] =
symbol_table.CreateSymbol(identifier->name_, false);
// Create an equality expression and store it in all_filters_.

View File

@ -102,7 +102,7 @@ class OriginalAfterCloningAstGenerator : public AstGenerator {
explicit OriginalAfterCloningAstGenerator(const std::string &query)
: AstGenerator(query) {
AstStorage storage;
query_->Clone(storage);
query_->Clone(&storage);
}
PropertyIx Prop(const std::string &prop_name) override {
@ -126,9 +126,16 @@ class ClonedAstGenerator : public Base {
explicit ClonedAstGenerator(const std::string &query) : Base(query) {
::frontend::opencypher::Parser parser(query);
AstStorage tmp_storage;
{
// Add a label, property and edge type into temporary storage so
// indices have to change in cloned AST.
tmp_storage.GetLabelIx("jkfdklajfkdalsj");
tmp_storage.GetPropertyIx("fdjakfjdklfjdaslk");
tmp_storage.GetEdgeTypeIx("fdjkalfjdlkajfdkla");
}
CypherMainVisitor visitor(context_, &tmp_storage);
visitor.visit(parser.tree());
query_ = visitor.query()->Clone(ast_storage_);
query_ = visitor.query()->Clone(&ast_storage_);
}
PropertyIx Prop(const std::string &prop_name) override {
@ -159,7 +166,7 @@ class CachedAstGenerator : public Base {
AstStorage tmp_storage;
CypherMainVisitor visitor(context_, &tmp_storage);
visitor.visit(parser.tree());
query_ = visitor.query()->Clone(ast_storage_);
query_ = visitor.query()->Clone(&ast_storage_);
}
PropertyIx Prop(const std::string &prop_name) override {