This is an automated email from the ASF dual-hosted git repository.
xiaokang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git
The following commit(s) were added to refs/heads/main by this push:
new d535a437 test(C++): add test case for vertices collection filtering by
label (#880)
d535a437 is described below
commit d535a437667c6e2bf28f7f376930b13ed5aed63d
Author: Jason Yao <[email protected]>
AuthorDate: Sat Feb 28 13:54:26 2026 +0800
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 <[email protected]>
* test(C++): fix missing function
Signed-off-by: syaojun <[email protected]>
---------
Signed-off-by: syaojun <[email protected]>
---
cpp/src/graphar/high-level/graph_reader.h | 4 ++++
cpp/test/test_graph.cc | 34 +++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/cpp/src/graphar/high-level/graph_reader.h
b/cpp/src/graphar/high-level/graph_reader.h
index 0a0ae102..f67502ae 100644
--- a/cpp/src/graphar/high-level/graph_reader.h
+++ b/cpp/src/graphar/high-level/graph_reader.h
@@ -375,6 +375,10 @@ class VerticesCollection {
return vertex_num_;
}
+ std::shared_ptr<VertexInfo> GetVertexInfo() const { return vertex_info_; }
+
+ std::string GetPrefix() const { return prefix_; }
+
/** The vertex id list that satisfies the label filter condition. */
Result<std::vector<IdType>> filter(
const std::vector<std::string>& filter_labels,
diff --git a/cpp/test/test_graph.cc b/cpp/test/test_graph.cc
index a66bf37d..6c83f163 100644
--- a/cpp/test/test_graph.cc
+++ b/cpp/test/test_graph.cc
@@ -79,6 +79,40 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
it_begin.property<int64_t>("id").value());
}
+ SECTION("VerticesCollectionFilterByLabel") {
+ std::string path = test_data_dir + "/ldbc/parquet/" + "ldbc.graph.yml";
+ auto maybe_graph_info = GraphInfo::Load(path);
+ REQUIRE(maybe_graph_info.status().ok());
+ auto graph_info = maybe_graph_info.value();
+
+ auto vertex_info = graph_info->GetVertexInfo("organisation");
+ REQUIRE(vertex_info != nullptr);
+
+ auto labels = vertex_info->GetLabels();
+ if (!labels.empty()) {
+ auto vertices = std::make_shared<VerticesCollection>(
+ vertex_info, graph_info->GetPrefix());
+
+ auto maybe_filtered_ids =
+ vertices->filter(std::vector<std::string>{labels[0]}, nullptr);
+ REQUIRE(maybe_filtered_ids.status().ok());
+ auto filtered_ids = maybe_filtered_ids.value();
+
+ std::cout << "Filtered " << filtered_ids.size()
+ << " vertices with label '" << labels[0] << "'" << std::endl;
+
+ auto filtered_vertices = std::make_shared<VerticesCollection>(
+ vertex_info, graph_info->GetPrefix(), true, filtered_ids);
+
+ size_t count = 0;
+ for (auto it = filtered_vertices->begin(); it !=
filtered_vertices->end();
+ ++it) {
+ count++;
+ }
+ REQUIRE(count == filtered_ids.size());
+ }
+ }
+
SECTION("ListProperty") {
// read file and construct graph info
std::string path =
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]