sanjibansg commented on code in PR #14758: URL: https://github.com/apache/arrow/pull/14758#discussion_r1140061314
########## cpp/src/arrow/util/align_util.cc: ########## @@ -26,56 +26,63 @@ namespace arrow { namespace util { -Result<std::shared_ptr<Array>> EnsureAlignment(const Array& object, int64_t alignment, +Result<std::shared_ptr<Buffer>> EnsureAlignment(const std::shared_ptr<Buffer>& object, int64_t alignment, MemoryPool* memory_pool) { - std::vector<std::shared_ptr<Buffer>> buffers_ = object.data()->buffers; + auto buffer_address = object->address(); + if ((buffer_address % alignment) != 0) { + ARROW_ASSIGN_OR_RAISE( + auto new_buffer, AllocateBuffer(object->size(), alignment, memory_pool)); + std::memcpy(new_buffer->mutable_data(), object->data(), object->size()); + return new_buffer; + } else { + return object; + } +} + +Result<std::shared_ptr<Array>> EnsureAlignment(const std::shared_ptr<Array>& object, int64_t alignment, + MemoryPool* memory_pool) { + std::vector<std::shared_ptr<Buffer>> buffers_ = object->data()->buffers; for (size_t i = 0; i < buffers_.size(); ++i) { if (buffers_[i]) { - auto buffer_address = buffers_[i]->address(); - if ((buffer_address % alignment) != 0) { - ARROW_ASSIGN_OR_RAISE( - auto new_buffer, AllocateBuffer(buffers_[i]->size(), alignment, memory_pool)); - std::memcpy(new_buffer->mutable_data(), buffers_[i]->data(), buffers_[i]->size()); - buffers_[i] = std::move(new_buffer); + ARROW_ASSIGN_OR_RAISE(buffers_[i], EnsureAlignment(buffers_[i], alignment, memory_pool)); } - } } auto new_array_data = - ArrayData::Make(object.data()->type, object.data()->length, std::move(buffers_), - object.data()->GetNullCount(), object.data()->offset); + ArrayData::Make(object->data()->type, object->data()->length, std::move(buffers_), Review Comment: Handling children and dictionary. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org