Separate distributed implementation of GraphDbAccessor
Summary: GraphDbAccessor is now constructed only through GraphDb. This allows the concrete GraphDb to instantiate a concrete GraphDbAccessor. This allows us to use virtual calls, so that the implementation may be kept separate. The major downside of doing things this way is heap allocation of GraphDbAccessor. In case it turns out to be a real performance issues, another solution with pointer to static implementation may be used. InsertVertexIntoRemote is now a non-member function, which reduces coupling. It made no sense for it to be member function because it used only the public parts of GraphDbAccessor. Reviewers: msantl, mtomic, mferencevic Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1504
This commit is contained in:
@@ -84,19 +84,19 @@ void CheckPlansProduce(
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchReturn) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// Make a graph (v1) -[:r]-> (v2)
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
dba.InsertEdge(v1, v2, dba.EdgeType("r"));
|
||||
dba.AdvanceCommand();
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v2 = dba->InsertVertex();
|
||||
dba->InsertEdge(v1, v2, dba->EdgeType("r"));
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n) -[r]-> (m) RETURN n
|
||||
AstStorage storage;
|
||||
QUERY(SINGLE_QUERY(
|
||||
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.
|
||||
CheckPlansProduce(2, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
|
||||
// We expect to produce only a single (v1) node.
|
||||
AssertRows(results, {{v1}});
|
||||
});
|
||||
@@ -104,14 +104,14 @@ TEST(TestVariableStartPlanner, MatchReturn) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// 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"));
|
||||
dba.AdvanceCommand();
|
||||
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"));
|
||||
dba->AdvanceCommand();
|
||||
{
|
||||
// Test `MATCH (n) -[r]-> (m) -[e]-> (l) RETURN n`
|
||||
AstStorage storage;
|
||||
@@ -120,7 +120,7 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
EDGE("e", Direction::OUT), NODE("l"))),
|
||||
RETURN("n")));
|
||||
// We have 3 nodes: `n`, `m` and `l` from which we could start.
|
||||
CheckPlansProduce(3, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(3, storage, *dba, [&](const auto &results) {
|
||||
// We expect to produce only a single (v1) node.
|
||||
AssertRows(results, {{v1}});
|
||||
});
|
||||
@@ -132,7 +132,7 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
MATCH(PATTERN(NODE("n"), EDGE("r", Direction::OUT), NODE("m")),
|
||||
PATTERN(NODE("m"), EDGE("e", Direction::OUT), NODE("l"))),
|
||||
RETURN("n")));
|
||||
CheckPlansProduce(3, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(3, storage, *dba, [&](const auto &results) {
|
||||
AssertRows(results, {{v1}});
|
||||
});
|
||||
}
|
||||
@@ -140,14 +140,14 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// 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"));
|
||||
dba.AdvanceCommand();
|
||||
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"));
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n) -[r]-> (m) OPTIONAL MATCH (m) -[e]-> (l) RETURN n, l
|
||||
AstStorage storage;
|
||||
QUERY(SINGLE_QUERY(
|
||||
@@ -156,7 +156,7 @@ 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.
|
||||
CheckPlansProduce(4, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(4, storage, *dba, [&](const auto &results) {
|
||||
// We expect to produce 2 rows:
|
||||
// * (v1), (v3)
|
||||
// * (v2), null
|
||||
@@ -166,13 +166,13 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// Graph (v1) -[:r]-> (v2)
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto r_type = dba.EdgeType("r");
|
||||
dba.InsertEdge(v1, v2, r_type);
|
||||
dba.AdvanceCommand();
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v2 = dba->InsertVertex();
|
||||
auto r_type = dba->EdgeType("r");
|
||||
dba->InsertEdge(v1, v2, r_type);
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n) -[r]-> (m) OPTIONAL MATCH (m) -[e]-> (l)
|
||||
// MERGE (u) -[q:r]-> (v) RETURN n, m, l, u, v
|
||||
AstStorage storage;
|
||||
@@ -183,7 +183,7 @@ 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.
|
||||
CheckPlansProduce(8, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(8, storage, *dba, [&](const auto &results) {
|
||||
// We expect to produce a single row: (v1), (v2), null, (v1), (v2)
|
||||
AssertRows(results, {{v1, v2, TypedValue::Null, v1, v2}});
|
||||
});
|
||||
@@ -191,12 +191,12 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchWithMatchReturn) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// Graph (v1) -[:r]-> (v2)
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
dba.InsertEdge(v1, v2, dba.EdgeType("r"));
|
||||
dba.AdvanceCommand();
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v2 = dba->InsertVertex();
|
||||
dba->InsertEdge(v1, v2, dba->EdgeType("r"));
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n) -[r]-> (m) WITH n MATCH (m) -[r]-> (l) RETURN n, m, l
|
||||
AstStorage storage;
|
||||
QUERY(SINGLE_QUERY(
|
||||
@@ -206,7 +206,7 @@ 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.
|
||||
CheckPlansProduce(4, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(4, storage, *dba, [&](const auto &results) {
|
||||
// We expect to produce a single row: (v1), (v1), (v2)
|
||||
AssertRows(results, {{v1, v1, v2}});
|
||||
});
|
||||
@@ -214,14 +214,14 @@ TEST(TestVariableStartPlanner, MatchWithMatchReturn) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchVariableExpand) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba = db.Access();
|
||||
// Graph (v1) -[:r1]-> (v2) -[:r2]-> (v3)
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto r1 = dba.InsertEdge(v1, v2, dba.EdgeType("r1"));
|
||||
auto r2 = dba.InsertEdge(v2, v3, dba.EdgeType("r2"));
|
||||
dba.AdvanceCommand();
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v2 = dba->InsertVertex();
|
||||
auto v3 = dba->InsertVertex();
|
||||
auto r1 = dba->InsertEdge(v1, v2, dba->EdgeType("r1"));
|
||||
auto r2 = dba->InsertEdge(v2, v3, dba->EdgeType("r2"));
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n) -[r*]-> (m) RETURN r
|
||||
AstStorage storage;
|
||||
auto edge = EDGE_VARIABLE("r", Direction::OUT);
|
||||
@@ -230,14 +230,15 @@ TEST(TestVariableStartPlanner, MatchVariableExpand) {
|
||||
TypedValue r1_list(std::vector<TypedValue>{r1}); // [r1]
|
||||
TypedValue r2_list(std::vector<TypedValue>{r2}); // [r2]
|
||||
TypedValue r1_r2_list(std::vector<TypedValue>{r1, r2}); // [r1, r2]
|
||||
CheckPlansProduce(2, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
|
||||
AssertRows(results, {{r1_list}, {r2_list}, {r1_r2_list}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba_ptr = db.Access();
|
||||
auto &dba = *dba_ptr;
|
||||
auto id = dba.Property("id");
|
||||
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
|
||||
auto v1 = dba.InsertVertex();
|
||||
@@ -264,16 +265,16 @@ TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) {
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchVariableExpandBoth) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto id = dba.Property("id");
|
||||
auto dba = db.Access();
|
||||
auto id = dba->Property("id");
|
||||
// Graph (v1 {id:1}) -[:r1]-> (v2) -[:r2]-> (v3)
|
||||
auto v1 = dba.InsertVertex();
|
||||
auto v1 = dba->InsertVertex();
|
||||
v1.PropsSet(id, 1);
|
||||
auto v2 = dba.InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
auto r1 = dba.InsertEdge(v1, v2, dba.EdgeType("r1"));
|
||||
auto r2 = dba.InsertEdge(v2, v3, dba.EdgeType("r2"));
|
||||
dba.AdvanceCommand();
|
||||
auto v2 = dba->InsertVertex();
|
||||
auto v3 = dba->InsertVertex();
|
||||
auto r1 = dba->InsertEdge(v1, v2, dba->EdgeType("r1"));
|
||||
auto r2 = dba->InsertEdge(v2, v3, dba->EdgeType("r2"));
|
||||
dba->AdvanceCommand();
|
||||
// Test MATCH (n {id:1}) -[r*]- (m) RETURN r
|
||||
AstStorage storage;
|
||||
auto edge = EDGE_VARIABLE("r", Direction::BOTH);
|
||||
@@ -283,14 +284,15 @@ TEST(TestVariableStartPlanner, MatchVariableExpandBoth) {
|
||||
// We expect to get a single column with the following rows:
|
||||
TypedValue r1_list(std::vector<TypedValue>{r1}); // [r1]
|
||||
TypedValue r1_r2_list(std::vector<TypedValue>{r1, r2}); // [r1, r2]
|
||||
CheckPlansProduce(2, storage, dba, [&](const auto &results) {
|
||||
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
|
||||
AssertRows(results, {{r1_list}, {r1_r2_list}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchBfs) {
|
||||
database::SingleNode db;
|
||||
database::GraphDbAccessor dba(db);
|
||||
auto dba_ptr = db.Access();
|
||||
auto &dba = *dba_ptr;
|
||||
auto id = dba.Property("id");
|
||||
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
|
||||
auto v1 = dba.InsertVertex();
|
||||
|
||||
Reference in New Issue
Block a user