2018-10-23 22:01:02 +08:00
|
|
|
#include <atomic>
|
2017-07-05 22:00:07 +08:00
|
|
|
#include <experimental/optional>
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
#include <memory>
|
2017-08-11 15:48:13 +08:00
|
|
|
#include <thread>
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-06-21 17:29:13 +08:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2018-10-05 18:37:23 +08:00
|
|
|
#include "database/single_node/graph_db.hpp"
|
|
|
|
#include "database/single_node/graph_db_accessor.hpp"
|
2017-07-05 22:00:07 +08:00
|
|
|
#include "utils/bound.hpp"
|
2017-04-21 21:39:41 +08:00
|
|
|
|
|
|
|
using testing::UnorderedElementsAreArray;
|
|
|
|
|
|
|
|
template <typename TIterable>
|
|
|
|
auto Count(TIterable iterable) {
|
|
|
|
return std::distance(iterable.begin(), iterable.end());
|
|
|
|
}
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
/**
|
|
|
|
* A test fixture that contains a database, accessor,
|
|
|
|
* label, property and an edge_type.
|
|
|
|
*/
|
|
|
|
class GraphDbAccessorIndex : public testing::Test {
|
|
|
|
protected:
|
2018-10-09 17:09:10 +08:00
|
|
|
database::GraphDb db;
|
2018-07-26 15:08:21 +08:00
|
|
|
std::unique_ptr<database::GraphDbAccessor> dba{db.Access()};
|
2018-01-16 17:09:15 +08:00
|
|
|
storage::Property property = dba->Property("property");
|
|
|
|
storage::Label label = dba->Label("label");
|
|
|
|
storage::EdgeType edge_type = dba->EdgeType("edge_type");
|
2017-04-21 21:39:41 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
auto AddVertex() {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex = dba->InsertVertex();
|
2017-07-13 17:24:18 +08:00
|
|
|
vertex.add_label(label);
|
|
|
|
return vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto AddVertex(int property_value) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex = dba->InsertVertex();
|
2017-07-13 17:24:18 +08:00
|
|
|
vertex.add_label(label);
|
|
|
|
vertex.PropsSet(property, property_value);
|
|
|
|
return vertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// commits the current dba, and replaces it with a new one
|
|
|
|
void Commit() {
|
2017-08-09 21:36:01 +08:00
|
|
|
dba->Commit();
|
2018-07-26 15:08:21 +08:00
|
|
|
dba = db.Access();
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(GraphDbAccessorIndex, LabelIndexCount) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto label2 = dba->Label("label2");
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label), 0);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label2), 0);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(), 0);
|
|
|
|
for (int i = 0; i < 11; ++i) dba->InsertVertex().add_label(label);
|
|
|
|
for (int i = 0; i < 17; ++i) dba->InsertVertex().add_label(label2);
|
2018-01-12 22:17:04 +08:00
|
|
|
// even though xxx_count functions in database::GraphDbAccessor can
|
|
|
|
// over-estaimate in this situation they should be exact (nothing was ever
|
|
|
|
// deleted)
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label), 11);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label2), 17);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(), 28);
|
2017-04-21 21:39:41 +08:00
|
|
|
}
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelIndexIteration) {
|
|
|
|
// add 10 vertices, check visibility
|
|
|
|
for (int i = 0; i < 10; i++) AddVertex();
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, false)), 0);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, true)), 10);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, false)), 10);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, true)), 10);
|
2017-07-13 17:24:18 +08:00
|
|
|
|
|
|
|
// remove 3 vertices, check visibility
|
|
|
|
int deleted = 0;
|
2017-08-09 21:36:01 +08:00
|
|
|
for (auto vertex : dba->Vertices(false)) {
|
|
|
|
dba->RemoveVertex(vertex);
|
2017-07-13 17:24:18 +08:00
|
|
|
if (++deleted >= 3) break;
|
|
|
|
}
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, false)), 10);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, true)), 7);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, false)), 7);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, true)), 7);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-10-06 19:29:40 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, EdgesCount) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto edge_type2 = dba->EdgeType("edge_type2");
|
|
|
|
EXPECT_EQ(dba->EdgesCount(), 0);
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
auto v1 = AddVertex();
|
|
|
|
auto v2 = AddVertex();
|
2017-08-09 21:36:01 +08:00
|
|
|
for (int i = 0; i < 11; ++i) dba->InsertEdge(v1, v2, edge_type);
|
|
|
|
for (int i = 0; i < 17; ++i) dba->InsertEdge(v1, v2, edge_type2);
|
2018-01-12 22:17:04 +08:00
|
|
|
// even though xxx_count functions in database::GraphDbAccessor can
|
|
|
|
// over-estaimate in this situation they should be exact (nothing was ever
|
|
|
|
// deleted)
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->EdgesCount(), 28);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyIndexBuild) {
|
|
|
|
AddVertex(0);
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 1);
|
2017-07-13 17:24:18 +08:00
|
|
|
|
|
|
|
// confirm there is a differentiation of indexes based on (label, property)
|
2017-08-09 21:36:01 +08:00
|
|
|
auto label2 = dba->Label("label2");
|
|
|
|
auto property2 = dba->Property("property2");
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label2, property, false);
|
|
|
|
dba->BuildIndex(label, property2, false);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
|
|
|
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 1);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label2, property), 0);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property2), 0);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 16:55:53 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyIndexDelete) {
|
|
|
|
dba->BuildIndex(label, property, false);
|
|
|
|
Commit();
|
|
|
|
EXPECT_TRUE(dba->LabelPropertyIndexExists(label, property));
|
|
|
|
|
|
|
|
dba->DeleteIndex(label, property);
|
|
|
|
Commit();
|
|
|
|
|
|
|
|
EXPECT_FALSE(dba->LabelPropertyIndexExists(label, property));
|
|
|
|
}
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyIndexBuildTwice) {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
|
|
|
EXPECT_THROW(dba->BuildIndex(label, property, false), utils::BasicException);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyIndexCount) {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 0);
|
2017-11-23 23:36:54 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, true)), 0);
|
2017-07-13 17:24:18 +08:00
|
|
|
for (int i = 0; i < 14; ++i) AddVertex(0);
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 14);
|
2017-11-23 23:36:54 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, true)), 14);
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
}
|
|
|
|
|
2017-08-11 15:48:13 +08:00
|
|
|
TEST(GraphDbAccessorIndexApi, LabelPropertyBuildIndexConcurrent) {
|
2018-10-23 22:01:02 +08:00
|
|
|
const int THREAD_COUNT = 10;
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
database::GraphDb db;
|
|
|
|
std::atomic<bool> failed{false};
|
|
|
|
for (int index = 0; index < THREAD_COUNT; ++index) {
|
|
|
|
threads.emplace_back([&db, &failed, index]() {
|
|
|
|
// If we fail to create a new transaction, don't bother.
|
|
|
|
try {
|
2018-07-26 15:08:21 +08:00
|
|
|
auto dba = db.Access();
|
2018-10-23 22:01:02 +08:00
|
|
|
try {
|
|
|
|
// This could either pass or throw.
|
|
|
|
dba->BuildIndex(dba->Label("l" + std::to_string(index)),
|
|
|
|
dba->Property("p" + std::to_string(index)), false);
|
|
|
|
// If it throws, make sure the exception is right.
|
2018-10-26 16:55:53 +08:00
|
|
|
} catch (const database::IndexTransactionException &e) {
|
2018-10-23 22:01:02 +08:00
|
|
|
// Nothing to see here, move along.
|
|
|
|
} catch (...) {
|
|
|
|
failed.store(true);
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
// Ignore this one also.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-11-28 20:02:58 +08:00
|
|
|
|
2018-10-23 22:01:02 +08:00
|
|
|
for (auto &thread : threads) {
|
|
|
|
if (thread.joinable()) {
|
|
|
|
thread.join();
|
2017-11-28 20:02:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-23 22:01:02 +08:00
|
|
|
|
|
|
|
EXPECT_FALSE(failed.load());
|
2017-08-11 15:48:13 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 22:00:07 +08:00
|
|
|
#define EXPECT_WITH_MARGIN(x, center) \
|
|
|
|
EXPECT_THAT( \
|
|
|
|
x, testing::AllOf(testing::Ge(center - 2), testing::Le(center + 2)));
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyValueCount) {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-07-05 22:00:07 +08:00
|
|
|
|
|
|
|
// add some vertices without the property
|
2017-07-13 17:24:18 +08:00
|
|
|
for (int i = 0; i < 20; i++) AddVertex();
|
2017-07-05 22:00:07 +08:00
|
|
|
|
|
|
|
// add vertices with prop values [0, 29), ten vertices for each value
|
2017-07-13 17:24:18 +08:00
|
|
|
for (int i = 0; i < 300; i++) AddVertex(i / 10);
|
2017-07-05 22:00:07 +08:00
|
|
|
// add verties in t he [30, 40) range, 100 vertices for each value
|
2017-07-13 17:24:18 +08:00
|
|
|
for (int i = 0; i < 1000; i++) AddVertex(30 + i / 100);
|
2017-07-05 22:00:07 +08:00
|
|
|
|
|
|
|
// test estimates for exact value count
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_WITH_MARGIN(dba->VerticesCount(label, property, 10), 10);
|
|
|
|
EXPECT_WITH_MARGIN(dba->VerticesCount(label, property, 14), 10);
|
|
|
|
EXPECT_WITH_MARGIN(dba->VerticesCount(label, property, 30), 100);
|
|
|
|
EXPECT_WITH_MARGIN(dba->VerticesCount(label, property, 39), 100);
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property, 40), 0);
|
2017-07-05 22:00:07 +08:00
|
|
|
|
|
|
|
// helper functions
|
|
|
|
auto Inclusive = [](int64_t value) {
|
|
|
|
return std::experimental::make_optional(
|
|
|
|
utils::MakeBoundInclusive(PropertyValue(value)));
|
|
|
|
};
|
|
|
|
auto Exclusive = [](int64_t value) {
|
|
|
|
return std::experimental::make_optional(
|
|
|
|
utils::MakeBoundExclusive(PropertyValue(value)));
|
|
|
|
};
|
2017-08-09 21:36:01 +08:00
|
|
|
auto VerticesCount = [this](auto lower, auto upper) {
|
|
|
|
return dba->VerticesCount(label, property, lower, upper);
|
2017-07-05 22:00:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
using std::experimental::nullopt;
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_DEATH(VerticesCount(nullopt, nullopt), "bound must be provided");
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(nullopt, Exclusive(4)), 40);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(nullopt, Inclusive(4)), 50);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Exclusive(13), nullopt), 160 + 1000);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Inclusive(13), nullopt), 170 + 1000);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Inclusive(13), Exclusive(14)), 10);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Exclusive(13), Inclusive(14)), 10);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Exclusive(13), Exclusive(13)), 0);
|
|
|
|
EXPECT_WITH_MARGIN(VerticesCount(Inclusive(20), Exclusive(13)), 0);
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
}
|
2017-04-21 21:39:41 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
#undef EXPECT_WITH_MARGIN
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyValueIteration) {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
|
|
|
|
|
|
|
// insert 10 verties and and check visibility
|
|
|
|
for (int i = 0; i < 10; i++) AddVertex(12);
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, 12, false)), 0);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, 12, true)), 10);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, 12, false)), 10);
|
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, 12, true)), 10);
|
2017-06-07 15:49:51 +08:00
|
|
|
}
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
TEST_F(GraphDbAccessorIndex, LabelPropertyValueSorting) {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
|
|
|
std::vector<PropertyValue> expected_property_value(50, 0);
|
|
|
|
|
|
|
|
// strings
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property,
|
|
|
|
static_cast<std::string>(std::to_string(i)));
|
|
|
|
expected_property_value[i] = vertex_accessor.PropsAt(property);
|
|
|
|
}
|
|
|
|
// bools - insert in reverse to check for comparison between values.
|
|
|
|
for (int i = 9; i >= 0; --i) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property, static_cast<bool>(i / 5));
|
|
|
|
expected_property_value[10 + i] = vertex_accessor.PropsAt(property);
|
|
|
|
}
|
|
|
|
|
|
|
|
// integers
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property, i);
|
|
|
|
expected_property_value[20 + 2 * i] = vertex_accessor.PropsAt(property);
|
|
|
|
}
|
|
|
|
// doubles
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property, static_cast<double>(i + 0.5));
|
|
|
|
expected_property_value[20 + 2 * i + 1] = vertex_accessor.PropsAt(property);
|
|
|
|
}
|
|
|
|
|
2017-07-05 22:00:07 +08:00
|
|
|
// lists of ints - insert in reverse to check for comparision between
|
|
|
|
// lists.
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
for (int i = 9; i >= 0; --i) {
|
2017-08-09 21:36:01 +08:00
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
std::vector<PropertyValue> value;
|
|
|
|
value.push_back(PropertyValue(i));
|
|
|
|
vertex_accessor.PropsSet(property, value);
|
|
|
|
expected_property_value[40 + i] = vertex_accessor.PropsAt(property);
|
|
|
|
}
|
|
|
|
|
2017-08-24 06:13:26 +08:00
|
|
|
// Maps. Declare a vector in the expected order, then shuffle when setting on
|
|
|
|
// vertices.
|
|
|
|
std::vector<std::map<std::string, PropertyValue>> maps{
|
|
|
|
{{"b", 12}},
|
|
|
|
{{"b", 12}, {"a", 77}},
|
|
|
|
{{"a", 77}, {"c", 0}},
|
|
|
|
{{"a", 78}, {"b", 12}}};
|
|
|
|
expected_property_value.insert(expected_property_value.end(), maps.begin(),
|
|
|
|
maps.end());
|
|
|
|
auto shuffled = maps;
|
|
|
|
std::random_shuffle(shuffled.begin(), shuffled.end());
|
|
|
|
for (const auto &map : shuffled) {
|
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property, map);
|
|
|
|
}
|
|
|
|
|
2017-08-09 21:36:01 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, false)), 0);
|
2017-08-24 06:13:26 +08:00
|
|
|
EXPECT_EQ(Count(dba->Vertices(label, property, true)), 54);
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
|
|
|
|
int cnt = 0;
|
2017-08-09 21:36:01 +08:00
|
|
|
for (auto vertex : dba->Vertices(label, property, true)) {
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
const PropertyValue &property_value = vertex.PropsAt(property);
|
|
|
|
EXPECT_EQ(property_value.type(), expected_property_value[cnt].type());
|
|
|
|
switch (property_value.type()) {
|
|
|
|
case PropertyValue::Type::Bool:
|
|
|
|
EXPECT_EQ(property_value.Value<bool>(),
|
|
|
|
expected_property_value[cnt].Value<bool>());
|
|
|
|
break;
|
|
|
|
case PropertyValue::Type::Double:
|
|
|
|
EXPECT_EQ(property_value.Value<double>(),
|
|
|
|
expected_property_value[cnt].Value<double>());
|
|
|
|
break;
|
|
|
|
case PropertyValue::Type::Int:
|
|
|
|
EXPECT_EQ(property_value.Value<int64_t>(),
|
|
|
|
expected_property_value[cnt].Value<int64_t>());
|
|
|
|
break;
|
|
|
|
case PropertyValue::Type::String:
|
|
|
|
EXPECT_EQ(property_value.Value<std::string>(),
|
|
|
|
expected_property_value[cnt].Value<std::string>());
|
|
|
|
break;
|
|
|
|
case PropertyValue::Type::List: {
|
|
|
|
auto received_value =
|
|
|
|
property_value.Value<std::vector<PropertyValue>>();
|
|
|
|
auto expected_value =
|
|
|
|
expected_property_value[cnt].Value<std::vector<PropertyValue>>();
|
|
|
|
EXPECT_EQ(received_value.size(), expected_value.size());
|
|
|
|
EXPECT_EQ(received_value.size(), 1);
|
|
|
|
EXPECT_EQ(received_value[0].Value<int64_t>(),
|
|
|
|
expected_value[0].Value<int64_t>());
|
|
|
|
break;
|
|
|
|
}
|
2017-08-24 06:13:26 +08:00
|
|
|
case PropertyValue::Type::Map: {
|
|
|
|
auto received_value =
|
|
|
|
property_value.Value<std::map<std::string, PropertyValue>>();
|
|
|
|
auto expected_value =
|
|
|
|
expected_property_value[cnt]
|
|
|
|
.Value<std::map<std::string, PropertyValue>>();
|
|
|
|
EXPECT_EQ(received_value.size(), expected_value.size());
|
|
|
|
for (const auto &kv : expected_value) {
|
|
|
|
auto found = expected_value.find(kv.first);
|
|
|
|
EXPECT_NE(found, expected_value.end());
|
|
|
|
EXPECT_EQ(kv.second.Value<int64_t>(), found->second.Value<int64_t>());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
LabelProperty index.
Summary:
Add return values.
After merge.
Inital working version. Still missing comments.
Update documentation.
Add checking for previous vlist and value equality.
After merge.
Remove functor, add boolean ffunction.
Build index.
More functionality. Start implementing tests.
Add tests.
Reviewers: matej.gradicek, mislav.bradac, mferencevic, buda, florijan
Reviewed By: mislav.bradac, buda, florijan
Subscribers: lion, florijan, teon.banek, buda, pullbot
Differential Revision: https://phabricator.memgraph.io/D355
2017-05-16 20:47:03 +08:00
|
|
|
case PropertyValue::Type::Null:
|
|
|
|
ASSERT_FALSE("Invalid value type.");
|
|
|
|
}
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 17:24:18 +08:00
|
|
|
/**
|
|
|
|
* A test fixture that contains a database, accessor,
|
|
|
|
* (label, property) index and 100 vertices, 10 for
|
|
|
|
* each of [0, 10) property values.
|
|
|
|
*/
|
2018-01-12 22:17:04 +08:00
|
|
|
class GraphDbAccessorIndexRange : public GraphDbAccessorIndex {
|
2017-07-13 17:24:18 +08:00
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2018-10-15 22:12:02 +08:00
|
|
|
dba->BuildIndex(label, property, false);
|
2017-07-13 17:24:18 +08:00
|
|
|
for (int i = 0; i < 100; i++) AddVertex(i / 10);
|
|
|
|
|
2017-08-09 21:36:01 +08:00
|
|
|
ASSERT_EQ(Count(dba->Vertices(false)), 0);
|
|
|
|
ASSERT_EQ(Count(dba->Vertices(true)), 100);
|
2017-07-13 17:24:18 +08:00
|
|
|
Commit();
|
2017-08-09 21:36:01 +08:00
|
|
|
ASSERT_EQ(Count(dba->Vertices(false)), 100);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Vertices(std::experimental::optional<utils::Bound<PropertyValue>> lower,
|
|
|
|
std::experimental::optional<utils::Bound<PropertyValue>> upper,
|
|
|
|
bool current_state = false) {
|
2017-08-09 21:36:01 +08:00
|
|
|
return dba->Vertices(label, property, lower, upper, current_state);
|
2017-07-13 17:24:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
auto Inclusive(PropertyValue value) {
|
|
|
|
return std::experimental::make_optional(
|
|
|
|
utils::MakeBoundInclusive(PropertyValue(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Exclusive(int value) {
|
|
|
|
return std::experimental::make_optional(
|
|
|
|
utils::MakeBoundExclusive(PropertyValue(value)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
TEST_F(GraphDbAccessorIndexRange, RangeIteration) {
|
2017-07-13 17:24:18 +08:00
|
|
|
using std::experimental::nullopt;
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(7))), 80);
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Exclusive(7))), 70);
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(7), nullopt)), 30);
|
|
|
|
EXPECT_EQ(Count(Vertices(Exclusive(7), nullopt)), 20);
|
|
|
|
EXPECT_EQ(Count(Vertices(Exclusive(3), Exclusive(6))), 20);
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(3), Inclusive(6))), 40);
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(6), Inclusive(3))), 0);
|
|
|
|
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
|
|
|
EXPECT_DEATH(Vertices(nullopt, nullopt), "bound must be provided");
|
2017-04-21 21:39:41 +08:00
|
|
|
}
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
TEST_F(GraphDbAccessorIndexRange, RangeIterationCurrentState) {
|
2017-07-13 17:24:18 +08:00
|
|
|
using std::experimental::nullopt;
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(7))), 80);
|
|
|
|
for (int i = 0; i < 20; i++) AddVertex(2);
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(7))), 80);
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(7), true)), 100);
|
|
|
|
Commit();
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(7))), 100);
|
|
|
|
}
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
TEST_F(GraphDbAccessorIndexRange, RangeInterationIncompatibleTypes) {
|
2017-07-13 17:24:18 +08:00
|
|
|
using std::experimental::nullopt;
|
|
|
|
|
|
|
|
// using PropertyValue::Null as a bound fails with an assertion
|
|
|
|
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
|
|
|
EXPECT_DEATH(Vertices(nullopt, Inclusive(PropertyValue::Null)),
|
|
|
|
"not a valid index bound");
|
|
|
|
EXPECT_DEATH(Vertices(Inclusive(PropertyValue::Null), nullopt),
|
|
|
|
"not a valid index bound");
|
|
|
|
std::vector<PropertyValue> incompatible_with_int{
|
|
|
|
"string", true, std::vector<PropertyValue>{1}};
|
|
|
|
|
|
|
|
// using incompatible upper and lower bounds yields no results
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(2), Inclusive("string"))), 0);
|
|
|
|
|
|
|
|
// for incomparable bound and stored data,
|
|
|
|
// expect that no results are returned
|
|
|
|
ASSERT_EQ(Count(Vertices(Inclusive(0), nullopt)), 100);
|
|
|
|
for (PropertyValue value : incompatible_with_int) {
|
|
|
|
::testing::FLAGS_gtest_death_test_style = "threadsafe";
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(value))), 0)
|
|
|
|
<< "Found vertices of type int for predicate value type: "
|
|
|
|
<< value.type();
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(value), nullopt)), 0)
|
|
|
|
<< "Found vertices of type int for predicate value type: "
|
|
|
|
<< value.type();
|
2017-04-21 21:39:41 +08:00
|
|
|
}
|
2017-07-13 17:24:18 +08:00
|
|
|
|
|
|
|
// we can compare int to double
|
|
|
|
EXPECT_EQ(Count(Vertices(nullopt, Inclusive(1000.0))), 100);
|
|
|
|
EXPECT_EQ(Count(Vertices(Inclusive(0.0), nullopt)), 100);
|
2017-04-21 21:39:41 +08:00
|
|
|
}
|
2018-10-15 22:12:02 +08:00
|
|
|
|
|
|
|
TEST_F(GraphDbAccessorIndex, UniqueConstraintViolationOnInsert) {
|
|
|
|
dba->BuildIndex(label, property, true);
|
|
|
|
Commit();
|
|
|
|
AddVertex(0);
|
|
|
|
EXPECT_THROW(AddVertex(0), database::IndexConstraintViolationException);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(GraphDbAccessorIndex, UniqueConstraintViolationOnBuild) {
|
|
|
|
AddVertex(0);
|
|
|
|
AddVertex(0);
|
|
|
|
Commit();
|
|
|
|
EXPECT_THROW(dba->BuildIndex(label, property, true),
|
|
|
|
database::IndexConstraintViolationException);
|
|
|
|
}
|
2018-10-19 16:38:12 +08:00
|
|
|
|
|
|
|
TEST_F(GraphDbAccessorIndex, UniqueConstraintUpdateProperty) {
|
|
|
|
dba->BuildIndex(label, property, true);
|
|
|
|
AddVertex(0);
|
|
|
|
auto vertex_accessor = dba->InsertVertex();
|
|
|
|
vertex_accessor.add_label(label);
|
|
|
|
vertex_accessor.PropsSet(property, 10);
|
|
|
|
|
|
|
|
EXPECT_THROW(vertex_accessor.PropsSet(property, 0),
|
|
|
|
database::IndexConstraintViolationException);
|
|
|
|
}
|