diff --git a/arrow/array/record.go b/arrow/array/record.go index 0aaf771b..6853dcca 100644 --- a/arrow/array/record.go +++ b/arrow/array/record.go @@ -348,6 +348,34 @@ func (b *RecordBuilder) Reserve(size int) { } } +// Resize adjusts the space allocated by all the field builders to n elements. +// If n is greater than an individual builder Cap(), additional memory will be +// allocated. If n is smaller, the allocated memory may reduced. +// +// As a special case, if n equals to -1, all field builders will be resized +// to the size of the shortest one. +func (b *RecordBuilder) Resize(n int) { + if n >= 0 { + for _, f := range b.fields { + f.Resize(n) + } + } else if n == -1 && len(b.fields) > 0 { + minLen := b.fields[0].Len() + var resizeNeeded bool + + for _, f := range b.fields[1 : ] { + if f.Len() < minLen { + resizeNeeded = true + minLen = f.Len() + } + } + + if resizeNeeded { + b.Resize(minLen) + } + } +} + // NewRecordBatch creates a new record batch from the memory buffers and resets the // RecordBuilder so it can be used to build a new record batch. //