diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 0d1339c99..34d3dcdc0 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -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; } diff --git a/tests/unit/interpreter.cpp b/tests/unit/interpreter.cpp index f5a3e03b3..276cae48b 100644 --- a/tests/unit/interpreter.cpp +++ b/tests/unit/interpreter.cpp @@ -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 expected_result = {"r1", "r2"}; + + const auto &result = stream.GetResults()[0]; + const auto &edges = ToEdgeList(result[0]); + + std::vector 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);