diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 77b789dce..2e545bd40 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -52,7 +52,7 @@ add_unit_test(deferred_deleter.cpp) target_link_libraries(${test_prefix}deferred_deleter mg-single-node kvstore_dummy_lib) add_unit_test(bfs_single_node.cpp) -target_link_libraries(${test_prefix}bfs_single_node mg-single-node kvstore_dummy_lib) +target_link_libraries(${test_prefix}bfs_single_node mg-single-node-v2 mg-auth kvstore_dummy_lib) add_unit_test(durability.cpp) target_link_libraries(${test_prefix}durability mg-single-node kvstore_dummy_lib) @@ -127,10 +127,10 @@ add_unit_test(query_plan_accumulate_aggregate.cpp) target_link_libraries(${test_prefix}query_plan_accumulate_aggregate mg-single-node kvstore_dummy_lib) add_unit_test(query_plan_bag_semantics.cpp) -target_link_libraries(${test_prefix}query_plan_bag_semantics mg-single-node kvstore_dummy_lib) +target_link_libraries(${test_prefix}query_plan_bag_semantics mg-single-node-v2 mg-auth kvstore_dummy_lib) add_unit_test(query_plan_create_set_remove_delete.cpp) -target_link_libraries(${test_prefix}query_plan_create_set_remove_delete mg-single-node kvstore_dummy_lib) +target_link_libraries(${test_prefix}query_plan_create_set_remove_delete mg-single-node-v2 mg-auth kvstore_dummy_lib) # Storage V2 in query execution add_unit_test(query_plan_v2_create_set_remove_delete.cpp) @@ -163,7 +163,7 @@ add_unit_test(query_semantic.cpp) target_link_libraries(${test_prefix}query_semantic mg-single-node-v2 mg-auth kvstore_dummy_lib) add_unit_test(query_variable_start_planner.cpp) -target_link_libraries(${test_prefix}query_variable_start_planner mg-single-node kvstore_dummy_lib) +target_link_libraries(${test_prefix}query_variable_start_planner mg-single-node-v2 mg-auth kvstore_dummy_lib) add_unit_test(queue.cpp) target_link_libraries(${test_prefix}queue mg-single-node kvstore_dummy_lib) diff --git a/tests/unit/bfs_common.hpp b/tests/unit/bfs_common.hpp index f50336a2f..2eaec29ba 100644 --- a/tests/unit/bfs_common.hpp +++ b/tests/unit/bfs_common.hpp @@ -26,15 +26,6 @@ void PrintTo(const query::EdgeAtom::Direction &dir, std::ostream *os) { } } // namespace query -#ifdef MG_SINGLE_NODE -using VertexAddress = mvcc::VersionList *; -using EdgeAddress = mvcc::VersionList *; -#endif -#ifdef MG_SINGLE_NODE_HA -using VertexAddress = mvcc::VersionList *; -using EdgeAddress = mvcc::VersionList *; -#endif - const auto kVertexCount = 6; // Maps vertices to workers const std::vector kVertexLocations = {0, 1, 1, 0, 2, 2}; @@ -203,8 +194,7 @@ enum class FilterLambdaType { NONE, USE_FRAME, USE_FRAME_NULL, USE_CTX, ERROR }; // Common interface for single-node and distributed Memgraph. class Database { public: - virtual std::unique_ptr Access() = 0; - virtual void AdvanceCommand(tx::TransactionId tx_id) = 0; + virtual storage::Storage::Accessor Access() = 0; virtual std::unique_ptr MakeBfsOperator( query::Symbol source_sym, query::Symbol sink_sym, query::Symbol edge_sym, query::EdgeAtom::Direction direction, @@ -213,9 +203,9 @@ class Database { bool existing_node, query::Expression *lower_bound, query::Expression *upper_bound, const query::plan::ExpansionLambda &filter_lambda) = 0; - virtual std::pair, std::vector> - BuildGraph(database::GraphDbAccessor *dba, - const std::vector &vertex_locations, + virtual std::pair, + std::vector> + BuildGraph(query::DbAccessor *dba, const std::vector &vertex_locations, const std::vector> &edges) = 0; virtual ~Database() {} @@ -224,14 +214,14 @@ class Database { // Returns an operator that yields vertices given by their address. We will also // include query::TypedValue() to account for the optional match case. std::unique_ptr YieldVertices( - database::GraphDbAccessor *dba, std::vector vertices, + query::DbAccessor *dba, std::vector vertices, query::Symbol symbol, std::shared_ptr input_op) { std::vector> frames; frames.push_back(std::vector{query::TypedValue()}); for (const auto &vertex : vertices) { - frames.emplace_back(std::vector{query::TypedValue( - query::VertexAccessor(VertexAccessor(vertex, *dba)))}); + frames.emplace_back( + std::vector{query::TypedValue(vertex)}); } return std::make_unique(input_op, std::vector{symbol}, frames); @@ -239,42 +229,31 @@ std::unique_ptr YieldVertices( // Returns an operator that yields edges and vertices given by their address. std::unique_ptr YieldEntities( - database::GraphDbAccessor *dba, std::vector vertices, - std::vector edges, query::Symbol symbol, + query::DbAccessor *dba, std::vector vertices, + std::vector edges, query::Symbol symbol, std::shared_ptr input_op) { std::vector> frames; for (const auto &vertex : vertices) { - frames.emplace_back(std::vector{query::TypedValue( - query::VertexAccessor(VertexAccessor(vertex, *dba)))}); + frames.emplace_back( + std::vector{query::TypedValue(vertex)}); } for (const auto &edge : edges) { - frames.emplace_back(std::vector{ - query::TypedValue(query::EdgeAccessor(EdgeAccessor(edge, *dba)))}); + frames.emplace_back( + std::vector{query::TypedValue(edge)}); } return std::make_unique(input_op, std::vector{symbol}, frames); } template -auto GetProp(const RecordAccessor &rec, std::string prop, - database::GraphDbAccessor *dba) { - return rec.PropsAt(dba->Property(prop)); -} - -inline auto GetProp(const query::VertexAccessor &rec, std::string prop, - database::GraphDbAccessor *dba) { - return GetProp(rec.impl_, prop, dba); -} - -inline auto GetProp(const query::EdgeAccessor &rec, std::string prop, - database::GraphDbAccessor *dba) { - return GetProp(rec.impl_, prop, dba); +auto GetProp(const TRecord &rec, std::string prop, query::DbAccessor *dba) { + return *rec.GetProperty(storage::View::OLD, dba->NameToProperty(prop)); } // Checks if the given path is actually a path from source to sink and if all // of its edges exist in the given edge list. template -void CheckPath(database::GraphDbAccessor *dba, const query::VertexAccessor &source, +void CheckPath(query::DbAccessor *dba, const query::VertexAccessor &source, const query::VertexAccessor &sink, const std::vector &path, const std::vector> &edges) { @@ -298,8 +277,7 @@ void CheckPath(database::GraphDbAccessor *dba, const query::VertexAccessor &sour // Given a list of BFS results of form (from, to, path, blocked entity), // checks if all paths are valid and returns the distance matrix. std::vector> CheckPathsAndExtractDistances( - database::GraphDbAccessor *dba, - const std::vector> edges, + query::DbAccessor *dba, const std::vector> edges, const std::vector> &results) { std::vector> distances(kVertexCount, std::vector(kVertexCount, -1)); @@ -320,11 +298,10 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, query::EdgeAtom::Direction direction, std::vector edge_types, bool known_sink, FilterLambdaType filter_lambda_type) { - auto dba_ptr = db->Access(); - auto &dba = *dba_ptr; + auto storage_dba = db->Access(); + query::DbAccessor dba(&storage_dba); query::AstStorage storage; - query::DbAccessor execution_dba(&dba); - query::ExecutionContext context{&execution_dba}; + query::ExecutionContext context{&dba}; query::Symbol blocked_sym = context.symbol_table.CreateSymbol("blocked", true); query::Symbol source_sym = context.symbol_table.CreateSymbol("source", true); @@ -338,13 +315,12 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, query::Identifier *inner_node = IDENT("inner_node")->MapTo(inner_node_sym); query::Identifier *inner_edge = IDENT("inner_edge")->MapTo(inner_edge_sym); - std::vector vertices; - std::vector edges; + std::vector vertices; + std::vector edges; - std::tie(vertices, edges) = - db->BuildGraph(dba_ptr.get(), kVertexLocations, kEdges); + std::tie(vertices, edges) = db->BuildGraph(&dba, kVertexLocations, kEdges); - db->AdvanceCommand(dba_ptr->transaction_id()); + dba.AdvanceCommand(); std::shared_ptr input_op; @@ -361,14 +337,12 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, break; case FilterLambdaType::USE_FRAME: // We block each entity in the graph and run BFS. - input_op = - YieldEntities(dba_ptr.get(), vertices, edges, blocked_sym, nullptr); + input_op = YieldEntities(&dba, vertices, edges, blocked_sym, nullptr); filter_expr = AND(NEQ(inner_node, blocked), NEQ(inner_edge, blocked)); break; case FilterLambdaType::USE_FRAME_NULL: // We block each entity in the graph and run BFS. - input_op = - YieldEntities(dba_ptr.get(), vertices, edges, blocked_sym, nullptr); + input_op = YieldEntities(&dba, vertices, edges, blocked_sym, nullptr); filter_expr = IF(AND(NEQ(inner_node, blocked), NEQ(inner_edge, blocked)), LITERAL(true), LITERAL(PropertyValue())); break; @@ -376,8 +350,8 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, // We only block vertex #5 and run BFS. input_op = std::make_shared( nullptr, std::vector{blocked_sym}, - std::vector>{{query::TypedValue( - query::VertexAccessor(VertexAccessor(vertices[5], *dba_ptr)))}}); + std::vector>{ + {query::TypedValue(vertices[5])}}); filter_expr = NEQ(PROPERTY_LOOKUP(inner_node, PROPERTY_PAIR("id")), PARAMETER_LOOKUP(0)); context.evaluation_context.parameters.Add(0, PropertyValue(5)); @@ -390,17 +364,17 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, } // We run BFS once from each vertex for each blocked entity. - input_op = YieldVertices(dba_ptr.get(), vertices, source_sym, input_op); + input_op = YieldVertices(&dba, vertices, source_sym, input_op); // If the sink is known, we run BFS for all posible combinations of source, // sink and blocked entity. if (known_sink) { - input_op = YieldVertices(dba_ptr.get(), vertices, sink_sym, input_op); + input_op = YieldVertices(&dba, vertices, sink_sym, input_op); } std::vector storage_edge_types; for (const auto &t : edge_types) { - storage_edge_types.push_back(dba_ptr->EdgeType(t)); + storage_edge_types.push_back(dba.NameToEdgeType(t)); } input_op = db->MakeBfsOperator( @@ -411,9 +385,9 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, filter_expr}); context.evaluation_context.properties = - query::NamesToProperties(storage.properties_, &execution_dba); + query::NamesToProperties(storage.properties_, &dba); context.evaluation_context.labels = - query::NamesToLabels(storage.labels_, &execution_dba); + query::NamesToLabels(storage.labels_, &dba); std::vector> results; // An exception should be thrown on one of the pulls. @@ -438,17 +412,14 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, query::TypedValue::BoolEqual{}(results[j][3], blocked)) ++j; - SCOPED_TRACE( - fmt::format("blocked entity = {}", ToString(blocked, execution_dba))); + SCOPED_TRACE(fmt::format("blocked entity = {}", ToString(blocked, dba))); // When an edge is blocked, it is blocked in both directions so we remove // it before modifying edge list to account for direction and edge types; auto edges = kEdges; if (blocked.IsEdge()) { - int from = - GetProp(blocked.ValueEdge(), "from", dba_ptr.get()).ValueInt(); - int to = - GetProp(blocked.ValueEdge(), "to", dba_ptr.get()).ValueInt(); + int from = GetProp(blocked.ValueEdge(), "from", &dba).ValueInt(); + int to = GetProp(blocked.ValueEdge(), "to", &dba).ValueInt(); edges.erase(std::remove_if(edges.begin(), edges.end(), [from, to](const auto &e) { return std::get<0>(e) == from && @@ -462,8 +433,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, // When a vertex is blocked, we remove all edges that lead into it. if (blocked.IsVertex()) { - int id = - GetProp(blocked.ValueVertex(), "id", dba_ptr.get()).ValueInt(); + int id = GetProp(blocked.ValueVertex(), "id", &dba).ValueInt(); edges_blocked.erase( std::remove_if(edges_blocked.begin(), edges_blocked.end(), [id](const auto &e) { return e.second == id; }), @@ -494,7 +464,7 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, EXPECT_EQ(j - i, num_results); auto distances = CheckPathsAndExtractDistances( - dba_ptr.get(), edges_blocked, + &dba, edges_blocked, std::vector>(results.begin() + i, results.begin() + j)); @@ -504,5 +474,5 @@ void BfsTest(Database *db, int lower_bound, int upper_bound, i = j; } - dba_ptr->Abort(); + dba.Abort(); } diff --git a/tests/unit/bfs_single_node.cpp b/tests/unit/bfs_single_node.cpp index e0cff0e26..0dde95626 100644 --- a/tests/unit/bfs_single_node.cpp +++ b/tests/unit/bfs_single_node.cpp @@ -7,16 +7,7 @@ class SingleNodeDb : public Database { public: SingleNodeDb() : db_() {} - std::unique_ptr Access() override { - std::unique_ptr dba = - std::make_unique(db_.Access()); - return dba; - } - - void AdvanceCommand(tx::TransactionId tx_id) override { - auto dba = db_.Access(tx_id); - dba.AdvanceCommand(); - } + storage::Storage::Accessor Access() override { return db_.Access(); } std::unique_ptr MakeBfsOperator( Symbol source_sym, Symbol sink_sym, Symbol edge_sym, @@ -31,36 +22,42 @@ class SingleNodeDb : public Database { filter_lambda, std::nullopt, std::nullopt); } - std::pair, std::vector> BuildGraph( - database::GraphDbAccessor *dba, const std::vector &vertex_locations, + std::pair, + std::vector> + BuildGraph( + query::DbAccessor *dba, const std::vector &vertex_locations, const std::vector> &edges) override { - std::vector vertex_addr; - std::vector edge_addr; + std::vector vertex_addr; + std::vector edge_addr; for (size_t id = 0; id < vertex_locations.size(); ++id) { auto vertex = dba->InsertVertex(); - vertex.PropsSet(dba->Property("id"), - PropertyValue(static_cast(id))); - vertex_addr.push_back(vertex.address()); + CHECK(vertex + .SetProperty(dba->NameToProperty("id"), + PropertyValue(static_cast(id))) + .HasValue()); + vertex_addr.push_back(vertex); } for (auto e : edges) { int u, v; std::string type; std::tie(u, v, type) = e; - ::VertexAccessor from(vertex_addr[u], *dba); - ::VertexAccessor to(vertex_addr[v], *dba); - auto edge = dba->InsertEdge(from, to, dba->EdgeType(type)); - edge.PropsSet(dba->Property("from"), PropertyValue(u)); - edge.PropsSet(dba->Property("to"), PropertyValue(v)); - edge_addr.push_back(edge.address()); + auto &from = vertex_addr[u]; + auto &to = vertex_addr[v]; + auto edge = dba->InsertEdge(&from, &to, dba->NameToEdgeType(type)); + CHECK(edge->SetProperty(dba->NameToProperty("from"), PropertyValue(u)) + .HasValue()); + CHECK(edge->SetProperty(dba->NameToProperty("to"), PropertyValue(v)) + .HasValue()); + edge_addr.push_back(*edge); } return std::make_pair(vertex_addr, edge_addr); } protected: - database::GraphDb db_; + storage::Storage db_; }; class SingleNodeBfsTest diff --git a/tests/unit/query_plan_bag_semantics.cpp b/tests/unit/query_plan_bag_semantics.cpp index 2b1b2d9d4..c6427bf72 100644 --- a/tests/unit/query_plan_bag_semantics.cpp +++ b/tests/unit/query_plan_bag_semantics.cpp @@ -21,8 +21,9 @@ using namespace query; using namespace query::plan; TEST(QueryPlan, Skip) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; @@ -30,8 +31,7 @@ TEST(QueryPlan, Skip) { auto n = MakeScanAll(storage, symbol_table, "n1"); auto skip = std::make_shared(n.op_, LITERAL(2)); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(0, PullAll(*skip, &context)); dba.InsertVertex(); @@ -52,8 +52,9 @@ TEST(QueryPlan, Skip) { } TEST(QueryPlan, Limit) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; @@ -61,8 +62,7 @@ TEST(QueryPlan, Limit) { auto n = MakeScanAll(storage, symbol_table, "n1"); auto skip = std::make_shared(n.op_, LITERAL(2)); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(0, PullAll(*skip, &context)); dba.InsertVertex(); @@ -86,8 +86,9 @@ TEST(QueryPlan, CreateLimit) { // CREATE (n), (m) // MATCH (n) CREATE (m) LIMIT 1 // in the end we need to have 3 vertices in the db - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); dba.InsertVertex(); dba.InsertVertex(); dba.AdvanceCommand(); @@ -101,19 +102,19 @@ TEST(QueryPlan, CreateLimit) { auto c = std::make_shared(n.op_, m); auto skip = std::make_shared(c, LITERAL(1)); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*skip, &context)); dba.AdvanceCommand(); - EXPECT_EQ(3, CountIterable(dba.Vertices(false))); + EXPECT_EQ(3, CountIterable(dba.Vertices(storage::View::OLD))); } TEST(QueryPlan, OrderBy) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; - auto prop = dba.Property("prop"); + auto prop = dba.NameToProperty("prop"); // contains a series of tests // each test defines the ordering a vector of values in the desired order @@ -142,9 +143,10 @@ TEST(QueryPlan, OrderBy) { values.reserve(order_value_pair.second.size()); for (const auto &v : order_value_pair.second) values.emplace_back(v); // empty database - for (auto &vertex : dba.Vertices(false)) dba.DetachRemoveVertex(vertex); + for (auto vertex : dba.Vertices(storage::View::OLD)) + dba.DetachRemoveVertex(&vertex); dba.AdvanceCommand(); - ASSERT_EQ(0, CountIterable(dba.Vertices(false))); + ASSERT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); // take some effort to shuffle the values // because we are testing that something not ordered gets ordered @@ -161,7 +163,9 @@ TEST(QueryPlan, OrderBy) { // create the vertices for (const auto &value : shuffled) - dba.InsertVertex().PropsSet(prop, PropertyValue(value)); + ASSERT_TRUE(dba.InsertVertex() + .SetProperty(prop, PropertyValue(value)) + .HasValue()); dba.AdvanceCommand(); // order by and collect results @@ -173,8 +177,7 @@ TEST(QueryPlan, OrderBy) { auto n_p_ne = NEXPR("n.p", n_p)->MapTo(symbol_table.CreateSymbol("n.p", true)); auto produce = MakeProduce(order_by, n_p_ne); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); auto results = CollectProduce(*produce, &context); ASSERT_EQ(values.size(), results.size()); for (int j = 0; j < results.size(); ++j) @@ -183,13 +186,14 @@ TEST(QueryPlan, OrderBy) { } TEST(QueryPlan, OrderByMultiple) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; - auto p1 = dba.Property("p1"); - auto p2 = dba.Property("p2"); + auto p1 = dba.NameToProperty("p1"); + auto p2 = dba.NameToProperty("p2"); // create a bunch of vertices that in two properties // have all the variations (with repetition) of N values. @@ -201,8 +205,8 @@ TEST(QueryPlan, OrderByMultiple) { std::random_shuffle(prop_values.begin(), prop_values.end()); for (const auto &pair : prop_values) { auto v = dba.InsertVertex(); - v.PropsSet(p1, PropertyValue(pair.first)); - v.PropsSet(p2, PropertyValue(pair.second)); + ASSERT_TRUE(v.SetProperty(p1, PropertyValue(pair.first)).HasValue()); + ASSERT_TRUE(v.SetProperty(p2, PropertyValue(pair.second)).HasValue()); } dba.AdvanceCommand(); @@ -226,8 +230,7 @@ TEST(QueryPlan, OrderByMultiple) { auto n_p2_ne = NEXPR("n.p2", n_p2)->MapTo(symbol_table.CreateSymbol("n.p2", true)); auto produce = MakeProduce(order_by, n_p1_ne, n_p2_ne); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); auto results = CollectProduce(*produce, &context); ASSERT_EQ(N * N, results.size()); for (int j = 0; j < N * N; ++j) { @@ -239,11 +242,12 @@ TEST(QueryPlan, OrderByMultiple) { } TEST(QueryPlan, OrderByExceptions) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; - auto prop = dba.Property("prop"); + auto prop = dba.NameToProperty("prop"); // a vector of pairs of typed values that should result // in an exception when trying to order on them @@ -263,17 +267,19 @@ TEST(QueryPlan, OrderByExceptions) { for (const auto &pair : exception_pairs) { // empty database - for (auto &vertex : dba.Vertices(false)) dba.DetachRemoveVertex(vertex); + for (auto vertex : dba.Vertices(storage::View::OLD)) + dba.DetachRemoveVertex(&vertex); dba.AdvanceCommand(); - ASSERT_EQ(0, CountIterable(dba.Vertices(false))); + ASSERT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); // make two vertices, and set values - dba.InsertVertex().PropsSet(prop, pair.first); - dba.InsertVertex().PropsSet(prop, pair.second); + ASSERT_TRUE(dba.InsertVertex().SetProperty(prop, pair.first).HasValue()); + ASSERT_TRUE(dba.InsertVertex().SetProperty(prop, pair.second).HasValue()); dba.AdvanceCommand(); - ASSERT_EQ(2, CountIterable(dba.Vertices(false))); - for (const auto &va : dba.Vertices(false)) - ASSERT_NE(va.PropsAt(prop).type(), PropertyValue::Type::Null); + ASSERT_EQ(2, CountIterable(dba.Vertices(storage::View::OLD))); + for (const auto &va : dba.Vertices(storage::View::OLD)) + ASSERT_NE(va.GetProperty(storage::View::OLD, prop).GetValue().type(), + PropertyValue::Type::Null); // order by and expect an exception auto n = MakeScanAll(storage, symbol_table, "n"); @@ -281,8 +287,7 @@ TEST(QueryPlan, OrderByExceptions) { auto order_by = std::make_shared( n.op_, std::vector{{Ordering::ASC, n_p}}, std::vector{}); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*order_by, &context), QueryRuntimeException); } } diff --git a/tests/unit/query_plan_common.hpp b/tests/unit/query_plan_common.hpp index e98bd6086..f21485f24 100644 --- a/tests/unit/query_plan_common.hpp +++ b/tests/unit/query_plan_common.hpp @@ -10,6 +10,12 @@ #include "query/interpret/frame.hpp" #include "query/plan/operator.hpp" +// TODO (mferencevic): Remove once all cpp tests are migrated to v2. +#ifdef MG_SINGLE_NODE_V2 +#include "query/db_accessor.hpp" +#include "storage/v2/storage.hpp" +#endif + #include "query_common.hpp" using namespace query; @@ -196,7 +202,28 @@ UnwindTuple MakeUnwind(SymbolTable &symbol_table, return UnwindTuple{sym, op}; } +#ifdef MG_SINGLE_NODE_V2 +template +auto CountIterable(TIterable &&iterable) { + uint64_t count = 0; + for (auto it = iterable.begin(); it != iterable.end(); ++it) { + ++count; + } + return count; +} + +inline uint64_t CountEdges(query::DbAccessor *dba, storage::View view) { + uint64_t count = 0; + for (auto vertex : dba->Vertices(view)) { + auto maybe_edges = vertex.OutEdges(view); + CHECK(maybe_edges.HasValue()); + count += CountIterable(*maybe_edges); + } + return count; +} +#else template auto CountIterable(TIterable iterable) { return std::distance(iterable.begin(), iterable.end()); } +#endif diff --git a/tests/unit/query_plan_create_set_remove_delete.cpp b/tests/unit/query_plan_create_set_remove_delete.cpp index 7f150c36d..cfb8cecd0 100644 --- a/tests/unit/query_plan_create_set_remove_delete.cpp +++ b/tests/unit/query_plan_create_set_remove_delete.cpp @@ -16,10 +16,11 @@ using namespace query; using namespace query::plan; TEST(QueryPlan, CreateNodeWithAttributes) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); - storage::Label label = dba.Label("Person"); + storage::Label label = dba.NameToLabel("Person"); auto property = PROPERTY_PAIR("prop"); AstStorage storage; @@ -31,20 +32,26 @@ TEST(QueryPlan, CreateNodeWithAttributes) { node.properties.emplace_back(property.second, LITERAL(42)); auto create = std::make_shared(nullptr, node); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*create, &context); dba.AdvanceCommand(); // count the number of vertices int vertex_count = 0; - for (auto vertex : dba.Vertices(false)) { + for (auto vertex : dba.Vertices(storage::View::OLD)) { vertex_count++; - EXPECT_EQ(vertex.labels().size(), 1); - EXPECT_EQ(*vertex.labels().begin(), label); - EXPECT_EQ(vertex.Properties().size(), 1); - auto prop_eq = - TypedValue(vertex.PropsAt(property.second)) == TypedValue(42); + auto maybe_labels = vertex.Labels(storage::View::OLD); + ASSERT_TRUE(maybe_labels.HasValue()); + const auto &labels = *maybe_labels; + EXPECT_EQ(labels.size(), 1); + EXPECT_EQ(*labels.begin(), label); + auto maybe_properties = vertex.Properties(storage::View::OLD); + ASSERT_TRUE(maybe_properties.HasValue()); + const auto &properties = *maybe_properties; + EXPECT_EQ(properties.size(), 1); + auto maybe_prop = vertex.GetProperty(storage::View::OLD, property.second); + ASSERT_TRUE(maybe_prop.HasValue()); + auto prop_eq = TypedValue(*maybe_prop) == TypedValue(42); ASSERT_EQ(prop_eq.type(), TypedValue::Type::Bool); EXPECT_TRUE(prop_eq.ValueBool()); } @@ -53,10 +60,11 @@ TEST(QueryPlan, CreateNodeWithAttributes) { TEST(QueryPlan, CreateReturn) { // test CREATE (n:Person {age: 42}) RETURN n, n.age - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); - storage::Label label = dba.Label("Person"); + storage::Label label = dba.NameToLabel("Person"); auto property = PROPERTY_PAIR("property"); AstStorage storage; @@ -77,38 +85,38 @@ TEST(QueryPlan, CreateReturn) { ->MapTo(symbol_table.CreateSymbol("named_expr_n_p", true)); auto produce = MakeProduce(create, named_expr_n, named_expr_n_p); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); auto results = CollectProduce(*produce, &context); EXPECT_EQ(1, results.size()); EXPECT_EQ(2, results[0].size()); EXPECT_EQ(TypedValue::Type::Vertex, results[0][0].type()); - auto maybe_labels = results[0][0].ValueVertex().Labels(storage::View::OLD); + auto maybe_labels = results[0][0].ValueVertex().Labels(storage::View::NEW); EXPECT_EQ(1, maybe_labels->size()); EXPECT_EQ(label, (*maybe_labels)[0]); EXPECT_EQ(TypedValue::Type::Int, results[0][1].type()); EXPECT_EQ(42, results[0][1].ValueInt()); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); } TEST(QueryPlan, CreateExpand) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); - storage::Label label_node_1 = dba.Label("Node1"); - storage::Label label_node_2 = dba.Label("Node2"); + storage::Label label_node_1 = dba.NameToLabel("Node1"); + storage::Label label_node_2 = dba.NameToLabel("Node2"); auto property = PROPERTY_PAIR("property"); - storage::EdgeType edge_type = dba.EdgeType("edge_type"); + storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); SymbolTable symbol_table; AstStorage storage; auto test_create_path = [&](bool cycle, int expected_nodes_created, int expected_edges_created) { - int before_v = CountIterable(dba.Vertices(false)); - int before_e = CountIterable(dba.Edges(false)); + int before_v = CountIterable(dba.Vertices(storage::View::OLD)); + int before_e = CountEdges(&dba, storage::View::OLD); // data for the first node NodeCreationInfo n; @@ -130,44 +138,57 @@ TEST(QueryPlan, CreateExpand) { auto create_op = std::make_shared(nullptr, n); auto create_expand = std::make_shared(m, r, create_op, n.symbol, cycle); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*create_expand, &context); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Vertices(false)) - before_v, + EXPECT_EQ(CountIterable(dba.Vertices(storage::View::OLD)) - before_v, expected_nodes_created); - EXPECT_EQ(CountIterable(dba.Edges(false)) - before_e, + EXPECT_EQ(CountEdges(&dba, storage::View::OLD) - before_e, expected_edges_created); }; test_create_path(false, 2, 1); test_create_path(true, 1, 1); - for (auto vertex : dba.Vertices(false)) { - EXPECT_EQ(vertex.labels().size(), 1); - storage::Label label = vertex.labels()[0]; + for (auto vertex : dba.Vertices(storage::View::OLD)) { + auto maybe_labels = vertex.Labels(storage::View::OLD); + CHECK(maybe_labels.HasValue()); + const auto &labels = *maybe_labels; + EXPECT_EQ(labels.size(), 1); + storage::Label label = labels[0]; if (label == label_node_1) { // node created by first op - EXPECT_EQ(vertex.PropsAt(property.second).ValueInt(), 1); + EXPECT_EQ( + vertex.GetProperty(storage::View::OLD, property.second)->ValueInt(), + 1); } else if (label == label_node_2) { // node create by expansion - EXPECT_EQ(vertex.PropsAt(property.second).ValueInt(), 2); + EXPECT_EQ( + vertex.GetProperty(storage::View::OLD, property.second)->ValueInt(), + 2); } else { // should not happen FAIL(); } - for (auto edge : dba.Edges(false)) { - EXPECT_EQ(edge.EdgeType(), edge_type); - EXPECT_EQ(edge.PropsAt(property.second).ValueInt(), 3); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + auto maybe_edges = vertex.OutEdges(storage::View::OLD); + CHECK(maybe_edges.HasValue()); + for (auto edge : *maybe_edges) { + EXPECT_EQ(edge.EdgeType(), edge_type); + EXPECT_EQ( + edge.GetProperty(storage::View::OLD, property.second)->ValueInt(), + 3); + } } } } TEST(QueryPlan, MatchCreateNode) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // add three nodes we'll match and expand-create from dba.InsertVertex(); @@ -186,17 +207,17 @@ TEST(QueryPlan, MatchCreateNode) { // creation op auto create_node = std::make_shared(n_scan_all.op_, m); - EXPECT_EQ(CountIterable(dba.Vertices(false)), 3); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + EXPECT_EQ(CountIterable(dba.Vertices(storage::View::OLD)), 3); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*create_node, &context); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Vertices(false)), 6); + EXPECT_EQ(CountIterable(dba.Vertices(storage::View::OLD)), 6); } TEST(QueryPlan, MatchCreateExpand) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // add three nodes we'll match and expand-create from dba.InsertVertex(); @@ -204,18 +225,18 @@ TEST(QueryPlan, MatchCreateExpand) { dba.InsertVertex(); dba.AdvanceCommand(); - // storage::Label label_node_1 = dba.Label("Node1"); - // storage::Label label_node_2 = dba.Label("Node2"); - // storage::Property property = dba.Label("prop"); - storage::EdgeType edge_type = dba.EdgeType("edge_type"); + // storage::Label label_node_1 = dba.NameToLabel("Node1"); + // storage::Label label_node_2 = dba.NameToLabel("Node2"); + // storage::Property property = dba.NameToLabel("prop"); + storage::EdgeType edge_type = dba.NameToEdgeType("edge_type"); SymbolTable symbol_table; AstStorage storage; auto test_create_path = [&](bool cycle, int expected_nodes_created, int expected_edges_created) { - int before_v = CountIterable(dba.Vertices(false)); - int before_e = CountIterable(dba.Edges(false)); + int before_v = CountIterable(dba.Vertices(storage::View::OLD)); + int before_e = CountEdges(&dba, storage::View::OLD); // data for the first node auto n_scan_all = MakeScanAll(storage, symbol_table, "n"); @@ -231,14 +252,13 @@ TEST(QueryPlan, MatchCreateExpand) { auto create_expand = std::make_shared(m, r, n_scan_all.op_, n_scan_all.sym_, cycle); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*create_expand, &context); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Vertices(false)) - before_v, + EXPECT_EQ(CountIterable(dba.Vertices(storage::View::OLD)) - before_v, expected_nodes_created); - EXPECT_EQ(CountIterable(dba.Edges(false)) - before_e, + EXPECT_EQ(CountEdges(&dba, storage::View::OLD) - before_e, expected_edges_created); }; @@ -247,20 +267,21 @@ TEST(QueryPlan, MatchCreateExpand) { } TEST(QueryPlan, Delete) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // make a fully-connected (one-direction, no cycles) with 4 nodes - std::vector<::VertexAccessor> vertices; + std::vector vertices; for (int i = 0; i < 4; ++i) vertices.push_back(dba.InsertVertex()); - auto type = dba.EdgeType("type"); + auto type = dba.NameToEdgeType("type"); for (int j = 0; j < 4; ++j) for (int k = j + 1; k < 4; ++k) - dba.InsertEdge(vertices[j], vertices[k], type); + ASSERT_TRUE(dba.InsertEdge(&vertices[j], &vertices[k], type).HasValue()); dba.AdvanceCommand(); - EXPECT_EQ(4, CountIterable(dba.Vertices(false))); - EXPECT_EQ(6, CountIterable(dba.Edges(false))); + EXPECT_EQ(4, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(6, CountEdges(&dba, storage::View::OLD)); AstStorage storage; SymbolTable symbol_table; @@ -271,12 +292,11 @@ TEST(QueryPlan, Delete) { auto n_get = storage.Create("n")->MapTo(n.sym_); auto delete_op = std::make_shared( n.op_, std::vector{n_get}, false); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*delete_op, &context), QueryRuntimeException); dba.AdvanceCommand(); - EXPECT_EQ(4, CountIterable(dba.Vertices(false))); - EXPECT_EQ(6, CountIterable(dba.Edges(false))); + EXPECT_EQ(4, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(6, CountEdges(&dba, storage::View::OLD)); } // detach delete a single vertex @@ -286,12 +306,11 @@ TEST(QueryPlan, Delete) { auto delete_op = std::make_shared( n.op_, std::vector{n_get}, true); Frame frame(symbol_table.max_position()); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); delete_op->MakeCursor(utils::NewDeleteResource())->Pull(frame, context); dba.AdvanceCommand(); - EXPECT_EQ(3, CountIterable(dba.Vertices(false))); - EXPECT_EQ(3, CountIterable(dba.Edges(false))); + EXPECT_EQ(3, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(3, CountEdges(&dba, storage::View::OLD)); } // delete all remaining edges @@ -303,12 +322,11 @@ TEST(QueryPlan, Delete) { auto r_get = storage.Create("r")->MapTo(r_m.edge_sym_); auto delete_op = std::make_shared( r_m.op_, std::vector{r_get}, false); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*delete_op, &context); dba.AdvanceCommand(); - EXPECT_EQ(3, CountIterable(dba.Vertices(false))); - EXPECT_EQ(0, CountIterable(dba.Edges(false))); + EXPECT_EQ(3, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(0, CountEdges(&dba, storage::View::OLD)); } // delete all remaining vertices @@ -317,12 +335,11 @@ TEST(QueryPlan, Delete) { auto n_get = storage.Create("n")->MapTo(n.sym_); auto delete_op = std::make_shared( n.op_, std::vector{n_get}, false); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); PullAll(*delete_op, &context); dba.AdvanceCommand(); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - EXPECT_EQ(0, CountIterable(dba.Edges(false))); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(0, CountEdges(&dba, storage::View::OLD)); } } @@ -339,15 +356,16 @@ TEST(QueryPlan, DeleteTwiceDeleteBlockingEdge) { // MATCH (n)-[r]-(m) [DETACH] DELETE n, r, m auto test_delete = [](bool detach) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); - dba.InsertEdge(v1, v2, dba.EdgeType("T")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("T")).HasValue()); dba.AdvanceCommand(); - EXPECT_EQ(2, CountIterable(dba.Vertices(false))); - EXPECT_EQ(1, CountIterable(dba.Edges(false))); + EXPECT_EQ(2, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(1, CountEdges(&dba, storage::View::OLD)); AstStorage storage; SymbolTable symbol_table; @@ -364,12 +382,11 @@ TEST(QueryPlan, DeleteTwiceDeleteBlockingEdge) { auto delete_op = std::make_shared( r_m.op_, std::vector{n_get, r_get, m_get}, detach); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*delete_op, &context)); dba.AdvanceCommand(); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - EXPECT_EQ(0, CountIterable(dba.Edges(false))); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(0, CountEdges(&dba, storage::View::OLD)); }; test_delete(true); @@ -377,19 +394,20 @@ TEST(QueryPlan, DeleteTwiceDeleteBlockingEdge) { } TEST(QueryPlan, DeleteReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // make a fully-connected (one-direction, no cycles) with 4 nodes auto prop = PROPERTY_PAIR("property"); for (int i = 0; i < 4; ++i) { auto va = dba.InsertVertex(); - va.PropsSet(prop.second, PropertyValue(42)); + ASSERT_TRUE(va.SetProperty(prop.second, PropertyValue(42)).HasValue()); } dba.AdvanceCommand(); - EXPECT_EQ(4, CountIterable(dba.Vertices(false))); - EXPECT_EQ(0, CountIterable(dba.Edges(false))); + EXPECT_EQ(4, CountIterable(dba.Vertices(storage::View::OLD))); + EXPECT_EQ(0, CountEdges(&dba, storage::View::OLD)); AstStorage storage; SymbolTable symbol_table; @@ -405,26 +423,22 @@ TEST(QueryPlan, DeleteReturn) { ->MapTo(symbol_table.CreateSymbol("bla", true)); auto produce = MakeProduce(delete_op, n_p); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); - auto results = CollectProduce(*produce, &context); - EXPECT_EQ(4, results.size()); - dba.AdvanceCommand(); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); + auto context = MakeContext(storage, symbol_table, &dba); + ASSERT_THROW(CollectProduce(*produce, &context), QueryRuntimeException); } TEST(QueryPlan, DeleteNull) { // test (simplified) WITH Null as x delete x - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; auto once = std::make_shared(); auto delete_op = std::make_shared( once, std::vector{LITERAL(TypedValue())}, false); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*delete_op, &context)); } @@ -434,7 +448,7 @@ TEST(QueryPlan, DeleteAdvance) { // MATCH (n) DELETE n WITH n ... // this fails only if the deleted record `n` is actually used in subsequent // clauses, which is compatible with Neo's behavior. - database::GraphDb db; + storage::Storage db; AstStorage storage; SymbolTable symbol_table; @@ -447,31 +461,31 @@ TEST(QueryPlan, DeleteAdvance) { delete_op, std::vector{n.sym_}, true); auto res_sym = symbol_table.CreateSymbol("res", true); { - auto dba = db.Access(); + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); dba.InsertVertex(); dba.AdvanceCommand(); - query::DbAccessor execution_dba(&dba); auto produce = MakeProduce(advance, NEXPR("res", LITERAL(42))->MapTo(res_sym)); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*produce, &context)); - dba.Abort(); } { - auto dba = db.Access(); + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); dba.InsertVertex(); dba.AdvanceCommand(); - query::DbAccessor execution_dba(&dba); - auto n_prop = PROPERTY_LOOKUP(n_get, dba.Property("prop")); + auto n_prop = PROPERTY_LOOKUP(n_get, dba.NameToProperty("prop")); auto produce = MakeProduce(advance, NEXPR("res", n_prop)->MapTo(res_sym)); - auto context = MakeContext(storage, symbol_table, &execution_dba); - EXPECT_THROW(PullAll(*produce, &context), ReconstructionException); + auto context = MakeContext(storage, symbol_table, &dba); + EXPECT_THROW(PullAll(*produce, &context), QueryRuntimeException); } } TEST(QueryPlan, SetProperty) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // graph with 4 vertices in connected pairs // the origin vertex in each par and both edges @@ -480,9 +494,9 @@ TEST(QueryPlan, SetProperty) { auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); auto v4 = dba.InsertVertex(); - auto edge_type = dba.EdgeType("edge_type"); - dba.InsertEdge(v1, v3, edge_type); - dba.InsertEdge(v2, v4, edge_type); + auto edge_type = dba.NameToEdgeType("edge_type"); + ASSERT_TRUE(dba.InsertEdge(&v1, &v3, edge_type).HasValue()); + ASSERT_TRUE(dba.InsertEdge(&v2, &v4, edge_type).HasValue()); dba.AdvanceCommand(); AstStorage storage; @@ -495,7 +509,7 @@ TEST(QueryPlan, SetProperty) { EdgeAtom::Direction::OUT, {}, "m", false, storage::View::OLD); // set prop1 to 42 on n and r - auto prop1 = dba.Property("prop1"); + auto prop1 = dba.NameToProperty("prop1"); auto literal = LITERAL(42); auto n_p = PROPERTY_LOOKUP(IDENT("n")->MapTo(n.sym_), prop1); @@ -505,38 +519,45 @@ TEST(QueryPlan, SetProperty) { auto r_p = PROPERTY_LOOKUP(IDENT("r")->MapTo(r_m.edge_sym_), prop1); auto set_r_p = std::make_shared(set_n_p, prop1, r_p, literal); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*set_r_p, &context)); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Edges(false)), 2); - for (auto edge : dba.Edges(false)) { - ASSERT_EQ(edge.PropsAt(prop1).type(), PropertyValue::Type::Int); - EXPECT_EQ(edge.PropsAt(prop1).ValueInt(), 42); - auto from = edge.from(); - auto to = edge.to(); - ASSERT_EQ(from.PropsAt(prop1).type(), PropertyValue::Type::Int); - EXPECT_EQ(from.PropsAt(prop1).ValueInt(), 42); - ASSERT_EQ(to.PropsAt(prop1).type(), PropertyValue::Type::Null); + EXPECT_EQ(CountEdges(&dba, storage::View::OLD), 2); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + auto maybe_edges = vertex.OutEdges(storage::View::OLD); + ASSERT_TRUE(maybe_edges.HasValue()); + for (auto edge : *maybe_edges) { + ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42); + auto from = edge.From(); + auto to = edge.To(); + ASSERT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->ValueInt(), 42); + ASSERT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Null); + } } } TEST(QueryPlan, SetProperties) { auto test_set_properties = [](bool update) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // graph: ({a: 0})-[:R {b:1}]->({c:2}) - auto prop_a = dba.Property("a"); - auto prop_b = dba.Property("b"); - auto prop_c = dba.Property("c"); + auto prop_a = dba.NameToProperty("a"); + auto prop_b = dba.NameToProperty("b"); + auto prop_c = dba.NameToProperty("c"); auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); - auto e = dba.InsertEdge(v1, v2, dba.EdgeType("R")); - v1.PropsSet(prop_a, PropertyValue(0)); - e.PropsSet(prop_b, PropertyValue(1)); - v2.PropsSet(prop_c, PropertyValue(2)); + auto e = dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("R")); + ASSERT_TRUE(v1.SetProperty(prop_a, PropertyValue(0)).HasValue()); + ASSERT_TRUE(e->SetProperty(prop_b, PropertyValue(1)).HasValue()); + ASSERT_TRUE(v2.SetProperty(prop_c, PropertyValue(2)).HasValue()); dba.AdvanceCommand(); AstStorage storage; @@ -558,34 +579,44 @@ TEST(QueryPlan, SetProperties) { std::make_shared(r_m.op_, n.sym_, r_ident, op); auto set_m_to_r = std::make_shared( set_r_to_n, r_m.edge_sym_, m_ident, op); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*set_m_to_r, &context)); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Edges(false)), 1); - for (auto edge : dba.Edges(false)) { - auto from = edge.from(); - EXPECT_EQ(from.Properties().size(), update ? 2 : 1); - if (update) { - ASSERT_EQ(from.PropsAt(prop_a).type(), PropertyValue::Type::Int); - EXPECT_EQ(from.PropsAt(prop_a).ValueInt(), 0); - } - ASSERT_EQ(from.PropsAt(prop_b).type(), PropertyValue::Type::Int); - EXPECT_EQ(from.PropsAt(prop_b).ValueInt(), 1); + EXPECT_EQ(CountEdges(&dba, storage::View::OLD), 1); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + auto maybe_edges = vertex.OutEdges(storage::View::OLD); + ASSERT_TRUE(maybe_edges.HasValue()); + for (auto edge : *maybe_edges) { + auto from = edge.From(); + EXPECT_EQ(from.Properties(storage::View::OLD)->size(), update ? 2 : 1); + if (update) { + ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_a)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_a)->ValueInt(), + 0); + } + ASSERT_EQ(from.GetProperty(storage::View::OLD, prop_b)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(from.GetProperty(storage::View::OLD, prop_b)->ValueInt(), 1); - EXPECT_EQ(edge.Properties().size(), update ? 2 : 1); - if (update) { - ASSERT_EQ(edge.PropsAt(prop_b).type(), PropertyValue::Type::Int); - EXPECT_EQ(edge.PropsAt(prop_b).ValueInt(), 1); - } - ASSERT_EQ(edge.PropsAt(prop_c).type(), PropertyValue::Type::Int); - EXPECT_EQ(edge.PropsAt(prop_c).ValueInt(), 2); + EXPECT_EQ(edge.Properties(storage::View::OLD)->size(), update ? 2 : 1); + if (update) { + ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_b)->ValueInt(), + 1); + } + ASSERT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2); - auto to = edge.to(); - EXPECT_EQ(to.Properties().size(), 1); - ASSERT_EQ(to.PropsAt(prop_c).type(), PropertyValue::Type::Int); - EXPECT_EQ(to.PropsAt(prop_c).ValueInt(), 2); + auto to = edge.To(); + EXPECT_EQ(to.Properties(storage::View::OLD)->size(), 1); + ASSERT_EQ(to.GetProperty(storage::View::OLD, prop_c)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(to.GetProperty(storage::View::OLD, prop_c)->ValueInt(), 2); + } } }; @@ -594,14 +625,15 @@ TEST(QueryPlan, SetProperties) { } TEST(QueryPlan, SetLabels) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); - auto label1 = dba.Label("label1"); - auto label2 = dba.Label("label2"); - auto label3 = dba.Label("label3"); - dba.InsertVertex().add_label(label1); - dba.InsertVertex().add_label(label1); + auto label1 = dba.NameToLabel("label1"); + auto label2 = dba.NameToLabel("label2"); + auto label3 = dba.NameToLabel("label3"); + ASSERT_TRUE(dba.InsertVertex().AddLabel(label1).HasValue()); + ASSERT_TRUE(dba.InsertVertex().AddLabel(label1).HasValue()); dba.AdvanceCommand(); AstStorage storage; @@ -610,39 +642,42 @@ TEST(QueryPlan, SetLabels) { auto n = MakeScanAll(storage, symbol_table, "n"); auto label_set = std::make_shared( n.op_, n.sym_, std::vector{label2, label3}); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*label_set, &context)); - for (auto vertex : dba.Vertices(false)) { - vertex.SwitchNew(); - EXPECT_EQ(3, vertex.labels().size()); - EXPECT_TRUE(vertex.has_label(label2)); - EXPECT_TRUE(vertex.has_label(label3)); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + EXPECT_EQ(3, vertex.Labels(storage::View::NEW)->size()); + EXPECT_TRUE(*vertex.HasLabel(storage::View::NEW, label2)); + EXPECT_TRUE(*vertex.HasLabel(storage::View::NEW, label3)); } } TEST(QueryPlan, RemoveProperty) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // graph with 4 vertices in connected pairs // the origin vertex in each par and both edges // have a property set - auto prop1 = dba.Property("prop1"); + auto prop1 = dba.NameToProperty("prop1"); auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); auto v4 = dba.InsertVertex(); - auto edge_type = dba.EdgeType("edge_type"); - dba.InsertEdge(v1, v3, edge_type).PropsSet(prop1, PropertyValue(42)); - dba.InsertEdge(v2, v4, edge_type); - v2.PropsSet(prop1, PropertyValue(42)); - v3.PropsSet(prop1, PropertyValue(42)); - v4.PropsSet(prop1, PropertyValue(42)); - auto prop2 = dba.Property("prop2"); - v1.PropsSet(prop2, PropertyValue(0)); - v2.PropsSet(prop2, PropertyValue(0)); + auto edge_type = dba.NameToEdgeType("edge_type"); + { + auto e = dba.InsertEdge(&v1, &v3, edge_type); + ASSERT_TRUE(e.HasValue()); + ASSERT_TRUE(e->SetProperty(prop1, PropertyValue(42)).HasValue()); + } + ASSERT_TRUE(dba.InsertEdge(&v2, &v4, edge_type).HasValue()); + ASSERT_TRUE(v2.SetProperty(prop1, PropertyValue(42)).HasValue()); + ASSERT_TRUE(v3.SetProperty(prop1, PropertyValue(42)).HasValue()); + ASSERT_TRUE(v4.SetProperty(prop1, PropertyValue(42)).HasValue()); + auto prop2 = dba.NameToProperty("prop2"); + ASSERT_TRUE(v1.SetProperty(prop2, PropertyValue(0)).HasValue()); + ASSERT_TRUE(v2.SetProperty(prop2, PropertyValue(0)).HasValue()); dba.AdvanceCommand(); AstStorage storage; @@ -659,36 +694,44 @@ TEST(QueryPlan, RemoveProperty) { auto r_p = PROPERTY_LOOKUP(IDENT("r")->MapTo(r_m.edge_sym_), prop1); auto set_r_p = std::make_shared(set_n_p, prop1, r_p); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*set_r_p, &context)); dba.AdvanceCommand(); - EXPECT_EQ(CountIterable(dba.Edges(false)), 2); - for (auto edge : dba.Edges(false)) { - EXPECT_EQ(edge.PropsAt(prop1).type(), PropertyValue::Type::Null); - auto from = edge.from(); - auto to = edge.to(); - EXPECT_EQ(from.PropsAt(prop1).type(), PropertyValue::Type::Null); - EXPECT_EQ(from.PropsAt(prop2).type(), PropertyValue::Type::Int); - EXPECT_EQ(to.PropsAt(prop1).type(), PropertyValue::Type::Int); + EXPECT_EQ(CountEdges(&dba, storage::View::OLD), 2); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + auto maybe_edges = vertex.OutEdges(storage::View::OLD); + ASSERT_TRUE(maybe_edges.HasValue()); + for (auto edge : *maybe_edges) { + EXPECT_EQ(edge.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Null); + auto from = edge.From(); + auto to = edge.To(); + EXPECT_EQ(from.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Null); + EXPECT_EQ(from.GetProperty(storage::View::OLD, prop2)->type(), + PropertyValue::Type::Int); + EXPECT_EQ(to.GetProperty(storage::View::OLD, prop1)->type(), + PropertyValue::Type::Int); + } } } TEST(QueryPlan, RemoveLabels) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); - auto label1 = dba.Label("label1"); - auto label2 = dba.Label("label2"); - auto label3 = dba.Label("label3"); + auto label1 = dba.NameToLabel("label1"); + auto label2 = dba.NameToLabel("label2"); + auto label3 = dba.NameToLabel("label3"); auto v1 = dba.InsertVertex(); - v1.add_label(label1); - v1.add_label(label2); - v1.add_label(label3); + ASSERT_TRUE(v1.AddLabel(label1).HasValue()); + ASSERT_TRUE(v1.AddLabel(label2).HasValue()); + ASSERT_TRUE(v1.AddLabel(label3).HasValue()); auto v2 = dba.InsertVertex(); - v2.add_label(label1); - v2.add_label(label3); + ASSERT_TRUE(v2.AddLabel(label1).HasValue()); + ASSERT_TRUE(v2.AddLabel(label3).HasValue()); dba.AdvanceCommand(); AstStorage storage; @@ -697,30 +740,29 @@ TEST(QueryPlan, RemoveLabels) { auto n = MakeScanAll(storage, symbol_table, "n"); auto label_remove = std::make_shared( n.op_, n.sym_, std::vector{label1, label2}); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*label_remove, &context)); - for (auto vertex : dba.Vertices(false)) { - vertex.SwitchNew(); - EXPECT_EQ(1, vertex.labels().size()); - EXPECT_FALSE(vertex.has_label(label1)); - EXPECT_FALSE(vertex.has_label(label2)); + for (auto vertex : dba.Vertices(storage::View::OLD)) { + EXPECT_EQ(1, vertex.Labels(storage::View::NEW)->size()); + EXPECT_FALSE(*vertex.HasLabel(storage::View::NEW, label1)); + EXPECT_FALSE(*vertex.HasLabel(storage::View::NEW, label2)); } } TEST(QueryPlan, NodeFilterSet) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Create a graph such that (v1 {prop: 42}) is connected to v2 and v3. auto v1 = dba.InsertVertex(); auto prop = PROPERTY_PAIR("property"); - v1.PropsSet(prop.second, PropertyValue(42)); + ASSERT_TRUE(v1.SetProperty(prop.second, PropertyValue(42)).HasValue()); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - auto edge_type = dba.EdgeType("Edge"); - dba.InsertEdge(v1, v2, edge_type); - dba.InsertEdge(v1, v3, edge_type); + auto edge_type = dba.NameToEdgeType("Edge"); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, edge_type).HasValue()); + ASSERT_TRUE(dba.InsertEdge(&v1, &v3, edge_type).HasValue()); dba.AdvanceCommand(); // Create operations which match (v1 {prop: 42}) -- (v) and increment the // v1.prop. The expected result is two incremenentations, since v1 is matched @@ -743,28 +785,28 @@ TEST(QueryPlan, NodeFilterSet) { auto add = ADD(set_prop, LITERAL(1)); auto set = std::make_shared(node_filter, prop.second, set_prop, add); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*set, &context)); dba.AdvanceCommand(); - v1.Reconstruct(); - auto prop_eq = TypedValue(v1.PropsAt(prop.second)) == TypedValue(42 + 2); + auto prop_eq = TypedValue(*v1.GetProperty(storage::View::OLD, prop.second)) == + TypedValue(42 + 2); ASSERT_EQ(prop_eq.type(), TypedValue::Type::Bool); EXPECT_TRUE(prop_eq.ValueBool()); } TEST(QueryPlan, FilterRemove) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Create a graph such that (v1 {prop: 42}) is connected to v2 and v3. auto v1 = dba.InsertVertex(); auto prop = PROPERTY_PAIR("property"); - v1.PropsSet(prop.second, PropertyValue(42)); + ASSERT_TRUE(v1.SetProperty(prop.second, PropertyValue(42)).HasValue()); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - auto edge_type = dba.EdgeType("Edge"); - dba.InsertEdge(v1, v2, edge_type); - dba.InsertEdge(v1, v3, edge_type); + auto edge_type = dba.NameToEdgeType("Edge"); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, edge_type).HasValue()); + ASSERT_TRUE(dba.InsertEdge(&v1, &v3, edge_type).HasValue()); dba.AdvanceCommand(); // Create operations which match (v1 {prop: 42}) -- (v) and remove v1.prop. // The expected result is two matches, for each edge of v1. @@ -783,20 +825,20 @@ TEST(QueryPlan, FilterRemove) { auto rem_prop = PROPERTY_LOOKUP(IDENT("n")->MapTo(scan_all.sym_), prop); auto rem = std::make_shared(filter, prop.second, rem_prop); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(2, PullAll(*rem, &context)); dba.AdvanceCommand(); - v1.Reconstruct(); - EXPECT_EQ(v1.PropsAt(prop.second).type(), PropertyValue::Type::Null); + EXPECT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(), + PropertyValue::Type::Null); } TEST(QueryPlan, SetRemove) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); auto v = dba.InsertVertex(); - auto label1 = dba.Label("label1"); - auto label2 = dba.Label("label2"); + auto label1 = dba.NameToLabel("label1"); + auto label2 = dba.NameToLabel("label2"); dba.AdvanceCommand(); // Create operations which match (v) and set and remove v :label. // The expected result is single (v) as it was at the start. @@ -808,13 +850,11 @@ TEST(QueryPlan, SetRemove) { scan_all.op_, scan_all.sym_, std::vector{label1, label2}); auto rem = std::make_shared( set, scan_all.sym_, std::vector{label1, label2}); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*rem, &context)); dba.AdvanceCommand(); - v.Reconstruct(); - EXPECT_FALSE(v.has_label(label1)); - EXPECT_FALSE(v.has_label(label2)); + EXPECT_FALSE(*v.HasLabel(storage::View::OLD, label1)); + EXPECT_FALSE(*v.HasLabel(storage::View::OLD, label2)); } TEST(QueryPlan, Merge) { @@ -824,11 +864,12 @@ TEST(QueryPlan, Merge) { // - merge_match branch looks for an expansion (any direction) // and sets some property (for result validation) // - merge_create branch just sets some other property - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); - dba.InsertEdge(v1, v2, dba.EdgeType("Type")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("Type")).HasValue()); auto v3 = dba.InsertVertex(); dba.AdvanceCommand(); @@ -852,27 +893,27 @@ TEST(QueryPlan, Merge) { std::make_shared(), prop.second, n_p, LITERAL(2)); auto merge = std::make_shared(n.op_, m_set, n_set); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); ASSERT_EQ(3, PullAll(*merge, &context)); dba.AdvanceCommand(); - v1.Reconstruct(); - v2.Reconstruct(); - v3.Reconstruct(); - ASSERT_EQ(v1.PropsAt(prop.second).type(), PropertyValue::Type::Int); - ASSERT_EQ(v1.PropsAt(prop.second).ValueInt(), 1); - ASSERT_EQ(v2.PropsAt(prop.second).type(), PropertyValue::Type::Int); - ASSERT_EQ(v2.PropsAt(prop.second).ValueInt(), 1); - ASSERT_EQ(v3.PropsAt(prop.second).type(), PropertyValue::Type::Int); - ASSERT_EQ(v3.PropsAt(prop.second).ValueInt(), 2); + ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->type(), + PropertyValue::Type::Int); + ASSERT_EQ(v1.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1); + ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->type(), + PropertyValue::Type::Int); + ASSERT_EQ(v2.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 1); + ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->type(), + PropertyValue::Type::Int); + ASSERT_EQ(v3.GetProperty(storage::View::OLD, prop.second)->ValueInt(), 2); } TEST(QueryPlan, MergeNoInput) { // merge with no input, creates a single node - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; @@ -881,18 +922,18 @@ TEST(QueryPlan, MergeNoInput) { auto create = std::make_shared(nullptr, node); auto merge = std::make_shared(nullptr, create, create); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*merge, &context)); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); } TEST(QueryPlan, SetPropertyOnNull) { // SET (Null).prop = 42 - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; auto prop = PROPERTY_PAIR("property"); @@ -902,15 +943,15 @@ TEST(QueryPlan, SetPropertyOnNull) { auto once = std::make_shared(); auto set_op = std::make_shared(once, prop.second, n_prop, literal); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*set_op, &context)); } TEST(QueryPlan, SetPropertiesOnNull) { // OPTIONAL MATCH (n) SET n = n - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; auto n = MakeScanAll(storage, symbol_table, "n"); @@ -919,17 +960,17 @@ TEST(QueryPlan, SetPropertiesOnNull) { std::vector{n.sym_}); auto set_op = std::make_shared( optional, n.sym_, n_ident, plan::SetProperties::Op::REPLACE); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*set_op, &context)); } TEST(QueryPlan, SetLabelsOnNull) { // OPTIONAL MATCH (n) SET n :label - database::GraphDb db; - auto dba = db.Access(); - auto label = dba.Label("label"); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); + auto label = dba.NameToLabel("label"); AstStorage storage; SymbolTable symbol_table; auto n = MakeScanAll(storage, symbol_table, "n"); @@ -937,16 +978,16 @@ TEST(QueryPlan, SetLabelsOnNull) { std::vector{n.sym_}); auto set_op = std::make_shared( optional, n.sym_, std::vector{label}); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*set_op, &context)); } TEST(QueryPlan, RemovePropertyOnNull) { // REMOVE (Null).prop - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); AstStorage storage; SymbolTable symbol_table; auto prop = PROPERTY_PAIR("property"); @@ -955,16 +996,16 @@ TEST(QueryPlan, RemovePropertyOnNull) { auto once = std::make_shared(); auto remove_op = std::make_shared(once, prop.second, n_prop); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*remove_op, &context)); } TEST(QueryPlan, RemoveLabelsOnNull) { // OPTIONAL MATCH (n) REMOVE n :label - database::GraphDb db; - auto dba = db.Access(); - auto label = dba.Label("label"); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); + auto label = dba.NameToLabel("label"); AstStorage storage; SymbolTable symbol_table; auto n = MakeScanAll(storage, symbol_table, "n"); @@ -972,19 +1013,19 @@ TEST(QueryPlan, RemoveLabelsOnNull) { std::vector{n.sym_}); auto remove_op = std::make_shared( optional, n.sym_, std::vector{label}); - EXPECT_EQ(0, CountIterable(dba.Vertices(false))); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + EXPECT_EQ(0, CountIterable(dba.Vertices(storage::View::OLD))); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_EQ(1, PullAll(*remove_op, &context)); } TEST(QueryPlan, DeleteSetProperty) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Add a single vertex. dba.InsertVertex(); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); AstStorage storage; SymbolTable symbol_table; // MATCH (n) DELETE n SET n.property = 42 @@ -996,18 +1037,18 @@ TEST(QueryPlan, DeleteSetProperty) { auto n_prop = PROPERTY_LOOKUP(IDENT("n")->MapTo(n.sym_), prop); auto set_op = std::make_shared(delete_op, prop.second, n_prop, LITERAL(42)); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*set_op, &context), QueryRuntimeException); } TEST(QueryPlan, DeleteSetPropertiesFromMap) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Add a single vertex. dba.InsertVertex(); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); AstStorage storage; SymbolTable symbol_table; // MATCH (n) DELETE n SET n = {property: 42} @@ -1023,22 +1064,23 @@ TEST(QueryPlan, DeleteSetPropertiesFromMap) { {plan::SetProperties::Op::REPLACE, plan::SetProperties::Op::UPDATE}) { auto set_op = std::make_shared(delete_op, n.sym_, rhs, op_type); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*set_op, &context), QueryRuntimeException); } } -TEST(QueryPlan, DeleteSetPropertiesFromVertex) { - database::GraphDb db; - auto dba = db.Access(); +TEST(QueryPlan, DeleteSetPropertiesFrom) { + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Add a single vertex. { auto v = dba.InsertVertex(); - v.PropsSet(dba.Property("property"), PropertyValue(1)); + ASSERT_TRUE(v.SetProperty(dba.NameToProperty("property"), PropertyValue(1)) + .HasValue()); } dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); AstStorage storage; SymbolTable symbol_table; // MATCH (n) DELETE n SET n = n @@ -1051,19 +1093,19 @@ TEST(QueryPlan, DeleteSetPropertiesFromVertex) { {plan::SetProperties::Op::REPLACE, plan::SetProperties::Op::UPDATE}) { auto set_op = std::make_shared(delete_op, n.sym_, rhs, op_type); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*set_op, &context), QueryRuntimeException); } } TEST(QueryPlan, DeleteRemoveLabels) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Add a single vertex. dba.InsertVertex(); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); AstStorage storage; SymbolTable symbol_table; // MATCH (n) DELETE n REMOVE n :label @@ -1071,20 +1113,20 @@ TEST(QueryPlan, DeleteRemoveLabels) { auto n_get = storage.Create("n")->MapTo(n.sym_); auto delete_op = std::make_shared( n.op_, std::vector{n_get}, false); - std::vector labels{dba.Label("label")}; + std::vector labels{dba.NameToLabel("label")}; auto rem_op = std::make_shared(delete_op, n.sym_, labels); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*rem_op, &context), QueryRuntimeException); } TEST(QueryPlan, DeleteRemoveProperty) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Add a single vertex. dba.InsertVertex(); dba.AdvanceCommand(); - EXPECT_EQ(1, CountIterable(dba.Vertices(false))); + EXPECT_EQ(1, CountIterable(dba.Vertices(storage::View::OLD))); AstStorage storage; SymbolTable symbol_table; // MATCH (n) DELETE n REMOVE n.property @@ -1096,7 +1138,6 @@ TEST(QueryPlan, DeleteRemoveProperty) { auto n_prop = PROPERTY_LOOKUP(IDENT("n")->MapTo(n.sym_), prop); auto rem_op = std::make_shared(delete_op, prop.second, n_prop); - query::DbAccessor execution_dba(&dba); - auto context = MakeContext(storage, symbol_table, &execution_dba); + auto context = MakeContext(storage, symbol_table, &dba); EXPECT_THROW(PullAll(*rem_op, &context), QueryRuntimeException); } diff --git a/tests/unit/query_variable_start_planner.cpp b/tests/unit/query_variable_start_planner.cpp index 8f5acf41b..5fd9d7535 100644 --- a/tests/unit/query_variable_start_planner.cpp +++ b/tests/unit/query_variable_start_planner.cpp @@ -86,12 +86,13 @@ void CheckPlansProduce( } TEST(TestVariableStartPlanner, MatchReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Make a graph (v1) -[:r]-> (v2) auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); - dba.InsertEdge(v1, v2, dba.EdgeType("r")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r")).HasValue()); dba.AdvanceCommand(); // Test MATCH (n) -[r]-> (m) RETURN n AstStorage storage; @@ -99,24 +100,22 @@ TEST(TestVariableStartPlanner, MatchReturn) { MATCH(PATTERN(NODE("n"), EDGE("r", Direction::OUT), NODE("m"))), RETURN("n"))); // We have 2 nodes `n` and `m` from which we could start, so expect 2 plans. - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 2, query, storage, &execution_dba, [&](const auto &results) { - // We expect to produce only a single (v1) node. - AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, - execution_dba); - }); + CheckPlansProduce(2, query, storage, &dba, [&](const auto &results) { + // We expect to produce only a single (v1) node. + AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, dba); + }); } TEST(TestVariableStartPlanner, MatchTripletPatternReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Make a graph (v1) -[:r]-> (v2) -[:r]-> (v3) auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - dba.InsertEdge(v1, v2, dba.EdgeType("r")); - dba.InsertEdge(v2, v3, dba.EdgeType("r")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r")).HasValue()); + ASSERT_TRUE(dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r")).HasValue()); dba.AdvanceCommand(); { // Test `MATCH (n) -[r]-> (m) -[e]-> (l) RETURN n` @@ -126,13 +125,10 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) { EDGE("e", Direction::OUT), NODE("l"))), RETURN("n"))); // We have 3 nodes: `n`, `m` and `l` from which we could start. - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 3, query, storage, &execution_dba, [&](const auto &results) { - // We expect to produce only a single (v1) node. - AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, - execution_dba); - }); + CheckPlansProduce(3, query, storage, &dba, [&](const auto &results) { + // We expect to produce only a single (v1) node. + AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, dba); + }); } { // Equivalent to `MATCH (n) -[r]-> (m), (m) -[e]-> (l) RETURN n`. @@ -141,24 +137,22 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) { MATCH(PATTERN(NODE("n"), EDGE("r", Direction::OUT), NODE("m")), PATTERN(NODE("m"), EDGE("e", Direction::OUT), NODE("l"))), RETURN("n"))); - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 3, query, storage, &execution_dba, [&](const auto &results) { - AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, - execution_dba); - }); + CheckPlansProduce(3, query, storage, &dba, [&](const auto &results) { + AssertRows(results, {{TypedValue(query::VertexAccessor(v1))}}, dba); + }); } } TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Make a graph (v1) -[:r]-> (v2) -[:r]-> (v3) auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - dba.InsertEdge(v1, v2, dba.EdgeType("r")); - dba.InsertEdge(v2, v3, dba.EdgeType("r")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r")).HasValue()); + ASSERT_TRUE(dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r")).HasValue()); dba.AdvanceCommand(); // Test MATCH (n) -[r]-> (m) OPTIONAL MATCH (m) -[e]-> (l) RETURN n, l AstStorage storage; @@ -168,29 +162,28 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) { RETURN("n", "l"))); // We have 2 nodes `n` and `m` from which we could start the MATCH, and 2 // nodes for OPTIONAL MATCH. This should produce 2 * 2 plans. - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 4, query, storage, &execution_dba, [&](const auto &results) { - // We expect to produce 2 rows: - // * (v1), (v3) - // * (v2), null - AssertRows(results, - {{TypedValue(query::VertexAccessor(v1)), - TypedValue(query::VertexAccessor(v3))}, - {TypedValue(query::VertexAccessor(v2)), TypedValue()}}, - execution_dba); - }); + CheckPlansProduce(4, query, storage, &dba, [&](const auto &results) { + // We expect to produce 2 rows: + // * (v1), (v3) + // * (v2), null + AssertRows(results, + {{TypedValue(query::VertexAccessor(v1)), + TypedValue(query::VertexAccessor(v3))}, + {TypedValue(query::VertexAccessor(v2)), TypedValue()}}, + dba); + }); } TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Graph (v1) -[:r]-> (v2) query::VertexAccessor v1(dba.InsertVertex()); query::VertexAccessor v2(dba.InsertVertex()); auto r_type_name = "r"; - auto r_type = dba.EdgeType(r_type_name); - dba.InsertEdge(v1.impl_, v2.impl_, r_type); + auto r_type = dba.NameToEdgeType(r_type_name); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, r_type).HasValue()); dba.AdvanceCommand(); // Test MATCH (n) -[r]-> (m) OPTIONAL MATCH (m) -[e]-> (l) // MERGE (u) -[q:r]-> (v) RETURN n, m, l, u, v @@ -203,24 +196,23 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) { RETURN("n", "m", "l", "u", "v"))); // Since MATCH, OPTIONAL MATCH and MERGE each have 2 nodes from which we can // start, we generate 2 * 2 * 2 plans. - query::DbAccessor execution_dba(&dba); - CheckPlansProduce(8, query, storage, &execution_dba, - [&](const auto &results) { - // We expect to produce a single row: (v1), (v2), null, (v1), (v2) - AssertRows(results, - {{TypedValue(v1), TypedValue(v2), TypedValue(), - TypedValue(v1), TypedValue(v2)}}, - execution_dba); - }); + CheckPlansProduce(8, query, storage, &dba, [&](const auto &results) { + // We expect to produce a single row: (v1), (v2), null, (v1), (v2) + AssertRows(results, + {{TypedValue(v1), TypedValue(v2), TypedValue(), TypedValue(v1), + TypedValue(v2)}}, + dba); + }); } TEST(TestVariableStartPlanner, MatchWithMatchReturn) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Graph (v1) -[:r]-> (v2) query::VertexAccessor v1(dba.InsertVertex()); query::VertexAccessor v2(dba.InsertVertex()); - dba.InsertEdge(v1.impl_, v2.impl_, dba.EdgeType("r")); + ASSERT_TRUE(dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r")).HasValue()); dba.AdvanceCommand(); // Test MATCH (n) -[r]-> (m) WITH n MATCH (m) -[r]-> (l) RETURN n, m, l AstStorage storage; @@ -231,24 +223,23 @@ TEST(TestVariableStartPlanner, MatchWithMatchReturn) { RETURN("n", "m", "l"))); // We can start from 2 nodes in each match. Since WITH separates query parts, // we expect to get 2 plans for each, which totals 2 * 2. - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 4, query, storage, &execution_dba, [&](const auto &results) { - // We expect to produce a single row: (v1), (v1), (v2) - AssertRows(results, {{TypedValue(v1), TypedValue(v1), TypedValue(v2)}}, - execution_dba); - }); + CheckPlansProduce(4, query, storage, &dba, [&](const auto &results) { + // We expect to produce a single row: (v1), (v1), (v2) + AssertRows(results, {{TypedValue(v1), TypedValue(v1), TypedValue(v2)}}, + dba); + }); } TEST(TestVariableStartPlanner, MatchVariableExpand) { - database::GraphDb db; - auto dba = db.Access(); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); // Graph (v1) -[:r1]-> (v2) -[:r2]-> (v3) auto v1 = dba.InsertVertex(); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - query::EdgeAccessor r1(dba.InsertEdge(v1, v2, dba.EdgeType("r1"))); - query::EdgeAccessor r2(dba.InsertEdge(v2, v3, dba.EdgeType("r2"))); + auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); + auto r2 = *dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")); dba.AdvanceCommand(); // Test MATCH (n) -[r*]-> (m) RETURN r AstStorage storage; @@ -261,27 +252,25 @@ TEST(TestVariableStartPlanner, MatchVariableExpand) { // [r1, r2] TypedValue r1_r2_list( std::vector{TypedValue(r1), TypedValue(r2)}); - query::DbAccessor execution_dba(&dba); - CheckPlansProduce(2, query, storage, &execution_dba, - [&](const auto &results) { - AssertRows(results, {{r1_list}, {r2_list}, {r1_r2_list}}, - execution_dba); - }); + CheckPlansProduce(2, query, storage, &dba, [&](const auto &results) { + AssertRows(results, {{r1_list}, {r2_list}, {r1_r2_list}}, dba); + }); } TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) { - database::GraphDb db; - auto dba = db.Access(); - auto id = dba.Property("id"); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); + auto id = dba.NameToProperty("id"); // Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3}) auto v1 = dba.InsertVertex(); - v1.PropsSet(id, PropertyValue(1)); + ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); auto v2 = dba.InsertVertex(); - v2.PropsSet(id, PropertyValue(2)); + ASSERT_TRUE(v2.SetProperty(id, PropertyValue(2)).HasValue()); auto v3 = dba.InsertVertex(); - v3.PropsSet(id, PropertyValue(3)); - query::EdgeAccessor r1(dba.InsertEdge(v1, v2, dba.EdgeType("r1"))); - query::EdgeAccessor r2(dba.InsertEdge(v2, v3, dba.EdgeType("r2"))); + ASSERT_TRUE(v3.SetProperty(id, PropertyValue(3)).HasValue()); + auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); + auto r2 = *dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")); dba.AdvanceCommand(); // Test MATCH (n) -[r*..n.id]-> (m) RETURN r AstStorage storage; @@ -294,24 +283,23 @@ TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) { TypedValue r1_list(std::vector{TypedValue(r1)}); // [r2] (v2 -[*..2]-> v3) TypedValue r2_list(std::vector{TypedValue(r2)}); - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 2, query, storage, &execution_dba, [&](const auto &results) { - AssertRows(results, {{r1_list}, {r2_list}}, execution_dba); - }); + CheckPlansProduce(2, query, storage, &dba, [&](const auto &results) { + AssertRows(results, {{r1_list}, {r2_list}}, dba); + }); } TEST(TestVariableStartPlanner, MatchVariableExpandBoth) { - database::GraphDb db; - auto dba = db.Access(); - auto id = dba.Property("id"); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); + auto id = dba.NameToProperty("id"); // Graph (v1 {id:1}) -[:r1]-> (v2) -[:r2]-> (v3) auto v1 = dba.InsertVertex(); - v1.PropsSet(id, PropertyValue(1)); + ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); auto v2 = dba.InsertVertex(); auto v3 = dba.InsertVertex(); - query::EdgeAccessor r1(dba.InsertEdge(v1, v2, dba.EdgeType("r1"))); - query::EdgeAccessor r2(dba.InsertEdge(v2, v3, dba.EdgeType("r2"))); + auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); + auto r2 = *dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")); dba.AdvanceCommand(); // Test MATCH (n {id:1}) -[r*]- (m) RETURN r AstStorage storage; @@ -325,26 +313,25 @@ TEST(TestVariableStartPlanner, MatchVariableExpandBoth) { // [r1, r2] TypedValue r1_r2_list( std::vector{TypedValue(r1), TypedValue(r2)}); - query::DbAccessor execution_dba(&dba); - CheckPlansProduce( - 2, query, storage, &execution_dba, [&](const auto &results) { - AssertRows(results, {{r1_list}, {r1_r2_list}}, execution_dba); - }); + CheckPlansProduce(2, query, storage, &dba, [&](const auto &results) { + AssertRows(results, {{r1_list}, {r1_r2_list}}, dba); + }); } TEST(TestVariableStartPlanner, MatchBfs) { - database::GraphDb db; - auto dba = db.Access(); - auto id = dba.Property("id"); + storage::Storage db; + auto storage_dba = db.Access(); + query::DbAccessor dba(&storage_dba); + auto id = dba.NameToProperty("id"); // Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3}) auto v1 = dba.InsertVertex(); - v1.PropsSet(id, PropertyValue(1)); + ASSERT_TRUE(v1.SetProperty(id, PropertyValue(1)).HasValue()); auto v2 = dba.InsertVertex(); - v2.PropsSet(id, PropertyValue(2)); + ASSERT_TRUE(v2.SetProperty(id, PropertyValue(2)).HasValue()); auto v3 = dba.InsertVertex(); - v3.PropsSet(id, PropertyValue(3)); - query::EdgeAccessor r1(dba.InsertEdge(v1, v2, dba.EdgeType("r1"))); - dba.InsertEdge(v2, v3, dba.EdgeType("r2")); + ASSERT_TRUE(v3.SetProperty(id, PropertyValue(3)).HasValue()); + auto r1 = *dba.InsertEdge(&v1, &v2, dba.NameToEdgeType("r1")); + ASSERT_TRUE(dba.InsertEdge(&v2, &v3, dba.NameToEdgeType("r2")).HasValue()); dba.AdvanceCommand(); // Test MATCH (n) -[r *bfs..10](r, n | n.id <> 3)]-> (m) RETURN r AstStorage storage; @@ -359,11 +346,9 @@ TEST(TestVariableStartPlanner, MatchBfs) { SINGLE_QUERY(MATCH(PATTERN(NODE("n"), bfs, NODE("m"))), RETURN("r"))); // We expect to get a single column with the following rows: TypedValue r1_list(std::vector{TypedValue(r1)}); // [r1] - query::DbAccessor execution_dba(&dba); - CheckPlansProduce(2, query, storage, &execution_dba, - [&](const auto &results) { - AssertRows(results, {{r1_list}}, execution_dba); - }); + CheckPlansProduce(2, query, storage, &dba, [&](const auto &results) { + AssertRows(results, {{r1_list}}, dba); + }); } } // namespace