pitrou commented on code in PR #46408:
URL: https://github.com/apache/arrow/pull/46408#discussion_r2109183910


##########
cpp/src/arrow/ipc/read_write_test.cc:
##########
@@ -579,6 +579,40 @@ TEST_F(TestIpcRoundTrip, SpecificMetadataVersion) {
   TestMetadataVersion(MetadataVersion::V5);
 }
 
+TEST_F(TestIpcRoundTrip, AlienSlice) {
+  // This tests serialization of a sliced ListArray that got sliced "the Rust
+  // way": by slicing the value_offsets buffer, but keeping top-level offset at
+  // 0.
+
+  // Values buffer [1, 2, 3, 4, 5]
+  TypedBufferBuilder<int32_t> values_builder;
+  ASSERT_OK(values_builder.Reserve(5));
+  for (int32_t i = 1; i <= 5; i++) {
+    ASSERT_OK(values_builder.Append(i));
+  }
+  ASSERT_OK_AND_ASSIGN(auto values_buffer, values_builder.Finish());

Review Comment:
   Note that this could be written more succinctly:
   ```c++
     // Values array
     auto child_data = ArrayFromJSON(int32(), "[1, 2, 3, 4, 5]")->data();
   ```



##########
cpp/src/arrow/ipc/writer.cc:
##########
@@ -327,11 +327,9 @@ class RecordBatchSerializer {
     auto offsets = array.value_offsets();
 
     int64_t required_bytes = sizeof(offset_type) * (array.length() + 1);
-    if (array.offset() != 0) {
-      // If we have a non-zero offset, then the value offsets do not start at
-      // zero. We must a) create a new offsets array with shifted offsets and
-      // b) slice the values array accordingly
-
+    if (array.offset() != 0 || (array.length() > 0 && array.value_offset(0) > 
0)) {

Review Comment:
   > This path is extensively tested by TestFeather.SliceStringsRoundTrip.
   
   It would be nice to add a similar test for list slices, however. This can 
probably be in the same `TestFeather` fixture.



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

Reply via email to