westonpace commented on code in PR #14758:
URL: https://github.com/apache/arrow/pull/14758#discussion_r1147835236


##########
cpp/src/arrow/util/align_util_test.cc:
##########
@@ -59,6 +63,18 @@ void CheckBitmapWordAlign(const uint8_t* data, int64_t 
bit_offset, int64_t lengt
   }
 }
 
+arrow::Result<std::shared_ptr<Array>> CreateUnalignedArray(const Array& array) 
{
+  BufferVector sliced_buffers(array.data()->buffers.size(), nullptr);

Review Comment:
   ```suggestion
     // Slicing by 1 would create an invalid array if the type was wider than
     // 1 byte so double-check that the array is a 1-byte type
     EXPECT_EQ(array.type_id(), Type::UINT8);
     BufferVector sliced_buffers(array.data()->buffers.size(), nullptr);
   ```



##########
cpp/src/arrow/util/align_util_test.cc:
##########
@@ -59,6 +63,18 @@ void CheckBitmapWordAlign(const uint8_t* data, int64_t 
bit_offset, int64_t lengt
   }
 }
 
+arrow::Result<std::shared_ptr<Array>> CreateUnalignedArray(const Array& array) 
{
+  BufferVector sliced_buffers(array.data()->buffers.size(), nullptr);
+  for (std::size_t i = 0; i < array.data()->buffers.size(); ++i) {
+    if (array.data()->buffers[i]) {
+      sliced_buffers[i] = SliceBuffer(array.data()->buffers[i], 1, 2);
+    }
+  }
+  auto sliced_array_data =
+      ArrayData::Make(array.type(), array.length(), std::move(sliced_buffers));

Review Comment:
   ```suggestion
     auto sliced_array_data =
         ArrayData::Make(array.type(), /*length=*/2, std::move(sliced_buffers));
   ```
   
   This works today, but only because you never call `Validate` or any kind of 
compute function on the returned array.  This could be a time bomb for a future 
maintainer.  Better to make sure the array is properly formed which means the 
length of the array must match the length of its buffers.



-- 
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