Skip to content

Commit

Permalink
apacheGH-38816: [C#] Fix IArrowRecord implementation on StructArray (a…
Browse files Browse the repository at this point in the history
…pache#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 <curt@hagenlocher.org>
Signed-off-by: Curt Hagenlocher <curt@hagenlocher.org>
  • Loading branch information
CurtHagenlocher authored Nov 21, 2023
1 parent 9a36c42 commit c5a1eb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions csharp/src/Apache.Arrow/Arrays/StructArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ private IReadOnlyList<IArrowArray> InitializeFields()

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];
}
}
18 changes: 18 additions & 0 deletions csharp/test/Apache.Arrow.Tests/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRecordType>
Expand Down

0 comments on commit c5a1eb0

Please sign in to comment.