Skip to content

Commit

Permalink
Fix IArrowRecord implementation on StructArray
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtHagenlocher committed Nov 21, 2023
1 parent 9a36c42 commit 6cc5a03
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 6cc5a03

Please sign in to comment.