This is an automated email from the ASF dual-hosted git repository.
yangxk1 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 f62ad3a6 fix(cpp): correct hasLabel() for filtered collections (#927)
f62ad3a6 is described below
commit f62ad3a6f2baec4445c86ffe302636194b984874
Author: Jason <[email protected]>
AuthorDate: Tue May 19 13:50:07 2026 +0800
fix(cpp): correct hasLabel() for filtered collections (#927)
* fix(cpp): correct hasLabel() for filtered collections
Signed-off-by: Jason <[email protected]>
* fix: correct the variable name
Signed-off-by: Jason <[email protected]>
* fix: correct the test
Signed-off-by: Jason <[email protected]>
---------
Signed-off-by: Jason <[email protected]>
---
cpp/src/graphar/high-level/graph_reader.cc | 6 +++++-
cpp/test/test_graph.cc | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/cpp/src/graphar/high-level/graph_reader.cc
b/cpp/src/graphar/high-level/graph_reader.cc
index 757f38dd..f33b611f 100644
--- a/cpp/src/graphar/high-level/graph_reader.cc
+++ b/cpp/src/graphar/high-level/graph_reader.cc
@@ -104,7 +104,11 @@ Vertex::Vertex(IdType id,
Result<bool> VertexIter::hasLabel(const std::string& label) noexcept {
std::shared_ptr<arrow::ChunkedArray> column(nullptr);
- label_reader_.seek(cur_offset_);
+ if (is_filtered_) {
+ label_reader_.seek(filtered_ids_[cur_offset_]);
+ } else {
+ label_reader_.seek(cur_offset_);
+ }
GAR_ASSIGN_OR_RAISE(auto chunk_table, label_reader_.GetLabelChunk());
column = util::GetArrowColumnByName(chunk_table, label);
if (column != nullptr) {
diff --git a/cpp/test/test_graph.cc b/cpp/test/test_graph.cc
index ed81fb8d..804a3ade 100644
--- a/cpp/test/test_graph.cc
+++ b/cpp/test/test_graph.cc
@@ -429,5 +429,33 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
REQUIRE(count == 10);
std::cout << "TimestampType edge_count=" << count << std::endl;
}
+
+ SECTION("HasLabel") {
+ // Test hasLabel on organisation vertices which have labels
+ std::string ldbc_path = test_data_dir + "/ldbc/parquet/ldbc.graph.yml";
+ auto maybe_ldbc_graph_info = GraphInfo::Load(ldbc_path);
+ REQUIRE(maybe_ldbc_graph_info.status().ok());
+ auto ldbc_graph_info = maybe_ldbc_graph_info.value();
+
+ // Get university vertices (filtered by label)
+ auto result = VerticesCollection::verticesWithLabel(
+ "university", ldbc_graph_info, "organisation");
+ REQUIRE(!result.has_error());
+ auto vertices = result.value();
+ REQUIRE(vertices->size() > 0);
+
+ // Iterate and verify hasLabel works correctly on filtered collection
+ for (auto it = vertices->begin(); it != vertices->end(); ++it) {
+ REQUIRE(it.id() >= 0);
+ // university vertices should have label "university" as true
+ auto has_university = it.hasLabel("university");
+ REQUIRE(!has_university.has_error());
+ REQUIRE(has_university.value());
+ // university vertices should have label "company" as false
+ auto has_company = it.hasLabel("company");
+ REQUIRE(!has_company.has_error());
+ REQUIRE(!has_company.value());
+ }
+ }
}
} // namespace graphar
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]