Skip to content

Commit ea9a324

Browse files
authored
feat(c++): Add support for the date/timestamp property types in iter (#754)
* feat: Add support for the date/timestamp property types in vertexIter/edgeIter * feat: add test for date/timestamp types * fix: format
1 parent 9b2219e commit ea9a324

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

cpp/src/graphar/util.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ Result<const void*> GetArrowArrayData(
8989
} else if (array->type()->Equals(arrow::boolean())) {
9090
return reinterpret_cast<const void*>(
9191
std::dynamic_pointer_cast<arrow::BooleanArray>(array).get());
92+
} else if (array->type()->Equals(arrow::date32())) {
93+
return reinterpret_cast<const void*>(
94+
std::dynamic_pointer_cast<arrow::Date32Array>(array)->raw_values());
95+
} else if (array->type()->Equals(arrow::timestamp(arrow::TimeUnit::MILLI))) {
96+
return reinterpret_cast<const void*>(
97+
std::dynamic_pointer_cast<arrow::TimestampArray>(array)->raw_values());
9298
} else {
9399
return Status::TypeError("Array type - ", array->type()->ToString(),
94100
" is not supported yet...");

cpp/test/test_graph.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,63 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
298298
REQUIRE(count == edges->size());
299299
std::cout << "Total edge_count=" << count << std::endl;
300300
}
301+
302+
SECTION("DateType") {
303+
std::string path_date =
304+
test_data_dir + "/ldbc_sample/parquet/ldbc_sample_date.graph.yml";
305+
auto maybe_graph_info_date = GraphInfo::Load(path_date);
306+
REQUIRE(maybe_graph_info_date.status().ok());
307+
auto graph_info_date = maybe_graph_info_date.value();
308+
std::string src_type = "person", edge_type = "knows-date",
309+
dst_type = "person";
310+
auto expect =
311+
EdgesCollection::Make(graph_info_date, src_type, edge_type, dst_type,
312+
AdjListType::ordered_by_source);
313+
REQUIRE(!expect.has_error());
314+
auto edges = expect.value();
315+
316+
// Expected values for the first ten creationDate-date entries
317+
int32_t expected_dates[10] = {14820, 15442, 14909, 15182, 15141,
318+
15058, 15155, 15135, 15364, 15455};
319+
size_t count = 0;
320+
for (auto it = edges->begin(); it != edges->end() && count < 10;
321+
++it, ++count) {
322+
auto date_val = it.property<int32_t>("creationDate-date");
323+
REQUIRE(date_val.has_value());
324+
REQUIRE(date_val.value() == expected_dates[count]);
325+
}
326+
REQUIRE(count == 10);
327+
std::cout << "DateType edge_count=" << count << std::endl;
328+
}
329+
330+
SECTION("TimestampType") {
331+
std::string path_timestamp =
332+
test_data_dir + "/ldbc_sample/parquet/ldbc_sample_timestamp.graph.yml";
333+
auto maybe_graph_info_timestamp = GraphInfo::Load(path_timestamp);
334+
REQUIRE(maybe_graph_info_timestamp.status().ok());
335+
auto graph_info_timestamp = maybe_graph_info_timestamp.value();
336+
std::string src_type = "person", edge_type = "knows-timestamp",
337+
dst_type = "person";
338+
auto expect =
339+
EdgesCollection::Make(graph_info_timestamp, src_type, edge_type,
340+
dst_type, AdjListType::ordered_by_source);
341+
REQUIRE(!expect.has_error());
342+
auto edges = expect.value();
343+
344+
// Expected values for the first ten creationDate-timestamp entries
345+
int64_t expected_timestamps[10] = {
346+
1280503193298LL, 1334239018931LL, 1288146786288LL, 1311781394869LL,
347+
1308223719623LL, 1301064563134LL, 1309416320777LL, 1307728039432LL,
348+
1327492287348LL, 1335389465259LL};
349+
size_t count = 0;
350+
for (auto it = edges->begin(); it != edges->end() && count < 10;
351+
++it, ++count) {
352+
auto ts_val = it.property<int64_t>("creationDate-timestamp");
353+
REQUIRE(ts_val.has_value());
354+
REQUIRE(ts_val.value() == expected_timestamps[count]);
355+
}
356+
REQUIRE(count == 10);
357+
std::cout << "TimestampType edge_count=" << count << std::endl;
358+
}
301359
}
302360
} // namespace graphar

0 commit comments

Comments
 (0)