Don't make an Expansion of single node if it is expanded

Summary:
We would redundantly generate an Expansion for the first node if it was part of
an expand. For example, the pattern `(n) -[r]- (m)` would generate
`Expansion{n}` and `Expansion{n, r, m}`, when only the latter is enough. This
change corrects that behaviour by dropping the first Expansion.

Reviewers: florijan, mislav.bradac

Reviewed By: florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D412
This commit is contained in:
Teon Banek 2017-05-25 15:45:03 +02:00
parent 62f6a58c32
commit d706a91b1b

View File

@ -593,15 +593,19 @@ LogicalOperator *HandleWriteClause(Clause *clause, LogicalOperator *input_op,
std::vector<Expansion> NormalizePatterns(
const std::vector<Pattern *> &patterns) {
std::vector<Expansion> expansions;
auto collect_node = [&](auto *node) {
expansions.emplace_back(Expansion{node});
};
auto ignore_node = [&](auto *node) {};
auto collect_expansion = [&](auto *prev_node, auto *edge,
auto *current_node) {
expansions.emplace_back(Expansion{prev_node, edge, current_node});
};
for (const auto &pattern : patterns) {
ForeachPattern(*pattern, collect_node, collect_expansion);
if (pattern->atoms_.size() == 1U) {
auto *node = dynamic_cast<NodeAtom *>(pattern->atoms_[0]);
debug_assert(node, "First pattern atom is not a node");
expansions.emplace_back(Expansion{node});
} else {
ForeachPattern(*pattern, ignore_node, collect_expansion);
}
}
return expansions;
}