You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "adamreeve (via GitHub)" <gi...@apache.org> on 2024/03/26 02:03:46 UTC
[I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
adamreeve opened a new issue, #40790:
URL: https://github.com/apache/arrow/issues/40790
### Describe the bug, including details regarding any error messages, version, and platform.
Code to reproduce, as an XUnit test:
```C#
[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#
--
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: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on issue #40790:
URL: https://github.com/apache/arrow/issues/40790#issuecomment-2022925188
Issue resolved by pull request 40805
https://github.com/apache/arrow/pull/40805
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher closed issue #40790: [C#] Slicing a StructArray doesn't slice the child field arrays
URL: https://github.com/apache/arrow/issues/40790
--
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: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on issue #40790:
URL: https://github.com/apache/arrow/issues/40790#issuecomment-2019284944
Okay, after looking at the example I guess it's structs too...
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
Posted by "CurtHagenlocher (via GitHub)" <gi...@apache.org>.
CurtHagenlocher commented on issue #40790:
URL: https://github.com/apache/arrow/issues/40790#issuecomment-2019269696
I think it's not structs per se that are the problem but lists (and fixed size lists and unions and maps).
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [C#] Slicing a StructArray doesn't slice the child field arrays [arrow]
Posted by "adamreeve (via GitHub)" <gi...@apache.org>.
adamreeve commented on issue #40790:
URL: https://github.com/apache/arrow/issues/40790#issuecomment-2019287063
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:
```c#
[Fact]
public void TestSliceListArray()
{
const int numRows = 10;
var builder = new ListArray.Builder(new Int32Type());
var valueBuilder = (Int32Array.Builder) builder.ValueBuilder;
for (var rowIdx = 0; rowIdx < numRows; ++rowIdx)
{
builder.Append();
var length = rowIdx % 3;
for (var i = 0; i < length; ++i)
{
valueBuilder.Append(valueBuilder.Length);
}
}
var array = builder.Build();
var slicedArray = (ListArray) array.Slice(2, 4);
Assert.Equal(4, slicedArray.Length);
for (var rowIdx = 0; rowIdx < slicedArray.Length; ++rowIdx)
{
var slicedArrayList = (IReadOnlyList<int?>)slicedArray.GetSlicedValues(rowIdx);
var sourceArrayList = (IReadOnlyList<int?>)array.GetSlicedValues(rowIdx + 2);
Assert.Equal(sourceArrayList, slicedArrayList);
}
}
```
--
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-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org