sanjibansg commented on code in PR #14758:
URL: https://github.com/apache/arrow/pull/14758#discussion_r1140062709
##########
cpp/src/arrow/util/align_util.h:
##########
@@ -68,19 +68,25 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t*
data, int64_t bit_of
namespace util {
-Result<std::shared_ptr<Array>> EnsureAlignment(const Array& object, int64_t
alignment,
- MemoryPool* memory_pool);
+Result<std::shared_ptr<Buffer>> EnsureAlignment(const std::shared_ptr<Buffer>&
object,
+ int64_t alignment,
+ MemoryPool* memory_pool);
-Result<std::shared_ptr<ChunkedArray>> EnsureAlignment(const ChunkedArray&
object,
- int64_t alignment,
- MemoryPool* memory_pool);
+Result<std::shared_ptr<Array>> EnsureAlignment(const std::shared_ptr<Array>&
object,
+ int64_t alignment,
+ MemoryPool* memory_pool);
-Result<std::shared_ptr<RecordBatch>> EnsureAlignment(const RecordBatch& object,
- int64_t alignment,
- MemoryPool* memory_pool);
+Result<std::shared_ptr<ChunkedArray>> EnsureAlignment(
+ const std::shared_ptr<ChunkedArray>& object, int64_t alignment,
+ MemoryPool* memory_pool);
-Result<std::shared_ptr<Table>> EnsureAlignment(const Table& object, int64_t
alignment,
- MemoryPool* memory_pool);
+Result<std::shared_ptr<RecordBatch>> EnsureAlignment(
+ const std::shared_ptr<RecordBatch>& object, int64_t alignment,
+ MemoryPool* memory_pool);
+
+Result<std::shared_ptr<Table>> EnsureAlignment(const std::shared_ptr<Table>&
object,
Review Comment:
Made the change.
##########
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_),
+ object->data()->GetNullCount(), object->data()->offset);
return MakeArray(new_array_data);
}
-Result<std::shared_ptr<ChunkedArray>> EnsureAlignment(const ChunkedArray&
object,
+Result<std::shared_ptr<ChunkedArray>> EnsureAlignment(const
std::shared_ptr<ChunkedArray>& object,
Review Comment:
Made the change.
--
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]