WillAyd opened a new issue, #526:
URL: https://github.com/apache/arrow-nanoarrow/issues/526

   #404 added a lot of really nice ways to iterate over the elements of arrays, 
but constructing an array is still quite a few steps.
   
   As a convenience maybe we should add method(s) that allow you to fill array 
values from C++ iterables? Something along the lines of this (untested, 
demo-only code sans error handling):
   
   ```c++
   template<typename T>
   auto UniqueArray::FillFrom(const T& values) noexcept {
     using ValueType = typename T::value_type;
     enum ArrowType arrow_type;
   
     if constexpr(std::is_same<int8_t, ValueType>::value) {
       arrow_type = NANOARROW_TYPE_INT8;
     } else if constexpr(std::is_same<int16_t, ValueType>::value) {
       arrow_type = NANOARROW_TYPE_INT16;
     } else if constexpr(std::is_same<int32_t, ValueType>::value) {
       arrow_type = NANOARROW_TYPE_INT32;
     } else if constexpr(std::is_same<int64_t, ValueType>::value) {
       arrow_type = NANOARROW_TYPE_INT64;
     }
     ArrowArrayInitFromType(this->get(), arrow_type);
     ArrowArrayStartAppending(this->get());
   
     struct ArrowBuffer* data_buffer = ArrowArrayBuffer(this->get(), 1);
     for (const auto val : values) {
       ArrowBufferAppend(data_buffer, &val, sizeof(T));
     }
     ArrowArrayFinishBuildingDefault(this->get(), nullptr);
   
     return 0;  // or error code somewhere
   };
   ```
   
   Could allow users pretty high level ways of creating arrays:
   
   ```c++
   nanoarrow::UniqueArray array;
   array.FillFrom(std::vector<int64_t>{1, 2, 3})
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to