Plan Remove operators

Reviewers: florijan, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D203
This commit is contained in:
Teon Banek 2017-03-30 08:44:56 +02:00
parent 078b50a154
commit a3da7cd5a8
3 changed files with 39 additions and 0 deletions

View File

@ -200,6 +200,14 @@ std::unique_ptr<LogicalOperator> MakeLogicalPlan(
const auto &input_symbol = symbol_table.at(*set->identifier_);
input_op = new plan::SetLabels(std::shared_ptr<LogicalOperator>(input_op),
input_symbol, set->labels_);
} else if (auto *rem = dynamic_cast<query::RemoveProperty *>(clause_ptr)) {
input_op = new plan::RemoveProperty(
std::shared_ptr<LogicalOperator>(input_op), rem->property_lookup_);
} else if (auto *rem = dynamic_cast<query::RemoveLabels *>(clause_ptr)) {
const auto &input_symbol = symbol_table.at(*rem->identifier_);
input_op =
new plan::RemoveLabels(std::shared_ptr<LogicalOperator>(input_op),
input_symbol, rem->labels_);
} else {
throw NotYetImplemented();
}

View File

@ -162,6 +162,21 @@ auto GetSet(AstTreeStorage &storage, const std::string &name,
return storage.Create<SetLabels>(storage.Create<Identifier>(name), labels);
}
///
/// Create a remove property clause for given property lookup
///
auto GetRemove(AstTreeStorage &storage, PropertyLookup *prop_lookup) {
return storage.Create<RemoveProperty>(prop_lookup);
}
///
/// Create a remove labels clause for given identifier name and labels.
///
auto GetRemove(AstTreeStorage &storage, const std::string &name,
std::vector<GraphDbTypes::Label> labels) {
return storage.Create<RemoveLabels>(storage.Create<Identifier>(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<query::LessOperator>((expr1), (expr2))

View File

@ -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()});
}
}