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
4 changes: 3 additions & 1 deletion arrow/array/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ func TestChunkedInvalid(t *testing.T) {
}
}()

// Keep a valid chunk before the mismatch so failed construction must not
// leave an extra reference to it.
c1 := arrow.NewChunked(arrow.PrimitiveTypes.Int32, []arrow.Array{
f1, f2,
f2, f1,
})
defer c1.Release()
}
Expand Down
9 changes: 6 additions & 3 deletions arrow/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ type Chunked struct {
//
// NewChunked panics if the chunks do not have the same data type.
func NewChunked(dtype DataType, chunks []Array) *Chunked {
for _, chunk := range chunks {
if chunk != nil && !TypeEqual(chunk.DataType(), dtype) {
panic(fmt.Errorf("%w: arrow/array: mismatch data type %s vs %s", ErrInvalid, chunk.DataType().String(), dtype.String()))
}
}

arr := &Chunked{
chunks: make([]Array, 0, len(chunks)),
dtype: dtype,
Expand All @@ -157,9 +163,6 @@ func NewChunked(dtype DataType, chunks []Array) *Chunked {
continue
}

if !TypeEqual(chunk.DataType(), dtype) {
panic(fmt.Errorf("%w: arrow/array: mismatch data type %s vs %s", ErrInvalid, chunk.DataType().String(), dtype.String()))
}
chunk.Retain()
arr.chunks = append(arr.chunks, chunk)
arr.length += chunk.Len()
Expand Down
Loading