Remove Dbms
Summary: Remove name from GraphDb. Take GraphDb in query test macros instead of accessor. Add is_accepting_transactions flag to GraphDb. Reviewers: mislav.bradac, florijan, mferencevic Reviewed By: mislav.bradac Subscribers: mferencevic, pullbot Differential Revision: https://phabricator.memgraph.io/D940
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "database/dbms.hpp"
|
||||
#include "query/frontend/semantic/symbol_generator.hpp"
|
||||
#include "query/frontend/semantic/symbol_table.hpp"
|
||||
#include "query/plan/planner.hpp"
|
||||
@@ -79,34 +78,34 @@ void CheckPlansProduce(
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchReturn) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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
|
||||
AstTreeStorage storage;
|
||||
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}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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`
|
||||
AstTreeStorage storage;
|
||||
@@ -114,7 +113,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}});
|
||||
});
|
||||
@@ -125,22 +124,22 @@ TEST(TestVariableStartPlanner, MatchTripletPatternReturn) {
|
||||
QUERY(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}});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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
|
||||
AstTreeStorage storage;
|
||||
QUERY(
|
||||
@@ -149,7 +148,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
|
||||
@@ -158,14 +157,14 @@ TEST(TestVariableStartPlanner, MatchOptionalMatchReturn) {
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchOptionalMatchMergeReturn) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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
|
||||
AstTreeStorage storage;
|
||||
@@ -176,20 +175,20 @@ 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}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchWithMatchReturn) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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
|
||||
AstTreeStorage storage;
|
||||
QUERY(MATCH(PATTERN(NODE("n"), EDGE("r", Direction::OUT), NODE("m"))),
|
||||
@@ -198,22 +197,22 @@ 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}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchVariableExpand) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
// 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
|
||||
AstTreeStorage storage;
|
||||
auto edge = EDGE_VARIABLE("r", Direction::OUT);
|
||||
@@ -222,25 +221,25 @@ 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) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
auto id = dba->Property("id");
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
auto id = dba.Property("id");
|
||||
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(id, 1);
|
||||
auto v2 = dba->InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.PropsSet(id, 2);
|
||||
auto v3 = dba->InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
v3.PropsSet(id, 3);
|
||||
auto r1 = dba->InsertEdge(v1, v2, dba->EdgeType("r1"));
|
||||
auto r2 = dba->InsertEdge(v2, v3, dba->EdgeType("r2"));
|
||||
dba->AdvanceCommand();
|
||||
auto r1 = dba.InsertEdge(v1, v2, dba.EdgeType("r1"));
|
||||
auto r2 = dba.InsertEdge(v2, v3, dba.EdgeType("r2"));
|
||||
dba.AdvanceCommand();
|
||||
// Test MATCH (n) -[r*..n.id]-> (m) RETURN r
|
||||
AstTreeStorage storage;
|
||||
auto edge = EDGE_VARIABLE("r", Direction::OUT);
|
||||
@@ -249,23 +248,23 @@ TEST(TestVariableStartPlanner, MatchVariableExpandReferenceNode) {
|
||||
// We expect to get a single column with the following rows:
|
||||
TypedValue r1_list(std::vector<TypedValue>{r1}); // [r1] (v1 -[*..1]-> v2)
|
||||
TypedValue r2_list(std::vector<TypedValue>{r2}); // [r2] (v2 -[*..2]-> v3)
|
||||
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
|
||||
CheckPlansProduce(2, storage, dba, [&](const auto &results) {
|
||||
AssertRows(results, {{r1_list}, {r2_list}});
|
||||
});
|
||||
}
|
||||
|
||||
TEST(TestVariableStartPlanner, MatchVariableExpandBoth) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
auto id = dba->Property("id");
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
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
|
||||
AstTreeStorage storage;
|
||||
auto edge = EDGE_VARIABLE("r", Direction::BOTH);
|
||||
@@ -275,25 +274,25 @@ 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) {
|
||||
Dbms dbms;
|
||||
auto dba = dbms.active();
|
||||
auto id = dba->Property("id");
|
||||
GraphDb db;
|
||||
GraphDbAccessor dba(db);
|
||||
auto id = dba.Property("id");
|
||||
// Graph (v1 {id:1}) -[:r1]-> (v2 {id: 2}) -[:r2]-> (v3 {id: 3})
|
||||
auto v1 = dba->InsertVertex();
|
||||
auto v1 = dba.InsertVertex();
|
||||
v1.PropsSet(id, 1);
|
||||
auto v2 = dba->InsertVertex();
|
||||
auto v2 = dba.InsertVertex();
|
||||
v2.PropsSet(id, 2);
|
||||
auto v3 = dba->InsertVertex();
|
||||
auto v3 = dba.InsertVertex();
|
||||
v3.PropsSet(id, 3);
|
||||
auto r1 = dba->InsertEdge(v1, v2, dba->EdgeType("r1"));
|
||||
dba->InsertEdge(v2, v3, dba->EdgeType("r2"));
|
||||
dba->AdvanceCommand();
|
||||
auto r1 = dba.InsertEdge(v1, v2, dba.EdgeType("r1"));
|
||||
dba.InsertEdge(v2, v3, dba.EdgeType("r2"));
|
||||
dba.AdvanceCommand();
|
||||
// Test MATCH (n) -[r *bfs..10](r, n | n.id <> 3)]-> (m) RETURN r
|
||||
AstTreeStorage storage;
|
||||
auto *bfs = storage.Create<query::EdgeAtom>(
|
||||
@@ -306,7 +305,7 @@ TEST(TestVariableStartPlanner, MatchBfs) {
|
||||
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]
|
||||
CheckPlansProduce(2, storage, *dba, [&](const auto &results) {
|
||||
CheckPlansProduce(2, storage, dba, [&](const auto &results) {
|
||||
AssertRows(results, {{r1_list}});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user