Skip to content

[C#] Slicing a StructArray doesn't slice the child field arrays #40790

@adamreeve

Description

@adamreeve

Describe the bug, including details regarding any error messages, version, and platform.

Code to reproduce, as an XUnit test:

[Fact]
public void TestSliceStructArray()
{
    const int numRows = 10;
    var fields = new List<Field>
    {
        new Field.Builder().Name("ints").DataType(new Int32Type()).Nullable(true).Build(),
    };
    var arrays = new List<IArrowArray>
    {
        new Int32Array.Builder().AppendRange(Enumerable.Range(0, numRows)).Build(),
    };

    var nullBitmap = new ArrowBuffer.BitmapBuilder().AppendRange(true, numRows).Build();
    var array = new StructArray(new StructType(fields), numRows, arrays, nullBitmap, nullCount: 0);

    var slicedArray = (StructArray) array.Slice(3, 4);

    Assert.Equal(4, slicedArray.Length);
    Assert.Single(slicedArray.Fields);
    var slicedField = 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.

Component(s)

C#

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions