This is an automated email from the ASF dual-hosted git repository.

CurtHagenlocher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-dotnet.git


The following commit(s) were added to refs/heads/main by this push:
     new 7ecd054  Fix GetSlicedValues for list types whose values are an 
ExtensionArray (#471)
7ecd054 is described below

commit 7ecd054f04996ad20e2363eb426df32f2e41cd65
Author: Curt Hagenlocher <[email protected]>
AuthorDate: Sun Oct 18 14:35:22 2026 -0700

    Fix GetSlicedValues for list types whose values are an ExtensionArray (#471)
    
    ## What's Changed
    
    `GetSlicedValues` only sliced when `Values` derived from `Array`.
    `ExtensionArray` implements `IArrowArray` but doesn't derive from
    `Array`, so a list of extension values (e.g. `list<arrow.uuid>` backed
    by a `GuidArray`) returned `null` for non-null elements,
    indistinguishable from a null list entry.
    
    This slices any `IArrowArray` via `ArrowArrayFactory.Slice`, which is
    what `Array.Slice` already delegates to, so behavior for regular arrays
    is unchanged and extension values now come back as the appropriate
    extension array. Applied to `ListArray`, `ListViewArray`,
    `LargeListArray`, `LargeListViewArray` and `FixedSizeListArray`
    (`ListViewArray` had the same check, though the issue didn't list it).
    
    Added `ListArrayExtensionValuesTests` covering all five list types with
    `GuidArray` values; these fail without the fix.
    
    Closes #468.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 src/Apache.Arrow/Arrays/FixedSizeListArray.cs      |   7 +-
 src/Apache.Arrow/Arrays/LargeListArray.cs          |   7 +-
 src/Apache.Arrow/Arrays/LargeListViewArray.cs      |   7 +-
 src/Apache.Arrow/Arrays/ListArray.cs               |   7 +-
 src/Apache.Arrow/Arrays/ListViewArray.cs           |   7 +-
 .../ListArrayExtensionValuesTests.cs               | 104 +++++++++++++++++++++
 6 files changed, 109 insertions(+), 30 deletions(-)

diff --git a/src/Apache.Arrow/Arrays/FixedSizeListArray.cs 
b/src/Apache.Arrow/Arrays/FixedSizeListArray.cs
index d80b8d5..bb395a3 100644
--- a/src/Apache.Arrow/Arrays/FixedSizeListArray.cs
+++ b/src/Apache.Arrow/Arrays/FixedSizeListArray.cs
@@ -167,15 +167,10 @@ namespace Apache.Arrow
                 return null;
             }
 
-            if (!(Values is Array array))
-            {
-                return default;
-            }
-
             index += Data.Offset;
 
             int length = ((FixedSizeListType)Data.DataType).ListSize;
-            return array.Slice(index * length, length);
+            return ArrowArrayFactory.Slice(Values, index * length, length);
         }
 
         protected override void Dispose(bool disposing)
diff --git a/src/Apache.Arrow/Arrays/LargeListArray.cs 
b/src/Apache.Arrow/Arrays/LargeListArray.cs
index 7220119..4cc5874 100644
--- a/src/Apache.Arrow/Arrays/LargeListArray.cs
+++ b/src/Apache.Arrow/Arrays/LargeListArray.cs
@@ -167,12 +167,7 @@ namespace Apache.Arrow
                 return null;
             }
 
-            if (!(Values is Array array))
-            {
-                return default;
-            }
-
-            return array.Slice(checked((int)ValueOffsets[index]), 
GetValueLength(index));
+            return ArrowArrayFactory.Slice(Values, 
checked((int)ValueOffsets[index]), GetValueLength(index));
         }
 
         protected override void Dispose(bool disposing)
diff --git a/src/Apache.Arrow/Arrays/LargeListViewArray.cs 
b/src/Apache.Arrow/Arrays/LargeListViewArray.cs
index 240b731..7e83258 100644
--- a/src/Apache.Arrow/Arrays/LargeListViewArray.cs
+++ b/src/Apache.Arrow/Arrays/LargeListViewArray.cs
@@ -197,12 +197,7 @@ namespace Apache.Arrow
                 return null;
             }
 
-            if (!(Values is Array array))
-            {
-                return default;
-            }
-
-            return array.Slice(checked((int)ValueOffsets[index]), 
GetValueLength(index));
+            return ArrowArrayFactory.Slice(Values, 
checked((int)ValueOffsets[index]), GetValueLength(index));
         }
 
         protected override void Dispose(bool disposing)
diff --git a/src/Apache.Arrow/Arrays/ListArray.cs 
b/src/Apache.Arrow/Arrays/ListArray.cs
index 0c3e242..49f3dcb 100644
--- a/src/Apache.Arrow/Arrays/ListArray.cs
+++ b/src/Apache.Arrow/Arrays/ListArray.cs
@@ -194,12 +194,7 @@ namespace Apache.Arrow
                 return null;
             }
 
