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 ea9a3244 feat(c++): Add support for the date/timestamp property types 
in iter (#754)
ea9a3244 is described below

commit ea9a3244ae6164dbe622adf36b746413cf6a031f
Author: Gary <73336879+gary-cl...@users.noreply.github.com>
AuthorDate: Mon Sep 15 16:49:25 2025 +0800

    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
---
 cpp/src/graphar/util.cc |  6 +++++
 cpp/test/test_graph.cc  | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/cpp/src/graphar/util.cc b/cpp/src/graphar/util.cc
index 7a3b1a82..0712e070 100644
--- a/cpp/src/graphar/util.cc
+++ b/cpp/src/graphar/util.cc
@@ -89,6 +89,12 @@ Result<const void*> GetArrowArrayData(
   } else if (array->type()->Equals(arrow::boolean())) {
     return reinterpret_cast<const void*>(
         std::dynamic_pointer_cast<arrow::BooleanArray>(array).get());
+  } else if (array->type()->Equals(arrow::date32())) {
+    return reinterpret_cast<const void*>(
+        std::dynamic_pointer_cast<arrow::Date32Array>(array)->raw_values());
+  } else if (array->type()->Equals(arrow::timestamp(arrow::TimeUnit::MILLI))) {
+    return reinterpret_cast<const void*>(
+        std::dynamic_pointer_cast<arrow::TimestampArray>(array)->raw_values());
   } else {
     return Status::TypeError("Array type - ", array->type()->ToString(),
                              " is not supported yet...");
diff --git a/cpp/test/test_graph.cc b/cpp/test/test_graph.cc
index 0cd211d1..a66bf37d 100644
--- a/cpp/test/test_graph.cc
+++ b/cpp/test/test_graph.cc
@@ -298,5 +298,63 @@ TEST_CASE_METHOD(GlobalFixture, "Graph") {
     REQUIRE(count == edges->size());
     std::cout << "Total edge_count=" << count << std::endl;
   }
+
+  SECTION("DateType") {
+    std::string path_date =
+        test_data_dir + "/ldbc_sample/parquet/ldbc_sample_date.graph.yml";
+    auto maybe_graph_info_date = GraphInfo::Load(path_date);
+    REQUIRE(maybe_graph_info_date.status().ok());
+    auto graph_info_date = maybe_graph_info_date.value();
+    std::string src_type = "person", edge_type = "knows-date",
+                dst_type = "person";
+    auto expect =
+        EdgesCollection::Make(graph_info_date, src_type, edge_type, dst_type,
+                              AdjListType::ordered_by_source);
+    REQUIRE(!expect.has_error());
+    auto edges = expect.value();
+
+    // Expected values for the first ten creationDate-date entries
+    int32_t expected_dates[10] = {14820, 15442, 14909, 15182, 15141,
+                                  15058, 15155, 15135, 15364, 15455};
+    size_t count = 0;
+    for (auto it = edges->begin(); it != edges->end() && count < 10;
+         ++it, ++count) {
+      auto date_val = it.property<int32_t>("creationDate-date");
+      REQUIRE(date_val.has_value());
+      REQUIRE(date_val.value() == expected_dates[count]);
+    }
+    REQUIRE(count == 10);
+    std::cout << "DateType edge_count=" << count << std::endl;
+  }
+
+  SECTION("TimestampType") {
+    std::string path_timestamp =
+        test_data_dir + "/ldbc_sample/parquet/ldbc_sample_timestamp.graph.yml";
+    auto maybe_graph_info_timestamp = GraphInfo::Load(path_timestamp);
+    REQUIRE(maybe_graph_info_timestamp.status().ok());
+    auto graph_info_timestamp = maybe_graph_info_timestamp.value();
+    std::string src_type = "person", edge_type = "knows-timestamp",
+                dst_type = "person";
+    auto expect =
+        EdgesCollection::Make(graph_info_timestamp, src_type, edge_type,
+                              dst_type, AdjListType::ordered_by_source);
+    REQUIRE(!expect.has_error());
+    auto edges = expect.value();
+
+    // Expected values for the first ten creationDate-timestamp entries
+    int64_t expected_timestamps[10] = {
+        1280503193298LL, 1334239018931LL, 1288146786288LL, 1311781394869LL,
+        1308223719623LL, 1301064563134LL, 1309416320777LL, 1307728039432LL,
+        1327492287348LL, 1335389465259LL};
+    size_t count = 0;
+    for (auto it = edges->begin(); it != edges->end() && count < 10;
+         ++it, ++count) {
+      auto ts_val = it.property<int64_t>("creationDate-timestamp");
+      REQUIRE(ts_val.has_value());
+      REQUIRE(ts_val.value() == expected_timestamps[count]);
+    }
+    REQUIRE(count == 10);
+    std::cout << "TimestampType edge_count=" << count << std::endl;
+  }
 }
 }  // namespace graphar


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@graphar.apache.org
For additional commands, e-mail: commits-h...@graphar.apache.org

Reply via email to