diff --git a/csharp/src/Apache.Arrow/Arrays/StructArray.cs b/csharp/src/Apache.Arrow/Arrays/StructArray.cs index 11d40e6d4e886..5b827c7b85e85 100644 --- a/csharp/src/Apache.Arrow/Arrays/StructArray.cs +++ b/csharp/src/Apache.Arrow/Arrays/StructArray.cs @@ -72,11 +72,11 @@ private IReadOnlyList InitializeFields() IRecordType IArrowRecord.Schema => (StructType)Data.DataType; - int IArrowRecord.ColumnCount => _fields.Count; + int IArrowRecord.ColumnCount => Fields.Count; IArrowArray IArrowRecord.Column(string columnName, IEqualityComparer 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 09b0d2c6655ba..cfca4556b63a6 100644 --- a/csharp/test/Apache.Arrow.Tests/RecordTests.cs +++ b/csharp/test/Apache.Arrow.Tests/RecordTests.cs @@ -74,7 +74,25 @@ public void VisitStructAndBatch() 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