-            if (!(Values is Array array))
-            {
-                return default;
-            }
-
-            return array.Slice(ValueOffsets[index], GetValueLength(index));
+            return ArrowArrayFactory.Slice(Values, ValueOffsets[index], 
GetValueLength(index));
         }
 
         protected override void Dispose(bool disposing)
diff --git a/src/Apache.Arrow/Arrays/ListViewArray.cs 
b/src/Apache.Arrow/Arrays/ListViewArray.cs
index cc8d841..2c50e41 100644
--- a/src/Apache.Arrow/Arrays/ListViewArray.cs
+++ b/src/Apache.Arrow/Arrays/ListViewArray.cs
@@ -198,12 +198,7 @@ namespace Apache.Arrow
                 return null;
             }
 
-            if (!(Values is Array array))
-            {
-                return default;
-            }
-
-            return array.Slice(ValueOffsets[index], GetValueLength(index));
+            return ArrowArrayFactory.Slice(Values, ValueOffsets[index], 
GetValueLength(index));
         }
 
         protected override void Dispose(bool disposing)
diff --git a/test/Apache.Arrow.Tests/ListArrayExtensionValuesTests.cs 
b/test/Apache.Arrow.Tests/ListArrayExtensionValuesTests.cs
new file mode 100644
index 0000000..6095220
--- /dev/null
+++ b/test/Apache.Arrow.Tests/ListArrayExtensionValuesTests.cs
@@ -0,0 +1,104 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.Linq;
+using Apache.Arrow.Types;
+using Xunit;
+
+namespace Apache.Arrow.Tests;
+
+/// <summary>
+/// GetSlicedValues must slice values that are an <see cref="ExtensionArray"/>,
+/// which implements <see cref="IArrowArray"/> but doesn't derive from <see 
cref="Array"/>.
+/// </summary>
+public class ListArrayExtensionValuesTests
+{
+    private static readonly Guid[] s_guids = Enumerable.Range(0, 4).Select(_ 
=> Guid.NewGuid()).ToArray();
+
+    private static readonly Field s_itemField = new Field("item", 
GuidType.Default, true);
+
+    private static GuidArray BuildGuids() => new 
GuidArray.Builder().AppendRange(s_guids).Build();
+
+    // Each list type below holds [[g0], [g1, g2, g3]].
+    private static void AssertSlices(Func<int, IArrowArray> getSlicedValues)
+    {
+        GuidArray first = Assert.IsType<GuidArray>(getSlicedValues(0));
+        Assert.Equal(new Guid?[] { s_guids[0] }, first.ToArray());
+
+        GuidArray second = Assert.IsType<GuidArray>(getSlicedValues(1));
+        Assert.Equal(new Guid?[] { s_guids[1], s_guids[2], s_guids[3] }, 
second.ToArray());
+    }
+
+    [Fact]
+    public void ListArray()
+    {
+        ListArray list = new ListArray(
+            new ListType(s_itemField), 2,
+            new 
ArrowBuffer.Builder<int>().Append(0).Append(1).Append(4).Build(),
+            BuildGuids(), ArrowBuffer.Empty);
+
+        AssertSlices(list.GetSlicedValues);
+    }
+
+    [Fact]
+    public void LargeListArray()
+    {
+        LargeListArray list = new LargeListArray(
+            new LargeListType(s_itemField), 2,
+            new 
ArrowBuffer.Builder<long>().Append(0).Append(1).Append(4).Build(),
+            BuildGuids(), ArrowBuffer.Empty);
+
+        AssertSlices(list.GetSlicedValues);
+    }
+
+    [Fact]
+    public void ListViewArray()
+    {
+        ListViewArray list = new ListViewArray(
+            new ListViewType(s_itemField), 2,
+            new ArrowBuffer.Builder<int>().Append(0).Append(1).Build(),
+            new ArrowBuffer.Builder<int>().Append(1).Append(3).Build(),
+            BuildGuids(), ArrowBuffer.Empty);
+
+        AssertSlices(list.GetSlicedValues);
+    }
+
+    [Fact]
+    public void LargeListViewArray()
+    {
+        LargeListViewArray list = new LargeListViewArray(
+            new LargeListViewType(s_itemField), 2,
+            new ArrowBuffer.Builder<long>().Append(0).Append(1).Build(),
+            new ArrowBuffer.Builder<long>().Append(1).Append(3).Build(),
+            BuildGuids(), ArrowBuffer.Empty);
+
+        AssertSlices(list.GetSlicedValues);
+    }
+
+    [Fact]
+    public void FixedSizeListArray()
+    {
+        FixedSizeListArray list = new FixedSizeListArray(
+            new FixedSizeListType(s_itemField, 2), 2,
+            BuildGuids(), ArrowBuffer.Empty);
+
+        GuidArray first = Assert.IsType<GuidArray>(list.GetSlicedValues(0));
+        Assert.Equal(new Guid?[] { s_guids[0], s_guids[1] }, first.ToArray());
+
+        GuidArray second = Assert.IsType<GuidArray>(list.GetSlicedValues(1));
+        Assert.Equal(new Guid?[] { s_guids[2], s_guids[3] }, second.ToArray());
+    }
+}

Reply via email to