|
21 | 21 |
|
22 | 22 | #include "./util.h" |
23 | 23 | #include "graphar/api/high_level_reader.h" |
| 24 | +#include "graphar/expression.h" |
| 25 | +#include "graphar/label.h" |
| 26 | +#include "graphar/reader_util.h" |
24 | 27 |
|
25 | 28 | #include <catch2/catch_test_macros.hpp> |
26 | 29 |
|
27 | 30 | namespace graphar { |
| 31 | +constexpr size_t expectedFemaleCount = 454; |
| 32 | +constexpr size_t expectedMaleCount = 449; |
| 33 | +constexpr size_t expectedTotalCount = 903; |
28 | 34 | TEST_CASE_METHOD(GlobalFixture, "Graph") { |
29 | 35 | // read file and construct graph info |
30 | 36 | std::string path = |
@@ -113,6 +119,47 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") { |
113 | 119 | } |
114 | 120 | } |
115 | 121 |
|
| 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 | + |
116 | 163 | SECTION("ListProperty") { |
117 | 164 | // read file and construct graph info |
118 | 165 | std::string path = |
|
0 commit comments