You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by cu...@apache.org on 2023/11/21 14:55:45 UTC

(arrow) branch main updated: GH-38816: [C#] Fix IArrowRecord implementation on StructArray (#38827)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new c5a1eb0163 GH-38816: [C#] Fix IArrowRecord implementation on StructArray (#38827)
c5a1eb0163 is described below

commit c5a1eb01631f770dd7b3a6ecf309022d34af4c1c
Author: Curt Hagenlocher <cu...@hagenlocher.org>
AuthorDate: Tue Nov 21 06:55:39 2023 -0800

    GH-38816: [C#] Fix IArrowRecord implementation on StructArray (#38827)
    
    ### What changes are included in this PR?
    
    Minor bug fix, test for the bug, and a few additional tests which were missed by the previous PR.
    
    ### Are these changes tested?
    
    Yes
    
    ### Are there any user-facing changes?
    
    No
    
    * Closes: #38816
    
    Authored-by: Curt Hagenlocher <cu...@hagenlocher.org>
    Signed-off-by: Curt Hagenlocher <cu...@hagenlocher.org>
---
 csharp/src/Apache.Arrow/Arrays/StructArray.cs |  6 +++---
 csharp/test/Apache.Arrow.Tests/RecordTests.cs | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/csharp/src/Apache.Arrow/Arrays/StructArray.cs b/csharp/src/Apache.Arrow/Arrays/StructArray.cs
index 11d40e6d4e..5b827c7b85 100644
--- a/csharp/src/Apache.Arrow/Arrays/StructArray.cs
+++ b/csharp/src/Apache.Arrow/Arrays/StructArray.cs
@@ -72,11 +72,11 @@ namespace Apache.Arrow
 
         IRecordType IArrowRecord.Schema => (StructType)Data.DataType;
 
-        int IArrowRecord.ColumnCount => _fields.Count;
+        int IArrowRecord.ColumnCount => Fields.Count;
 
         IArrowArray IArrowRecord.Column(string columnName, IEqualityComparer<string> comparer) =>
-            _fields[((StructType)Data.DataType).GetFieldIndex(columnName, comparer)];
+            Fields[((StructType)Data.DataType).GetFieldIndex(columnName, comparer)];
 
-        IArrowArray IArrowRecord.Column(int columnIndex) => _fields[columnIndex];
+        IArrowArray IArrowRecord.Column(int columnIndex) => Fields[columnIndex];
     }
 }
diff --git a/csharp/test/Apache.Arrow.Tests/RecordTests.cs b/csharp/test/Apache.Arrow.Tests/RecordTests.cs
index 09b0d2c665..cfca4556b6 100644
--- a/csharp/test/Apache.Arrow.Tests/RecordTests.cs
+++ b/csharp/test/Apache.Arrow.Tests/RecordTests.cs
@@ -74,7 +74,25 @@ namespace Apache.Arrow.Tests
             StructArray level2Array = new StructArray(level2, stringArray.Length, new[] { level1Array }, nulls);
             RecordBatch batch = new RecordBatch(schema, new IArrowArray[] { level2Array }, stringArray.Length);
 
+            var visitor3 = new TestArrayVisitor1();
+            visitor3.Visit(batch);
+            Assert.Equal("111utf8", visitor3.stringBuilder.ToString());
+            var visitor4 = new TestArrayVisitor2();
+            visitor4.Visit(batch);
+            Assert.Equal("322utf8", visitor4.stringBuilder.ToString());
+        }
+
+        [Fact]
+        public void LazyStructInitialization()
+        {
+            StringArray stringArray = new StringArray.Builder().Append("one").AppendNull().AppendNull().Append("four").Build();
+            Field stringField = new Field("column1", StringType.Default, true);
+            StructType structType = new StructType(new[] { stringField });
+            ArrayData structData = new ArrayData(structType, stringArray.Length, 0, 0, new[] { ArrowBuffer.Empty }, new[] { stringArray.Data });
+            IArrowRecord structArray = new StructArray(structData);
 
+            Assert.Equal(1, structArray.ColumnCount);
+            Assert.Equal(structArray.Length, structArray.Column(0).Length);
         }
 
         private class TestTypeVisitor1 : IArrowTypeVisitor, IArrowTypeVisitor<IRecordType>