Skip to content

Commit c5a1eb0

Browse files
apacheGH-38816: [C#] Fix IArrowRecord implementation on StructArray (apache#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: apache#38816 Authored-by: Curt Hagenlocher <[email protected]> Signed-off-by: Curt Hagenlocher <[email protected]>
1 parent 9a36c42 commit c5a1eb0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: csharp/src/Apache.Arrow/Arrays/StructArray.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ private IReadOnlyList<IArrowArray> InitializeFields()
7272

7373
IRecordType IArrowRecord.Schema => (StructType)Data.DataType;
7474

75-
int IArrowRecord.ColumnCount => _fields.Count;
75+
int IArrowRecord.ColumnCount => Fields.Count;
7676

7777
IArrowArray IArrowRecord.Column(string columnName, IEqualityComparer<string> comparer) =>
78-
_fields[((StructType)Data.DataType).GetFieldIndex(columnName, comparer)];
78+
Fields[((StructType)Data.DataType).GetFieldIndex(columnName, comparer)];
7979

80-
IArrowArray IArrowRecord.Column(int columnIndex) => _fields[columnIndex];
80+
IArrowArray IArrowRecord.Column(int columnIndex) => Fields[columnIndex];
8181
}
8282
}

Diff for: csharp/test/Apache.Arrow.Tests/RecordTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,25 @@ public void VisitStructAndBatch()
7474
StructArray level2Array = new StructArray(level2, stringArray.Length, new[] { level1Array }, nulls);
7575
RecordBatch batch = new RecordBatch(schema, new IArrowArray[] { level2Array }, stringArray.Length);
7676

77+
var visitor3 = new TestArrayVisitor1();
78+
visitor3.Visit(batch);
79+
Assert.Equal("111utf8", visitor3.stringBuilder.ToString());
80+
var visitor4 = new TestArrayVisitor2();
81+
visitor4.Visit(batch);
82+
Assert.Equal("322utf8", visitor4.stringBuilder.ToString());
83+
}
84+
85+
[Fact]
86+
public void LazyStructInitialization()
87+
{
88+
StringArray stringArray = new StringArray.Builder().Append("one").AppendNull().AppendNull().Append("four").Build();
89+
Field stringField = new Field("column1", StringType.Default, true);
90+
StructType structType = new StructType(new[] { stringField });
91+
ArrayData structData = new ArrayData(structType, stringArray.Length, 0, 0, new[] { ArrowBuffer.Empty }, new[] { stringArray.Data });
92+
IArrowRecord structArray = new StructArray(structData);
7793

94+
Assert.Equal(1, structArray.ColumnCount);
95+
Assert.Equal(structArray.Length, structArray.Column(0).Length);
7896
}
7997

8098
private class TestTypeVisitor1 : IArrowTypeVisitor, IArrowTypeVisitor<IRecordType>

0 commit comments

Comments
 (0)