westonpace commented on code in PR #14758:
URL: https://github.com/apache/arrow/pull/14758#discussion_r1091291897
##########
cpp/src/arrow/util/align_util.h:
##########
@@ -64,5 +66,23 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t*
data, int64_t bit_of
return p;
}
+template <typename T>
+Status EnsureAlignment(std::shared_ptr<T> object, int64_t alignment,
Review Comment:
This method doesn't recurse into child arrays. For example, a `StructArray`
is going to have `object->children()` that will need to be visited as well.
##########
cpp/src/arrow/util/align_util.h:
##########
@@ -64,5 +66,23 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t*
data, int64_t bit_of
return p;
}
+template <typename T>
Review Comment:
Why is this templated? Right now this relies on `T::data()` existing. What
other types of `T` do you expect to accept?
##########
cpp/src/arrow/util/align_util.h:
##########
@@ -64,5 +66,23 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t*
data, int64_t bit_of
return p;
}
+template <typename T>
+Status EnsureAlignment(std::shared_ptr<T> 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());
+ object->data()->buffers[i] = std::move(new_buffer);
Review Comment:
It'd be nice (and more consistent with the rest of the code base) if we
could do this by returning a new `std::shared_ptr<Array>` instead of modifying
the existing array in-place. You should be able to create a new `ArrayData`
with the new buffers and then create a new `Array` from that.
--
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]