viirya commented on code in PR #2083:
URL: https://github.com/apache/arrow-rs/pull/2083#discussion_r922422098


##########
arrow/src/ipc/writer.rs:
##########
@@ -1784,4 +1784,52 @@ mod tests {
 
         assert_eq!(record_batch_slice, deserialized_batch);
     }
+
+    #[test]
+    fn truncate_ipc_struct_array() {
+        fn create_batch() -> RecordBatch {
+            let strings: StringArray = [Some("foo"), None, Some("bar"), 
Some("baz")]
+                .into_iter()
+                .collect();
+            let ints: Int32Array =
+                [Some(0), Some(2), None, Some(1)].into_iter().collect();
+
+            let struct_array = StructArray::from(vec![
+                (
+                    Field::new("s", DataType::Utf8, true),
+                    Arc::new(strings) as ArrayRef,
+                ),
+                (
+                    Field::new("c", DataType::Int32, false),
+                    Arc::new(ints) as ArrayRef,
+                ),
+            ]);
+
+            let schema = Schema::new(vec![Field::new(
+                "struct_array",
+                struct_array.data_type().clone(),
+                true,
+            )]);
+
+            RecordBatch::try_new(Arc::new(schema), 
vec![Arc::new(struct_array)]).unwrap()
+        }
+
+        let record_batch = create_batch();
+        let record_batch_slice = record_batch.slice(1, 2);

Review Comment:
   > ArrayData::Slice contains a special case for StructArray where it recurses 
the offset into its children. However, it preserves the offset on the parent 
ArrayData, in order for the validity buffer to work correctly.
   
   I do see there is an special case, but not understand "it preserves the 
offset on the parent ArrayData".
   
   ```rust
   let new_offset = self.offset + offset;
   let new_data = ArrayData {
     ...
     offset: new_offset,
     ...
   };
   ```
   
   It updates new ArrayData with new offset, no?



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