Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-38816: [C#] Fix IArrowRecord implementation on StructArray #38827

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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