Fix ALLSHORTEST combined with id function (#636)

This commit is contained in:
Bruno Sačarić 2022-11-04 19:36:03 +01:00 committed by GitHub
parent ff21c0705c
commit 58e6097664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -1972,7 +1972,6 @@ class ExpandAllShortestPathsCursor : public query::plan::Cursor {
edges_on_frame.emplace(edges_on_frame.begin(), current_edge);
auto next_vertex = current_edge_direction == EdgeAtom::Direction::IN ? current_edge.From() : current_edge.To();
frame[self_.common_.node_symbol] = next_vertex;
frame[self_.total_weight_.value()] = current_weight;
if (next_edges_.find({next_vertex, traversal_stack_.size()}) != next_edges_.end()) {
@ -1985,6 +1984,15 @@ class ExpandAllShortestPathsCursor : public query::plan::Cursor {
}
if ((current_weight > visited_cost_.at(next_vertex)).ValueBool()) continue;
// Place destination node on the frame, handle existence flag
if (self_.common_.existing_node) {
const auto &node = frame[self_.common_.node_symbol];
ExpectType(self_.common_.node_symbol, node, TypedValue::Type::Vertex);
if (node.ValueVertex() != next_vertex) continue;
} else {
frame[self_.common_.node_symbol] = next_vertex;
}
return true;
}

View File

@ -480,6 +480,39 @@ TEST_F(InterpreterTest, ShortestPath) {
}
}
TEST_F(InterpreterTest, AllShortestById) {
auto stream_init = Interpret(
"CREATE (n:A {x: 1}), (m:B {x: 2}), (l:C {x: 3}), (k:D {x: 4}), (n)-[:r1 {w: 1 "
"}]->(m)-[:r2 {w: 2}]->(l), (n)-[:r3 {w: 4}]->(l), (k)-[:r4 {w: 3}]->(l) return id(n), id(l)");
auto id_n = stream_init.GetResults().front()[0].ValueInt();
auto id_l = stream_init.GetResults().front()[1].ValueInt();
auto stream = Interpret(
fmt::format("MATCH (n)-[e *allshortest 5 (e, n | e.w) ]->(l) WHERE id(n)={} AND id(l)={} return e", id_n, id_l));
ASSERT_EQ(stream.GetHeader().size(), 1U);
EXPECT_EQ(stream.GetHeader()[0], "e");
ASSERT_EQ(stream.GetResults().size(), 1U);
auto dba = db_.Access();
std::vector<std::string> expected_result = {"r1", "r2"};
const auto &result = stream.GetResults()[0];
const auto &edges = ToEdgeList(result[0]);
std::vector<std::string> datum;
datum.reserve(edges.size());
for (const auto &edge : edges) {
datum.push_back(edge.type);
}
EXPECT_TRUE(expected_result == datum);
Interpret("MATCH (n) DETACH DELETE n");
}
TEST_F(InterpreterTest, CreateLabelIndexInMulticommandTransaction) {
Interpret("BEGIN");
ASSERT_THROW(Interpret("CREATE INDEX ON :X"), memgraph::query::IndexInMulticommandTxException);