diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index c6e397e71..709172daf 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -691,6 +691,7 @@ class ExpandVariableCursor : public Cursor { : std::numeric_limits::max(); if (upper_bound_ > 0) { + SwitchAccessor(vertex, self_.graph_view_); edges_.emplace_back(ExpandFromVertex(vertex, self_.direction_)); edges_it_.emplace_back(edges_.back().begin()); } @@ -828,6 +829,7 @@ class ExpandVariableCursor : public Cursor { // we are doing depth-first search, so place the current // edge's expansions onto the stack, if we should continue to expand if (upper_bound_ > static_cast(edges_.size())) { + SwitchAccessor(current_vertex, self_.graph_view_); edges_.emplace_back(ExpandFromVertex(current_vertex, self_.direction_)); edges_it_.emplace_back(edges_.back().begin()); } diff --git a/tests/unit/query_plan_match_filter_return.cpp b/tests/unit/query_plan_match_filter_return.cpp index daf8e24de..bc5b4f79c 100644 --- a/tests/unit/query_plan_match_filter_return.cpp +++ b/tests/unit/query_plan_match_filter_return.cpp @@ -346,7 +346,8 @@ class QueryPlanExpandVariable : public testing::Test { int layer, EdgeAtom::Direction direction, std::experimental::optional lower, std::experimental::optional upper, Symbol edge_sym, - bool existing_edge, const std::string &node_to) { + bool existing_edge, const std::string &node_to, + GraphView graph_view = GraphView::AS_IS) { auto n_from = MakeScanAll(storage, symbol_table, node_from, input_op); auto filter_op = std::make_shared( n_from.op_, storage.Create( @@ -364,11 +365,11 @@ class QueryPlanExpandVariable : public testing::Test { }; return std::make_shared( n_to_sym, edge_sym, direction, convert(lower), convert(upper), - filter_op, n_from.sym_, false, existing_edge, GraphView::OLD); + filter_op, n_from.sym_, false, existing_edge, graph_view); } else return std::make_shared(n_to_sym, edge_sym, direction, filter_op, n_from.sym_, false, existing_edge, - GraphView::OLD); + graph_view); } /* Creates an edge (in the frame and symbol table). Returns the symbol. */ @@ -550,6 +551,31 @@ TEST_F(QueryPlanExpandVariable, ExistingEdges) { (map_int{{1, 4}, {2, 12}})); } +TEST_F(QueryPlanExpandVariable, GraphState) { + auto test_expand = [&](GraphView graph_view) { + auto e = Edge("r", EdgeAtom::Direction::OUT); + return GetResults(AddMatch(nullptr, "n", 0, EdgeAtom::Direction::OUT, + 2, 2, e, false, "m", graph_view), e); + }; + + EXPECT_EQ(test_expand(GraphView::OLD), (map_int{{2, 8}})); + + // add two vertices branching out from the second layer + for (VertexAccessor &vertex : dba->vertices(true)) + if (vertex.has_label(labels[1])) { + auto new_vertex = dba->insert_vertex(); + dba->insert_edge(vertex, new_vertex, dba->edge_type("some_type")); + } + ASSERT_EQ(CountIterable(dba->vertices(false)), 6); + ASSERT_EQ(CountIterable(dba->vertices(true)), 8); + + EXPECT_EQ(test_expand(GraphView::OLD), (map_int{{2, 8}})); + EXPECT_EQ(test_expand(GraphView::NEW), (map_int{{2, 12}})); + dba->advance_command(); + EXPECT_EQ(test_expand(GraphView::OLD), (map_int{{2, 12}})); + EXPECT_EQ(test_expand(GraphView::NEW), (map_int{{2, 12}})); +} + namespace std { template <> struct hash> {