kylebarron commented on issue #6151:
URL: https://github.com/apache/arrow-rs/issues/6151#issuecomment-2261554869

   ```rs
   #[cfg(test)]
   mod test {
       use std::sync::Arc;
   
       use arrow::array::ArrayDataBuilder;
       use arrow_array::{make_array, Array, Int8Array, StructArray, 
UInt64Array};
       use arrow_schema::Field;
   
       #[test]
       fn test() {
           let a = Arc::new(Int8Array::from(vec![1, 2, 3, 4]));
           let b = Arc::new(UInt64Array::from(vec![1, 2, 3, 4]));
           let fields = vec![
               Field::new("a", a.data_type().clone(), true),
               Field::new("b", b.data_type().clone(), true),
           ];
           let original_struct_array = StructArray::new(fields.into(), vec![a, 
b], None);
           let array_data = original_struct_array.to_data();
           let builder: ArrayDataBuilder = array_data.into();
   
           // Set `offset` to 2
           let offset_array_data = builder.offset(2).len(2).build().unwrap();
           let reconstructed_struct_array = make_array(offset_array_data);
   
           dbg!(&reconstructed_struct_array);
           dbg!(original_struct_array.slice(2, 2));
       }
   }
   ```
   
   This prints:
   ```
   [arro3-core/src/constructors.rs:129:9] &reconstructed_struct_array = 
StructArray
   [
   -- child 0: "a" (Int8)
   PrimitiveArray<Int8>
   [
     1,
     2,
     3,
     4,
   ]
   -- child 1: "b" (UInt64)
   PrimitiveArray<UInt64>
   [
     1,
     2,
     3,
     4,
   ]
   ]
   [arro3-core/src/constructors.rs:130:9] original_struct_array.slice(2, 2) = 
StructArray
   [
   -- child 0: "a" (Int8)
   PrimitiveArray<Int8>
   [
     3,
     4,
   ]
   -- child 1: "b" (UInt64)
   PrimitiveArray<UInt64>
   [
     3,
     4,
   ]
   ]
   ```
   
   My understanding is that setting `offset` and `len` on the 
`ArrayDataBuilder` **should** cause the same behavior as `.slice(2, 2)`


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