From a3da7cd5a82d27e343249c7a9bcb516be605f42e Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Thu, 30 Mar 2017 08:44:56 +0200 Subject: [PATCH] Plan Remove operators Reviewers: florijan, mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D203 --- src/query/frontend/logical/planner.cpp | 8 ++++++++ tests/unit/query_common.hpp | 16 ++++++++++++++++ tests/unit/query_planner.cpp | 15 +++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/query/frontend/logical/planner.cpp b/src/query/frontend/logical/planner.cpp index 1fc7d24f8..543bec97e 100644 --- a/src/query/frontend/logical/planner.cpp +++ b/src/query/frontend/logical/planner.cpp @@ -200,6 +200,14 @@ std::unique_ptr MakeLogicalPlan( const auto &input_symbol = symbol_table.at(*set->identifier_); input_op = new plan::SetLabels(std::shared_ptr(input_op), input_symbol, set->labels_); + } else if (auto *rem = dynamic_cast(clause_ptr)) { + input_op = new plan::RemoveProperty( + std::shared_ptr(input_op), rem->property_lookup_); + } else if (auto *rem = dynamic_cast(clause_ptr)) { + const auto &input_symbol = symbol_table.at(*rem->identifier_); + input_op = + new plan::RemoveLabels(std::shared_ptr(input_op), + input_symbol, rem->labels_); } else { throw NotYetImplemented(); } diff --git a/tests/unit/query_common.hpp b/tests/unit/query_common.hpp index 329385683..1e22026e4 100644 --- a/tests/unit/query_common.hpp +++ b/tests/unit/query_common.hpp @@ -162,6 +162,21 @@ auto GetSet(AstTreeStorage &storage, const std::string &name, return storage.Create(storage.Create(name), labels); } +/// +/// Create a remove property clause for given property lookup +/// +auto GetRemove(AstTreeStorage &storage, PropertyLookup *prop_lookup) { + return storage.Create(prop_lookup); +} + +/// +/// Create a remove labels clause for given identifier name and labels. +/// +auto GetRemove(AstTreeStorage &storage, const std::string &name, + std::vector labels) { + return storage.Create(storage.Create(name), labels); +} + } // namespace test_common } // namespace query @@ -200,5 +215,6 @@ auto GetSet(AstTreeStorage &storage, const std::string &name, #define DETACH_DELETE(...) \ query::test_common::GetDelete(storage, {__VA_ARGS__}, true) #define SET(...) query::test_common::GetSet(storage, __VA_ARGS__) +#define REMOVE(...) query::test_common::GetRemove(storage, __VA_ARGS__) #define QUERY(...) query::test_common::GetQuery(storage, __VA_ARGS__) #define LESS(expr1, expr2) storage.Create((expr1), (expr2)) diff --git a/tests/unit/query_planner.cpp b/tests/unit/query_planner.cpp index 7539f0cb1..d2d4218d3 100644 --- a/tests/unit/query_planner.cpp +++ b/tests/unit/query_planner.cpp @@ -38,6 +38,8 @@ class PlanChecker : public LogicalOperatorVisitor { void Visit(SetProperty &op) override { AssertType(op); } void Visit(SetProperties &op) override { AssertType(op); } void Visit(SetLabels &op) override { AssertType(op); } + void Visit(RemoveProperty &op) override { AssertType(op); } + void Visit(RemoveLabels &op) override { AssertType(op); } private: void AssertType(const LogicalOperator &op) { @@ -168,4 +170,17 @@ TEST(TestLogicalPlanner, MatchNodeSet) { typeid(SetProperties).hash_code(), typeid(SetLabels).hash_code()}); } +TEST(TestLogicalPlanner, MatchRemove) { + // Test MATCH (n) REMOVE n.prop REMOVE n :label + AstTreeStorage storage; + std::string prop("prop"); + std::string label("label"); + auto query = + QUERY(MATCH(PATTERN(NODE("n"))), REMOVE(PROPERTY_LOOKUP("n", &prop)), + REMOVE("n", {&label})); + CheckPlan(*query, + {typeid(ScanAll).hash_code(), typeid(RemoveProperty).hash_code(), + typeid(RemoveLabels).hash_code()}); +} + }