Skip to content

Commit 413fdf5

Browse files
committed
test: add test for label filter case
Signed-off-by: syaojun <libevent@yeah.net>
1 parent 080a2f6 commit 413fdf5

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

cpp/test/test_graph.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121

2222
#include "./util.h"
2323
#include "graphar/api/high_level_reader.h"
24+
#include "graphar/expression.h"
25+
#include "graphar/label.h"
26+
#include "graphar/reader_util.h"
2427

2528
#include <catch2/catch_test_macros.hpp>
2629

2730
namespace graphar {
31+
constexpr size_t expectedFemaleCount = 454;
32+
constexpr size_t expectedMaleCount = 449;
33+
constexpr size_t expectedTotalCount = 903;
2834
TEST_CASE_METHOD(GlobalFixture, "Graph") {
2935
// read file and construct graph info
3036
std::string path =
@@ -113,6 +119,47 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
113119
}
114120
}
115121

122+
SECTION("VerticesCollectionFilterByProperty") {
123+
std::string path =
124+
test_data_dir + "/ldbc_sample/parquet/ldbc_sample.graph.yml";
125+
auto maybe_graph_info = GraphInfo::Load(path);
126+
REQUIRE(maybe_graph_info.status().ok());
127+
auto graph_info = maybe_graph_info.value();
128+
129+
auto vertex_info = graph_info->GetVertexInfo("person");
130+
REQUIRE(vertex_info != nullptr);
131+
132+
auto vertices = std::make_shared<VerticesCollection>(
133+
vertex_info, graph_info->GetPrefix());
134+
REQUIRE(vertices.size() == expectedTotalCount);
135+
std::cout << "total size " << vertices->size() << std::endl;
136+
137+
auto filter_female =
138+
_Equal(_Property("gender"), _Literal(std::string("female")));
139+
std::vector<IdType> new_valid_chunk;
140+
auto maybe_filtered_female_ids =
141+
vertices->filter("gender", filter_female, &new_valid_chunk);
142+
REQUIRE(maybe_filtered_female_ids.status().ok());
143+
auto filtered_female_ids = maybe_filtered_female_ids.value();
144+
145+
auto filter_male =
146+
_Equal(_Property("gender"), _Literal(std::string("male")));
147+
auto maybe_filtered_male_ids =
148+
vertices->filter("gender", filter_male, &new_valid_chunk);
149+
REQUIRE(maybe_filtered_male_ids.status().ok());
150+
auto filtered_male_ids = maybe_filtered_male_ids.value();
151+
152+
std::cout << "Filtered " << filtered_female_ids.size()
153+
<< " vertices with gender='female'" << std::endl;
154+
std::cout << "Filtered " << filtered_male_ids.size()
155+
<< " vertices with gender='male'" << std::endl;
156+
157+
REQUIRE(filtered_female_ids.size() == expectedFemaleCount);
158+
REQUIRE(filtered_male_ids.size() == expectedMaleCount);
159+
REQUIRE(filtered_male_ids.size() + filtered_female_ids.size() ==
160+
expectedTotalCount);
161+
}
162+
116163
SECTION("ListProperty") {
117164
// read file and construct graph info
118165
std::string path =

0 commit comments

Comments
 (0)