You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C#] Slicing a StructArray doesn't slice the child field arrays #40790
Describe the bug, including details regarding any error messages, version, and platform.
Code to reproduce, as an XUnit test:
[Fact]publicvoidTestSliceStructArray(){constintnumRows=10;varfields=newList<Field>{newField.Builder().Name("ints").DataType(newInt32Type()).Nullable(true).Build(),};vararrays=newList<IArrowArray>{newInt32Array.Builder().AppendRange(Enumerable.Range(0,numRows)).Build(),};varnullBitmap=newArrowBuffer.BitmapBuilder().AppendRange(true,numRows).Build();vararray=newStructArray(newStructType(fields),numRows,arrays,nullBitmap,nullCount:0);varslicedArray=(StructArray)array.Slice(3,4);Assert.Equal(4,slicedArray.Length);Assert.Single(slicedArray.Fields);varslicedField=slicedArray.Fields[0];Assert.Equal(4,slicedField.Length);// Fails with "Actual: 10"}
Is this expected behaviour? If not, I'm happy to look into fixing this. The existing behaviour should probably be kept for backwards compatibility though, in case users are slicing the child fields themselves to work around this.
I think this is actually specific to structs. With a ListArray, the child buffer/Array doesn't need to be sliced, the offset just needs to be accounted for when accessing the value offsets, so slicing a ListArray seems to work fine. Eg. this passes:
Activity
CurtHagenlocher commentedon Mar 26, 2024
I think it's not structs per se that are the problem but lists (and fixed size lists and unions and maps).
CurtHagenlocher commentedon Mar 26, 2024
Okay, after looking at the example I guess it's structs too...
adamreeve commentedon Mar 26, 2024
I think this is actually specific to structs. With a
ListArray, the child buffer/Array doesn't need to be sliced, the offset just needs to be accounted for when accessing the value offsets, so slicing aListArrayseems to work fine. Eg. this passes:GH-40790: [C#] Account for offset and length when getting fields of a…
CurtHagenlocher commentedon Mar 27, 2024
Issue resolved by pull request 40805
#40805
apacheGH-40790: [C#] Account for offset and length when getting field…