Fix planning CREATE with expanding a created node
Reviewers: florijan, mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D253
This commit is contained in:
parent
7d0958b1a4
commit
9855621c9e
@ -61,7 +61,7 @@ auto ReducePattern(
|
||||
|
||||
auto GenCreateForPattern(Pattern &pattern, LogicalOperator *input_op,
|
||||
const query::SymbolTable &symbol_table,
|
||||
std::unordered_set<int> bound_symbols) {
|
||||
std::unordered_set<int> &bound_symbols) {
|
||||
auto base = [&](NodeAtom *node) -> LogicalOperator * {
|
||||
if (BindSymbol(bound_symbols, symbol_table.at(*node->identifier_)))
|
||||
return new CreateNode(node, std::shared_ptr<LogicalOperator>(input_op));
|
||||
@ -92,7 +92,7 @@ auto GenCreateForPattern(Pattern &pattern, LogicalOperator *input_op,
|
||||
|
||||
auto GenCreate(Create &create, LogicalOperator *input_op,
|
||||
const query::SymbolTable &symbol_table,
|
||||
std::unordered_set<int> bound_symbols) {
|
||||
std::unordered_set<int> &bound_symbols) {
|
||||
auto last_op = input_op;
|
||||
for (auto pattern : create.patterns_) {
|
||||
last_op =
|
||||
|
@ -279,4 +279,17 @@ TEST(TestLogicalPlanner, MatchWithWhereReturn) {
|
||||
CheckPlan<ScanAll, Accumulate, Produce, Filter, Produce>(*query);
|
||||
}
|
||||
|
||||
TEST(TestLogicalPlanner, CreateMultiExpand) {
|
||||
// Test CREATE (n) -[r :r]-> (m), (n) - [p :p]-> (l)
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
auto r = dba->edge_type("r");
|
||||
auto p = dba->edge_type("p");
|
||||
AstTreeStorage storage;
|
||||
auto query = QUERY(
|
||||
CREATE(PATTERN(NODE("n"), EDGE("r", r, Direction::RIGHT), NODE("m")),
|
||||
PATTERN(NODE("n"), EDGE("p", p, Direction::RIGHT), NODE("l"))));
|
||||
CheckPlan<CreateNode, CreateExpand, CreateExpand>(*query);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -340,4 +340,40 @@ TEST(TestSymbolGenerator, MatchWithWhereUnbound) {
|
||||
EXPECT_THROW(query->Accept(symbol_generator), UnboundVariableError);
|
||||
}
|
||||
|
||||
TEST(TestSymbolGenerator, CreateMultiExpand) {
|
||||
// Test CREATE (n) -[r :r]-> (m), (n) - [p :p]-> (l)
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
auto r_type = dba->edge_type("r");
|
||||
auto p_type = dba->edge_type("p");
|
||||
AstTreeStorage storage;
|
||||
auto node_n1 = NODE("n");
|
||||
auto edge_r = EDGE("r", r_type, EdgeAtom::Direction::RIGHT);
|
||||
auto node_m = NODE("m");
|
||||
auto node_n2 = NODE("n");
|
||||
auto edge_p = EDGE("p", p_type, EdgeAtom::Direction::RIGHT);
|
||||
auto node_l = NODE("l");
|
||||
auto query = QUERY(CREATE(PATTERN(node_n1, edge_r, node_m),
|
||||
PATTERN(node_n2, edge_p, node_l)));
|
||||
SymbolTable symbol_table;
|
||||
SymbolGenerator symbol_generator(symbol_table);
|
||||
query->Accept(symbol_generator);
|
||||
auto n1 = symbol_table.at(*node_n1->identifier_);
|
||||
auto n2 = symbol_table.at(*node_n2->identifier_);
|
||||
EXPECT_EQ(n1, n2);
|
||||
EXPECT_EQ(n1.type_, Symbol::Type::Vertex);
|
||||
auto m = symbol_table.at(*node_m->identifier_);
|
||||
EXPECT_EQ(m.type_, Symbol::Type::Vertex);
|
||||
EXPECT_NE(m, n1);
|
||||
auto l = symbol_table.at(*node_l->identifier_);
|
||||
EXPECT_EQ(l.type_, Symbol::Type::Vertex);
|
||||
EXPECT_NE(l, n1);
|
||||
EXPECT_NE(l, m);
|
||||
auto r = symbol_table.at(*edge_r->identifier_);
|
||||
auto p = symbol_table.at(*edge_p->identifier_);
|
||||
EXPECT_EQ(r.type_, Symbol::Type::Edge);
|
||||
EXPECT_EQ(p.type_, Symbol::Type::Edge);
|
||||
EXPECT_NE(r, p);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user