Test ExpandVariable reverses on Direction::BOTH

Summary: Add `is_flipped` to `Expansion`

Reviewers: florijan, mislav.bradac

Reviewed By: mislav.bradac

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D744
This commit is contained in:
Teon Banek 2017-09-04 14:09:24 +02:00
parent 65c6b50ade
commit d584a7b18b
4 changed files with 33 additions and 3 deletions

View File

@ -530,7 +530,7 @@ std::vector<Expansion> NormalizePatterns(
collector.symbols_.erase(
symbol_table.at(*bf_atom->next_node_identifier_));
}
expansions.emplace_back(Expansion{prev_node, edge, edge->direction_,
expansions.emplace_back(Expansion{prev_node, edge, edge->direction_, false,
collector.symbols_, current_node});
};
for (const auto &pattern : patterns) {

View File

@ -15,6 +15,8 @@ struct Expansion {
/// Direction of the edge, it may be flipped compared to original
/// @c EdgeAtom during plan generation.
EdgeAtom::Direction direction = EdgeAtom::Direction::BOTH;
/// True if the direction and nodes were flipped.
bool is_flipped = false;
/// Set of symbols found inside the range expressions of a variable path edge.
std::unordered_set<Symbol> symbols_in_range{};
/// Optional node at the other end of an edge. If the expansion
@ -489,8 +491,8 @@ class RuleBasedPlanner {
bound_symbols, node_symbol, all_filters, storage);
last_op = new ExpandVariable(
node_symbol, edge_symbol, expansion.direction,
expansion.direction != expansion.edge->direction_,
expansion.edge->lower_bound_, expansion.edge->upper_bound_,
expansion.is_flipped, expansion.edge->lower_bound_,
expansion.edge->upper_bound_,
std::shared_ptr<LogicalOperator>(last_op), node1_symbol,
existing_node, existing_edge, match_context.graph_view,
filter_expr);

View File

@ -96,6 +96,7 @@ void AddNextExpansions(
if (!dynamic_cast<BreadthFirstAtom *>(expansion.edge)) {
// BFS must *not* be flipped. Doing that changes the BFS results.
std::swap(expansion.node1, expansion.node2);
expansion.is_flipped = true;
if (expansion.direction != EdgeAtom::Direction::BOTH) {
expansion.direction = expansion.direction == EdgeAtom::Direction::IN
? EdgeAtom::Direction::OUT

View File

@ -263,6 +263,33 @@ TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) {
});
}
TEST(TestVariableStartPlanner, MatchVariableExpandBoth) {
Dbms dbms;
auto dba = dbms.active();
auto id = dba->Property("id");
// Graph (v1 {id:1}) -[:r1]-> (v2) -[:r2]-> (v3)
auto v1 = dba->InsertVertex();
v1.PropsSet(id, 1);
auto v2 = dba->InsertVertex();
auto v3 = dba->InsertVertex();
auto r1 = dba->InsertEdge(v1, v2, dba->EdgeType("r1"));
auto r2 = dba->InsertEdge(v2, v3, dba->EdgeType("r2"));
dba->AdvanceCommand();
// Test MATCH (n {id:1}) -[r*]- (m) RETURN r
AstTreeStorage storage;
auto edge = EDGE("r", Direction::BOTH);
edge->has_range_ = true;
auto node_n = NODE("n");
node_n->properties_[std::make_pair("id", id)] = LITERAL(1);
QUERY(MATCH(PATTERN(node_n, edge, NODE("m"))), RETURN("r"));
// We expect to get a single column with the following rows:
TypedValue r1_list(std::vector<TypedValue>{r1}); // [r1]
TypedValue r1_r2_list(std::vector<TypedValue>{r1, r2}); // [r1, r2]
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
AssertRows(results, {{r1_list}, {r1_r2_list}});
});
}
TEST(TestVariableStartPlanner, MatchBfs) {
Dbms dbms;
auto dba = dbms.active();