Skip to content

Commit 9b0afc3

Browse files
authored
ARROW-13129: [C#] Fix TableFromRecordBatches (apache#10562)
Authored-by: nullptr <3621629+0x0L@users.noreply.github.com> Signed-off-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent 797c88a commit 9b0afc3

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎csharp/src/Apache.Arrow/Table.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ public static Table TableFromRecordBatches(Schema schema, IList<RecordBatch> rec
3535
int nColumns = schema.Fields.Count;
3636

3737
List<Column> columns = new List<Column>(nColumns);
38-
List<Array> columnArrays = new List<Array>(nBatches);
3938
for (int icol = 0; icol < nColumns; icol++)
4039
{
40+
List<Array> columnArrays = new List<Array>(nBatches);
4141
for (int jj = 0; jj < nBatches; jj++)
4242
{
4343
columnArrays.Add(recordBatches[jj].Column(icol) as Array);
4444
}
4545
columns.Add(new Arrow.Column(schema.GetFieldByIndex(icol), columnArrays));
46-
columnArrays.Clear();
4746
}
4847

4948
return new Table(schema, columns);

‎csharp/test/Apache.Arrow.Tests/TableTests.cs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void TestTableFromRecordBatches()
6969

7070
List<Field> fields = new List<Field>();
7171
Field.Builder fieldBuilder = new Field.Builder();
72-
fields.Add(fieldBuilder.Name("Ints").DataType(Int32Type.Default).Nullable(true).Build());
72+
fields.Add(fieldBuilder.Name("Ints").DataType(Int32Type.Default).Nullable(true).Build());
7373
fieldBuilder = new Field.Builder();
7474
fields.Add(fieldBuilder.Name("Strings").DataType(StringType.Default).Nullable(true).Build());
7575
StructType structType = new StructType(fields);
@@ -107,5 +107,19 @@ public void TestTableAddRemoveAndSetColumn()
107107
newTable = table.SetColumn(0, existingColumn);
108108
Assert.True(newTable.Column(0) == existingColumn);
109109
}
110+
111+
[Fact]
112+
public void TestBuildFromRecordBatch()
113+
{
114+
Schema.Builder builder = new Schema.Builder();
115+
builder.Field(new Field("A", Int64Type.Default, nullable: false));
116+
Schema schema = builder.Build();
117+
118+
RecordBatch batch = TestData.CreateSampleRecordBatch(schema, 10);
119+
Table table = Table.TableFromRecordBatches(schema, new[] { batch });
120+
121+
Assert.NotNull(table.Column(0).Data.Array(0) as Int64Array);
122+
}
110123
}
124+
111125
}

0 commit comments

Comments
 (0)