Plan CreateIndex operator

Reviewers: florijan, mislav.bradac, buda

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D525
This commit is contained in:
Teon Banek 2017-07-06 11:32:28 +02:00
parent cbe6648eb8
commit 9fbaf69441
3 changed files with 33 additions and 0 deletions

View File

@ -914,6 +914,11 @@ std::unique_ptr<LogicalOperator> RuleBasedPlanner::Plan(
input_op =
new plan::Unwind(std::shared_ptr<LogicalOperator>(input_op),
unwind->named_expression_->expression_, symbol);
} else if (auto *create_index =
dynamic_cast<query::CreateIndex *>(clause)) {
debug_assert(!input_op, "Unexpected operator before CreateIndex");
input_op = new plan::CreateIndex(create_index->label_,
create_index->property_);
} else {
throw utils::NotYetImplemented(
"Encountered a clause which cannot be converted to operator(s)");

View File

@ -455,6 +455,8 @@ auto GetMerge(AstTreeStorage &storage, Pattern *pattern, OnMatch on_match,
query::test_common::OnCreate { \
std::vector<query::Clause *> { __VA_ARGS__ } \
}
#define CREATE_INDEX_ON(label, property) \
storage.Create<query::CreateIndex>((label), (property))
#define QUERY(...) query::test_common::GetQuery(storage, __VA_ARGS__)
// Various operators
#define ADD(expr1, expr2) \

View File

@ -208,6 +208,21 @@ class ExpectOptional : public OpChecker<Optional> {
const std::list<BaseOpChecker *> &optional_;
};
class ExpectCreateIndex : public OpChecker<CreateIndex> {
public:
ExpectCreateIndex(GraphDbTypes::Label label, GraphDbTypes::Property property)
: label_(label), property_(property) {}
void ExpectOp(CreateIndex &create_index, const SymbolTable &) override {
EXPECT_EQ(create_index.label(), label_);
EXPECT_EQ(create_index.property(), property_);
}
private:
GraphDbTypes::Label label_;
GraphDbTypes::Property property_;
};
auto MakeSymbolTable(query::Query &query) {
SymbolTable symbol_table;
SymbolGenerator symbol_generator(symbol_table);
@ -910,4 +925,15 @@ TEST(TestLogicalPlanner, ListSliceAggregationReturn) {
CheckPlan(storage, aggr, ExpectProduce());
}
TEST(TestLogicalPlanner, CreateIndex) {
// Test CREATE INDEX ON :label(property)
Dbms dbms;
auto dba = dbms.active();
auto label = dba->label("label");
auto property = dba->property("property");
AstTreeStorage storage;
QUERY(CREATE_INDEX_ON(label, property));
CheckPlan(storage, ExpectCreateIndex(label, property));
}
} // namespace