@@ -152,6 +152,20 @@ Status EdgesBuilder::validate(const Edge& e,
152152 invalid_type = true ;
153153 }
154154 break ;
155+ case Type::DATE:
156+ // date is stored as int32_t
157+ if (property.second .type () !=
158+ typeid (typename TypeToArrowType<Type::DATE>::CType::c_type)) {
159+ invalid_type = true ;
160+ }
161+ break ;
162+ case Type::TIMESTAMP:
163+ // timestamp is stored as int64_t
164+ if (property.second .type () !=
165+ typeid (typename TypeToArrowType<Type::TIMESTAMP>::CType::c_type)) {
166+ invalid_type = true ;
167+ }
168+ break ;
155169 default :
156170 return Status::TypeError (" Unsupported property type." );
157171 }
@@ -165,6 +179,67 @@ Status EdgesBuilder::validate(const Edge& e,
165179 return Status::OK ();
166180}
167181
182+ template <Type type>
183+ Status EdgesBuilder::tryToAppend (
184+ const std::string& property_name,
185+ std::shared_ptr<arrow::Array>& array, // NOLINT
186+ const std::vector<Edge>& edges) {
187+ using CType = typename TypeToArrowType<type>::CType;
188+ arrow::MemoryPool* pool = arrow::default_memory_pool ();
189+ typename TypeToArrowType<type>::BuilderType builder (pool);
190+ for (const auto & e : edges) {
191+ if (e.Empty () || (!e.ContainProperty (property_name))) {
192+ RETURN_NOT_ARROW_OK (builder.AppendNull ());
193+ } else {
194+ RETURN_NOT_ARROW_OK (
195+ builder.Append (std::any_cast<CType>(e.GetProperty (property_name))));
196+ }
197+ }
198+ array = builder.Finish ().ValueOrDie ();
199+ return Status::OK ();
200+ }
201+
202+ template <>
203+ Status EdgesBuilder::tryToAppend<Type::TIMESTAMP>(
204+ const std::string& property_name,
205+ std::shared_ptr<arrow::Array>& array, // NOLINT
206+ const std::vector<Edge>& edges) {
207+ using CType = typename TypeToArrowType<Type::TIMESTAMP>::CType::c_type;
208+ arrow::MemoryPool* pool = arrow::default_memory_pool ();
209+ typename TypeToArrowType<Type::TIMESTAMP>::BuilderType builder (
210+ arrow::timestamp (arrow::TimeUnit::MILLI), pool);
211+ for (const auto & e : edges) {
212+ if (e.Empty () || (!e.ContainProperty (property_name))) {
213+ RETURN_NOT_ARROW_OK (builder.AppendNull ());
214+ } else {
215+ RETURN_NOT_ARROW_OK (
216+ builder.Append (std::any_cast<CType>(e.GetProperty (property_name))));
217+ }
218+ }
219+ array = builder.Finish ().ValueOrDie ();
220+ return Status::OK ();
221+ }
222+
223+ template <>
224+ Status EdgesBuilder::tryToAppend<Type::DATE>(
225+ const std::string& property_name,
226+ std::shared_ptr<arrow::Array>& array, // NOLINT
227+ const std::vector<Edge>& edges) {
228+ using CType = typename TypeToArrowType<Type::DATE>::CType::c_type;
229+ arrow::MemoryPool* pool = arrow::default_memory_pool ();
230+ typename TypeToArrowType<Type::DATE>::BuilderType builder (pool);
231+ for (const auto & e : edges) {
232+ if (e.Empty () || (!e.ContainProperty (property_name))) {
233+ RETURN_NOT_ARROW_OK (builder.AppendNull ());
234+ } else {
235+ RETURN_NOT_ARROW_OK (
236+ builder.Append (std::any_cast<CType>(e.GetProperty (property_name))));
237+ }
238+ }
239+ array = builder.Finish ().ValueOrDie ();
240+ return Status::OK ();
241+ }
242+
168243Status EdgesBuilder::appendToArray (
169244 const std::shared_ptr<DataType>& type, const std::string& property_name,
170245 std::shared_ptr<arrow::Array>& array, // NOLINT
@@ -182,32 +257,16 @@ Status EdgesBuilder::appendToArray(
182257 return tryToAppend<Type::DOUBLE>(property_name, array, edges);
183258 case Type::STRING:
184259 return tryToAppend<Type::STRING>(property_name, array, edges);
260+ case Type::DATE:
261+ return tryToAppend<Type::DATE>(property_name, array, edges);
262+ case Type::TIMESTAMP:
263+ return tryToAppend<Type::TIMESTAMP>(property_name, array, edges);
185264 default :
186265 return Status::TypeError (" Unsupported property type." );
187266 }
188267 return Status::OK ();
189268}
190269
191- template <Type type>
192- Status EdgesBuilder::tryToAppend (
193- const std::string& property_name,
194- std::shared_ptr<arrow::Array>& array, // NOLINT
195- const std::vector<Edge>& edges) {
196- using CType = typename TypeToArrowType<type>::CType;
197- arrow::MemoryPool* pool = arrow::default_memory_pool ();
198- typename TypeToArrowType<type>::BuilderType builder (pool);
199- for (const auto & e : edges) {
200- if (e.Empty () || (!e.ContainProperty (property_name))) {
201- RETURN_NOT_ARROW_OK (builder.AppendNull ());
202- } else {
203- RETURN_NOT_ARROW_OK (
204- builder.Append (std::any_cast<CType>(e.GetProperty (property_name))));
205- }
206- }
207- array = builder.Finish ().ValueOrDie ();
208- return Status::OK ();
209- }
210-
211270Status EdgesBuilder::tryToAppend (
212271 int src_or_dest,
213272 std::shared_ptr<arrow::Array>& array, // NOLINT
0 commit comments