Skip to content

Commit d535a43

Browse files
authored
test(C++): add test case for vertices collection filtering by label (#880)
* test(C++): add test case for vertices collection filtering by label Signed-off-by: syaojun <libevent@yeah.net> * test(C++): fix missing function Signed-off-by: syaojun <libevent@yeah.net> --------- Signed-off-by: syaojun <libevent@yeah.net>
1 parent c2e44a8 commit d535a43

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

cpp/src/graphar/high-level/graph_reader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ class VerticesCollection {
375375
return vertex_num_;
376376
}
377377

378+
std::shared_ptr<VertexInfo> GetVertexInfo() const { return vertex_info_; }
379+
380+
std::string GetPrefix() const { return prefix_; }
381+
378382
/** The vertex id list that satisfies the label filter condition. */
379383
Result<std::vector<IdType>> filter(
380384
const std::vector<std::string>& filter_labels,

cpp/test/test_graph.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
7979
it_begin.property<int64_t>("id").value());
8080
}
8181

82+
SECTION("VerticesCollectionFilterByLabel") {
83+
std::string path = test_data_dir + "/ldbc/parquet/" + "ldbc.graph.yml";
84+
auto maybe_graph_info = GraphInfo::Load(path);
85+
REQUIRE(maybe_graph_info.status().ok());
86+
auto graph_info = maybe_graph_info.value();
87+
88+
auto vertex_info = graph_info->GetVertexInfo("organisation");
89+
REQUIRE(vertex_info != nullptr);
90+
91+
auto labels = vertex_info->GetLabels();
92+
if (!labels.empty()) {
93+
auto vertices = std::make_shared<VerticesCollection>(
94+
vertex_info, graph_info->GetPrefix());
95+
96+
auto maybe_filtered_ids =
97+
vertices->filter(std::vector<std::string>{labels[0]}, nullptr);
98+
REQUIRE(maybe_filtered_ids.status().ok());
99+
auto filtered_ids = maybe_filtered_ids.value();
100+
101+
std::cout << "Filtered " << filtered_ids.size()
102+
<< " vertices with label '" << labels[0] << "'" << std::endl;
103+
104+
auto filtered_vertices = std::make_shared<VerticesCollection>(
105+
vertex_info, graph_info->GetPrefix(), true, filtered_ids);
106+
107+
size_t count = 0;
108+
for (auto it = filtered_vertices->begin(); it != filtered_vertices->end();
109+
++it) {
110+
count++;
111+
}
112+
REQUIRE(count == filtered_ids.size());
113+
}
114+
}
115+
82116
SECTION("ListProperty") {
83117
// read file and construct graph info
84118
std::string path =

0 commit comments

Comments
 (0)