Skip to content
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
16 changes: 14 additions & 2 deletions arrow/array/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@ func NewTableFromSlice(schema *arrow.Schema, data [][]arrow.Array) arrow.Table {
chunked.Release()
}

var rows int64
if len(cols) > 0 {
rows = int64(cols[0].Len())
}

tbl := simpleTable{
schema: schema,
cols: cols,
rows: int64(cols[0].Len()),
rows: rows,
}
tbl.refCount.Add(1)

Expand All @@ -178,6 +183,13 @@ func NewTableFromSlice(schema *arrow.Schema, data [][]arrow.Array) arrow.Table {
func NewTableFromRecords(schema *arrow.Schema, recs []arrow.RecordBatch) arrow.Table {
arrs := make([]arrow.Array, len(recs))
cols := make([]arrow.Column, schema.NumFields())
rows := int64(-1)
if len(cols) == 0 {
rows = 0
for _, rec := range recs {
rows += rec.NumRows()
}
}

defer func(cols []arrow.Column) {
for i := range cols {
Expand All @@ -195,7 +207,7 @@ func NewTableFromRecords(schema *arrow.Schema, recs []arrow.RecordBatch) arrow.T
chunk.Release()
}

return NewTable(schema, cols, -1)
return NewTable(schema, cols, rows)
}

func (tbl *simpleTable) Schema() *arrow.Schema { return tbl.schema }
Expand Down
30 changes: 30 additions & 0 deletions arrow/array/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ func TestChunked(t *testing.T) {
}
}

func TestTableFromSliceWithoutColumns(t *testing.T) {
schema := arrow.NewSchema(nil, nil)
tbl := array.NewTableFromSlice(schema, nil)
defer tbl.Release()

if got, want := tbl.NumRows(), int64(0); got != want {
t.Fatalf("NumRows = %d, want %d", got, want)
}
}

func TestTableFromRecordsWithoutColumns(t *testing.T) {
schema := arrow.NewSchema(nil, nil)
records := []arrow.RecordBatch{
array.NewRecordBatch(schema, nil, 2),
array.NewRecordBatch(schema, nil, 3),
}
defer func() {
for _, rec := range records {
rec.Release()
}
}()

tbl := array.NewTableFromRecords(schema, records)
defer tbl.Release()

if got, want := tbl.NumRows(), int64(5); got != want {
t.Fatalf("NumRows = %d, want %d", got, want)
}
}

func TestChunkedEqualDataType(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(t, 0)
Expand Down
Loading