1 // Code generated by array/numericbuilder.gen.go.tmpl. DO NOT EDIT.
3 // Licensed to the Apache Software Foundation (ASF) under one
4 // or more contributor license agreements. See the NOTICE file
5 // distributed with this work for additional information
6 // regarding copyright ownership. The ASF licenses this file
7 // to you under the Apache License, Version 2.0 (the
8 // "License"); you may not use this file except in compliance
9 // with the License. You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
24 "github.com/apache/arrow/go/v6/arrow"
25 "github.com/apache/arrow/go/v6/arrow/bitutil"
26 "github.com/apache/arrow/go/v6/arrow/internal/debug"
27 "github.com/apache/arrow/go/v6/arrow/memory"
30 type Int64Builder struct {
37 func NewInt64Builder(mem memory.Allocator) *Int64Builder {
38 return &Int64Builder{builder: builder{refCount: 1, mem: mem}}
41 // Release decreases the reference count by 1.
42 // When the reference count goes to zero, the memory is freed.
43 func (b *Int64Builder) Release() {
44 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
46 if atomic.AddInt64(&b.refCount, -1) == 0 {
47 if b.nullBitmap != nil {
48 b.nullBitmap.Release()
59 func (b *Int64Builder) Append(v int64) {
64 func (b *Int64Builder) AppendNull() {
66 b.UnsafeAppendBoolToBitmap(false)
69 func (b *Int64Builder) UnsafeAppend(v int64) {
70 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
71 b.rawData[b.length] = v
75 func (b *Int64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
77 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
84 // AppendValues will append the values in the v slice. The valid slice determines which values
85 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
86 // all values in v are appended and considered valid.
87 func (b *Int64Builder) AppendValues(v []int64, valid []bool) {
88 if len(v) != len(valid) && len(valid) != 0 {
89 panic("len(v) != len(valid) && len(valid) != 0")
97 arrow.Int64Traits.Copy(b.rawData[b.length:], v)
98 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
101 func (b *Int64Builder) init(capacity int) {
102 b.builder.init(capacity)
104 b.data = memory.NewResizableBuffer(b.mem)
105 bytesN := arrow.Int64Traits.BytesRequired(capacity)
106 b.data.Resize(bytesN)
107 b.rawData = arrow.Int64Traits.CastFromBytes(b.data.Bytes())
110 // Reserve ensures there is enough space for appending n elements
111 // by checking the capacity and calling Resize if necessary.
112 func (b *Int64Builder) Reserve(n int) {
113 b.builder.reserve(n, b.Resize)
116 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
117 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
118 func (b *Int64Builder) Resize(n int) {
120 if n < minBuilderCapacity {
121 n = minBuilderCapacity
127 b.builder.resize(nBuilder, b.init)
128 b.data.Resize(arrow.Int64Traits.BytesRequired(n))
129 b.rawData = arrow.Int64Traits.CastFromBytes(b.data.Bytes())
133 // NewArray creates a Int64 array from the memory buffers used by the builder and resets the Int64Builder
134 // so it can be used to build a new array.
135 func (b *Int64Builder) NewArray() Interface {
136 return b.NewInt64Array()
139 // NewInt64Array creates a Int64 array from the memory buffers used by the builder and resets the Int64Builder
140 // so it can be used to build a new array.
141 func (b *Int64Builder) NewInt64Array() (a *Int64) {
143 a = NewInt64Data(data)
148 func (b *Int64Builder) newData() (data *Data) {
149 bytesRequired := arrow.Int64Traits.BytesRequired(b.length)
150 if bytesRequired > 0 && bytesRequired < b.data.Len() {
152 b.data.Resize(bytesRequired)
154 data = NewData(arrow.PrimitiveTypes.Int64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
166 type Uint64Builder struct {
173 func NewUint64Builder(mem memory.Allocator) *Uint64Builder {
174 return &Uint64Builder{builder: builder{refCount: 1, mem: mem}}
177 // Release decreases the reference count by 1.
178 // When the reference count goes to zero, the memory is freed.
179 func (b *Uint64Builder) Release() {
180 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
182 if atomic.AddInt64(&b.refCount, -1) == 0 {
183 if b.nullBitmap != nil {
184 b.nullBitmap.Release()
195 func (b *Uint64Builder) Append(v uint64) {
200 func (b *Uint64Builder) AppendNull() {
202 b.UnsafeAppendBoolToBitmap(false)
205 func (b *Uint64Builder) UnsafeAppend(v uint64) {
206 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
207 b.rawData[b.length] = v
211 func (b *Uint64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
213 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
220 // AppendValues will append the values in the v slice. The valid slice determines which values
221 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
222 // all values in v are appended and considered valid.
223 func (b *Uint64Builder) AppendValues(v []uint64, valid []bool) {
224 if len(v) != len(valid) && len(valid) != 0 {
225 panic("len(v) != len(valid) && len(valid) != 0")
233 arrow.Uint64Traits.Copy(b.rawData[b.length:], v)
234 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
237 func (b *Uint64Builder) init(capacity int) {
238 b.builder.init(capacity)
240 b.data = memory.NewResizableBuffer(b.mem)
241 bytesN := arrow.Uint64Traits.BytesRequired(capacity)
242 b.data.Resize(bytesN)
243 b.rawData = arrow.Uint64Traits.CastFromBytes(b.data.Bytes())
246 // Reserve ensures there is enough space for appending n elements
247 // by checking the capacity and calling Resize if necessary.
248 func (b *Uint64Builder) Reserve(n int) {
249 b.builder.reserve(n, b.Resize)
252 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
253 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
254 func (b *Uint64Builder) Resize(n int) {
256 if n < minBuilderCapacity {
257 n = minBuilderCapacity
263 b.builder.resize(nBuilder, b.init)
264 b.data.Resize(arrow.Uint64Traits.BytesRequired(n))
265 b.rawData = arrow.Uint64Traits.CastFromBytes(b.data.Bytes())
269 // NewArray creates a Uint64 array from the memory buffers used by the builder and resets the Uint64Builder
270 // so it can be used to build a new array.
271 func (b *Uint64Builder) NewArray() Interface {
272 return b.NewUint64Array()
275 // NewUint64Array creates a Uint64 array from the memory buffers used by the builder and resets the Uint64Builder
276 // so it can be used to build a new array.
277 func (b *Uint64Builder) NewUint64Array() (a *Uint64) {
279 a = NewUint64Data(data)
284 func (b *Uint64Builder) newData() (data *Data) {
285 bytesRequired := arrow.Uint64Traits.BytesRequired(b.length)
286 if bytesRequired > 0 && bytesRequired < b.data.Len() {
288 b.data.Resize(bytesRequired)
290 data = NewData(arrow.PrimitiveTypes.Uint64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
302 type Float64Builder struct {
309 func NewFloat64Builder(mem memory.Allocator) *Float64Builder {
310 return &Float64Builder{builder: builder{refCount: 1, mem: mem}}
313 // Release decreases the reference count by 1.
314 // When the reference count goes to zero, the memory is freed.
315 func (b *Float64Builder) Release() {
316 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
318 if atomic.AddInt64(&b.refCount, -1) == 0 {
319 if b.nullBitmap != nil {
320 b.nullBitmap.Release()
331 func (b *Float64Builder) Append(v float64) {
336 func (b *Float64Builder) AppendNull() {
338 b.UnsafeAppendBoolToBitmap(false)
341 func (b *Float64Builder) UnsafeAppend(v float64) {
342 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
343 b.rawData[b.length] = v
347 func (b *Float64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
349 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
356 // AppendValues will append the values in the v slice. The valid slice determines which values
357 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
358 // all values in v are appended and considered valid.
359 func (b *Float64Builder) AppendValues(v []float64, valid []bool) {
360 if len(v) != len(valid) && len(valid) != 0 {
361 panic("len(v) != len(valid) && len(valid) != 0")
369 arrow.Float64Traits.Copy(b.rawData[b.length:], v)
370 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
373 func (b *Float64Builder) init(capacity int) {
374 b.builder.init(capacity)
376 b.data = memory.NewResizableBuffer(b.mem)
377 bytesN := arrow.Float64Traits.BytesRequired(capacity)
378 b.data.Resize(bytesN)
379 b.rawData = arrow.Float64Traits.CastFromBytes(b.data.Bytes())
382 // Reserve ensures there is enough space for appending n elements
383 // by checking the capacity and calling Resize if necessary.
384 func (b *Float64Builder) Reserve(n int) {
385 b.builder.reserve(n, b.Resize)
388 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
389 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
390 func (b *Float64Builder) Resize(n int) {
392 if n < minBuilderCapacity {
393 n = minBuilderCapacity
399 b.builder.resize(nBuilder, b.init)
400 b.data.Resize(arrow.Float64Traits.BytesRequired(n))
401 b.rawData = arrow.Float64Traits.CastFromBytes(b.data.Bytes())
405 // NewArray creates a Float64 array from the memory buffers used by the builder and resets the Float64Builder
406 // so it can be used to build a new array.
407 func (b *Float64Builder) NewArray() Interface {
408 return b.NewFloat64Array()
411 // NewFloat64Array creates a Float64 array from the memory buffers used by the builder and resets the Float64Builder
412 // so it can be used to build a new array.
413 func (b *Float64Builder) NewFloat64Array() (a *Float64) {
415 a = NewFloat64Data(data)
420 func (b *Float64Builder) newData() (data *Data) {
421 bytesRequired := arrow.Float64Traits.BytesRequired(b.length)
422 if bytesRequired > 0 && bytesRequired < b.data.Len() {
424 b.data.Resize(bytesRequired)
426 data = NewData(arrow.PrimitiveTypes.Float64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
438 type Int32Builder struct {
445 func NewInt32Builder(mem memory.Allocator) *Int32Builder {
446 return &Int32Builder{builder: builder{refCount: 1, mem: mem}}
449 // Release decreases the reference count by 1.
450 // When the reference count goes to zero, the memory is freed.
451 func (b *Int32Builder) Release() {
452 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
454 if atomic.AddInt64(&b.refCount, -1) == 0 {
455 if b.nullBitmap != nil {
456 b.nullBitmap.Release()
467 func (b *Int32Builder) Append(v int32) {
472 func (b *Int32Builder) AppendNull() {
474 b.UnsafeAppendBoolToBitmap(false)
477 func (b *Int32Builder) UnsafeAppend(v int32) {
478 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
479 b.rawData[b.length] = v
483 func (b *Int32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
485 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
492 // AppendValues will append the values in the v slice. The valid slice determines which values
493 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
494 // all values in v are appended and considered valid.
495 func (b *Int32Builder) AppendValues(v []int32, valid []bool) {
496 if len(v) != len(valid) && len(valid) != 0 {
497 panic("len(v) != len(valid) && len(valid) != 0")
505 arrow.Int32Traits.Copy(b.rawData[b.length:], v)
506 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
509 func (b *Int32Builder) init(capacity int) {
510 b.builder.init(capacity)
512 b.data = memory.NewResizableBuffer(b.mem)
513 bytesN := arrow.Int32Traits.BytesRequired(capacity)
514 b.data.Resize(bytesN)
515 b.rawData = arrow.Int32Traits.CastFromBytes(b.data.Bytes())
518 // Reserve ensures there is enough space for appending n elements
519 // by checking the capacity and calling Resize if necessary.
520 func (b *Int32Builder) Reserve(n int) {
521 b.builder.reserve(n, b.Resize)
524 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
525 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
526 func (b *Int32Builder) Resize(n int) {
528 if n < minBuilderCapacity {
529 n = minBuilderCapacity
535 b.builder.resize(nBuilder, b.init)
536 b.data.Resize(arrow.Int32Traits.BytesRequired(n))
537 b.rawData = arrow.Int32Traits.CastFromBytes(b.data.Bytes())
541 // NewArray creates a Int32 array from the memory buffers used by the builder and resets the Int32Builder
542 // so it can be used to build a new array.
543 func (b *Int32Builder) NewArray() Interface {
544 return b.NewInt32Array()
547 // NewInt32Array creates a Int32 array from the memory buffers used by the builder and resets the Int32Builder
548 // so it can be used to build a new array.
549 func (b *Int32Builder) NewInt32Array() (a *Int32) {
551 a = NewInt32Data(data)
556 func (b *Int32Builder) newData() (data *Data) {
557 bytesRequired := arrow.Int32Traits.BytesRequired(b.length)
558 if bytesRequired > 0 && bytesRequired < b.data.Len() {
560 b.data.Resize(bytesRequired)
562 data = NewData(arrow.PrimitiveTypes.Int32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
574 type Uint32Builder struct {
581 func NewUint32Builder(mem memory.Allocator) *Uint32Builder {
582 return &Uint32Builder{builder: builder{refCount: 1, mem: mem}}
585 // Release decreases the reference count by 1.
586 // When the reference count goes to zero, the memory is freed.
587 func (b *Uint32Builder) Release() {
588 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
590 if atomic.AddInt64(&b.refCount, -1) == 0 {
591 if b.nullBitmap != nil {
592 b.nullBitmap.Release()
603 func (b *Uint32Builder) Append(v uint32) {
608 func (b *Uint32Builder) AppendNull() {
610 b.UnsafeAppendBoolToBitmap(false)
613 func (b *Uint32Builder) UnsafeAppend(v uint32) {
614 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
615 b.rawData[b.length] = v
619 func (b *Uint32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
621 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
628 // AppendValues will append the values in the v slice. The valid slice determines which values
629 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
630 // all values in v are appended and considered valid.
631 func (b *Uint32Builder) AppendValues(v []uint32, valid []bool) {
632 if len(v) != len(valid) && len(valid) != 0 {
633 panic("len(v) != len(valid) && len(valid) != 0")
641 arrow.Uint32Traits.Copy(b.rawData[b.length:], v)
642 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
645 func (b *Uint32Builder) init(capacity int) {
646 b.builder.init(capacity)
648 b.data = memory.NewResizableBuffer(b.mem)
649 bytesN := arrow.Uint32Traits.BytesRequired(capacity)
650 b.data.Resize(bytesN)
651 b.rawData = arrow.Uint32Traits.CastFromBytes(b.data.Bytes())
654 // Reserve ensures there is enough space for appending n elements
655 // by checking the capacity and calling Resize if necessary.
656 func (b *Uint32Builder) Reserve(n int) {
657 b.builder.reserve(n, b.Resize)
660 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
661 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
662 func (b *Uint32Builder) Resize(n int) {
664 if n < minBuilderCapacity {
665 n = minBuilderCapacity
671 b.builder.resize(nBuilder, b.init)
672 b.data.Resize(arrow.Uint32Traits.BytesRequired(n))
673 b.rawData = arrow.Uint32Traits.CastFromBytes(b.data.Bytes())
677 // NewArray creates a Uint32 array from the memory buffers used by the builder and resets the Uint32Builder
678 // so it can be used to build a new array.
679 func (b *Uint32Builder) NewArray() Interface {
680 return b.NewUint32Array()
683 // NewUint32Array creates a Uint32 array from the memory buffers used by the builder and resets the Uint32Builder
684 // so it can be used to build a new array.
685 func (b *Uint32Builder) NewUint32Array() (a *Uint32) {
687 a = NewUint32Data(data)
692 func (b *Uint32Builder) newData() (data *Data) {
693 bytesRequired := arrow.Uint32Traits.BytesRequired(b.length)
694 if bytesRequired > 0 && bytesRequired < b.data.Len() {
696 b.data.Resize(bytesRequired)
698 data = NewData(arrow.PrimitiveTypes.Uint32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
710 type Float32Builder struct {
717 func NewFloat32Builder(mem memory.Allocator) *Float32Builder {
718 return &Float32Builder{builder: builder{refCount: 1, mem: mem}}
721 // Release decreases the reference count by 1.
722 // When the reference count goes to zero, the memory is freed.
723 func (b *Float32Builder) Release() {
724 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
726 if atomic.AddInt64(&b.refCount, -1) == 0 {
727 if b.nullBitmap != nil {
728 b.nullBitmap.Release()
739 func (b *Float32Builder) Append(v float32) {
744 func (b *Float32Builder) AppendNull() {
746 b.UnsafeAppendBoolToBitmap(false)
749 func (b *Float32Builder) UnsafeAppend(v float32) {
750 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
751 b.rawData[b.length] = v
755 func (b *Float32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
757 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
764 // AppendValues will append the values in the v slice. The valid slice determines which values
765 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
766 // all values in v are appended and considered valid.
767 func (b *Float32Builder) AppendValues(v []float32, valid []bool) {
768 if len(v) != len(valid) && len(valid) != 0 {
769 panic("len(v) != len(valid) && len(valid) != 0")
777 arrow.Float32Traits.Copy(b.rawData[b.length:], v)
778 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
781 func (b *Float32Builder) init(capacity int) {
782 b.builder.init(capacity)
784 b.data = memory.NewResizableBuffer(b.mem)
785 bytesN := arrow.Float32Traits.BytesRequired(capacity)
786 b.data.Resize(bytesN)
787 b.rawData = arrow.Float32Traits.CastFromBytes(b.data.Bytes())
790 // Reserve ensures there is enough space for appending n elements
791 // by checking the capacity and calling Resize if necessary.
792 func (b *Float32Builder) Reserve(n int) {
793 b.builder.reserve(n, b.Resize)
796 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
797 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
798 func (b *Float32Builder) Resize(n int) {
800 if n < minBuilderCapacity {
801 n = minBuilderCapacity
807 b.builder.resize(nBuilder, b.init)
808 b.data.Resize(arrow.Float32Traits.BytesRequired(n))
809 b.rawData = arrow.Float32Traits.CastFromBytes(b.data.Bytes())
813 // NewArray creates a Float32 array from the memory buffers used by the builder and resets the Float32Builder
814 // so it can be used to build a new array.
815 func (b *Float32Builder) NewArray() Interface {
816 return b.NewFloat32Array()
819 // NewFloat32Array creates a Float32 array from the memory buffers used by the builder and resets the Float32Builder
820 // so it can be used to build a new array.
821 func (b *Float32Builder) NewFloat32Array() (a *Float32) {
823 a = NewFloat32Data(data)
828 func (b *Float32Builder) newData() (data *Data) {
829 bytesRequired := arrow.Float32Traits.BytesRequired(b.length)
830 if bytesRequired > 0 && bytesRequired < b.data.Len() {
832 b.data.Resize(bytesRequired)
834 data = NewData(arrow.PrimitiveTypes.Float32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
846 type Int16Builder struct {
853 func NewInt16Builder(mem memory.Allocator) *Int16Builder {
854 return &Int16Builder{builder: builder{refCount: 1, mem: mem}}
857 // Release decreases the reference count by 1.
858 // When the reference count goes to zero, the memory is freed.
859 func (b *Int16Builder) Release() {
860 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
862 if atomic.AddInt64(&b.refCount, -1) == 0 {
863 if b.nullBitmap != nil {
864 b.nullBitmap.Release()
875 func (b *Int16Builder) Append(v int16) {
880 func (b *Int16Builder) AppendNull() {
882 b.UnsafeAppendBoolToBitmap(false)
885 func (b *Int16Builder) UnsafeAppend(v int16) {
886 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
887 b.rawData[b.length] = v
891 func (b *Int16Builder) UnsafeAppendBoolToBitmap(isValid bool) {
893 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
900 // AppendValues will append the values in the v slice. The valid slice determines which values
901 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
902 // all values in v are appended and considered valid.
903 func (b *Int16Builder) AppendValues(v []int16, valid []bool) {
904 if len(v) != len(valid) && len(valid) != 0 {
905 panic("len(v) != len(valid) && len(valid) != 0")
913 arrow.Int16Traits.Copy(b.rawData[b.length:], v)
914 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
917 func (b *Int16Builder) init(capacity int) {
918 b.builder.init(capacity)
920 b.data = memory.NewResizableBuffer(b.mem)
921 bytesN := arrow.Int16Traits.BytesRequired(capacity)
922 b.data.Resize(bytesN)
923 b.rawData = arrow.Int16Traits.CastFromBytes(b.data.Bytes())
926 // Reserve ensures there is enough space for appending n elements
927 // by checking the capacity and calling Resize if necessary.
928 func (b *Int16Builder) Reserve(n int) {
929 b.builder.reserve(n, b.Resize)
932 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
933 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
934 func (b *Int16Builder) Resize(n int) {
936 if n < minBuilderCapacity {
937 n = minBuilderCapacity
943 b.builder.resize(nBuilder, b.init)
944 b.data.Resize(arrow.Int16Traits.BytesRequired(n))
945 b.rawData = arrow.Int16Traits.CastFromBytes(b.data.Bytes())
949 // NewArray creates a Int16 array from the memory buffers used by the builder and resets the Int16Builder
950 // so it can be used to build a new array.
951 func (b *Int16Builder) NewArray() Interface {
952 return b.NewInt16Array()
955 // NewInt16Array creates a Int16 array from the memory buffers used by the builder and resets the Int16Builder
956 // so it can be used to build a new array.
957 func (b *Int16Builder) NewInt16Array() (a *Int16) {
959 a = NewInt16Data(data)
964 func (b *Int16Builder) newData() (data *Data) {
965 bytesRequired := arrow.Int16Traits.BytesRequired(b.length)
966 if bytesRequired > 0 && bytesRequired < b.data.Len() {
968 b.data.Resize(bytesRequired)
970 data = NewData(arrow.PrimitiveTypes.Int16, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
982 type Uint16Builder struct {
989 func NewUint16Builder(mem memory.Allocator) *Uint16Builder {
990 return &Uint16Builder{builder: builder{refCount: 1, mem: mem}}
993 // Release decreases the reference count by 1.
994 // When the reference count goes to zero, the memory is freed.
995 func (b *Uint16Builder) Release() {
996 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
998 if atomic.AddInt64(&b.refCount, -1) == 0 {
999 if b.nullBitmap != nil {
1000 b.nullBitmap.Release()
1011 func (b *Uint16Builder) Append(v uint16) {
1016 func (b *Uint16Builder) AppendNull() {
1018 b.UnsafeAppendBoolToBitmap(false)
1021 func (b *Uint16Builder) UnsafeAppend(v uint16) {
1022 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1023 b.rawData[b.length] = v
1027 func (b *Uint16Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1029 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1036 // AppendValues will append the values in the v slice. The valid slice determines which values
1037 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1038 // all values in v are appended and considered valid.
1039 func (b *Uint16Builder) AppendValues(v []uint16, valid []bool) {
1040 if len(v) != len(valid) && len(valid) != 0 {
1041 panic("len(v) != len(valid) && len(valid) != 0")
1049 arrow.Uint16Traits.Copy(b.rawData[b.length:], v)
1050 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1053 func (b *Uint16Builder) init(capacity int) {
1054 b.builder.init(capacity)
1056 b.data = memory.NewResizableBuffer(b.mem)
1057 bytesN := arrow.Uint16Traits.BytesRequired(capacity)
1058 b.data.Resize(bytesN)
1059 b.rawData = arrow.Uint16Traits.CastFromBytes(b.data.Bytes())
1062 // Reserve ensures there is enough space for appending n elements
1063 // by checking the capacity and calling Resize if necessary.
1064 func (b *Uint16Builder) Reserve(n int) {
1065 b.builder.reserve(n, b.Resize)
1068 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1069 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1070 func (b *Uint16Builder) Resize(n int) {
1072 if n < minBuilderCapacity {
1073 n = minBuilderCapacity
1076 if b.capacity == 0 {
1079 b.builder.resize(nBuilder, b.init)
1080 b.data.Resize(arrow.Uint16Traits.BytesRequired(n))
1081 b.rawData = arrow.Uint16Traits.CastFromBytes(b.data.Bytes())
1085 // NewArray creates a Uint16 array from the memory buffers used by the builder and resets the Uint16Builder
1086 // so it can be used to build a new array.
1087 func (b *Uint16Builder) NewArray() Interface {
1088 return b.NewUint16Array()
1091 // NewUint16Array creates a Uint16 array from the memory buffers used by the builder and resets the Uint16Builder
1092 // so it can be used to build a new array.
1093 func (b *Uint16Builder) NewUint16Array() (a *Uint16) {
1095 a = NewUint16Data(data)
1100 func (b *Uint16Builder) newData() (data *Data) {
1101 bytesRequired := arrow.Uint16Traits.BytesRequired(b.length)
1102 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1104 b.data.Resize(bytesRequired)
1106 data = NewData(arrow.PrimitiveTypes.Uint16, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1118 type Int8Builder struct {
1125 func NewInt8Builder(mem memory.Allocator) *Int8Builder {
1126 return &Int8Builder{builder: builder{refCount: 1, mem: mem}}
1129 // Release decreases the reference count by 1.
1130 // When the reference count goes to zero, the memory is freed.
1131 func (b *Int8Builder) Release() {
1132 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1134 if atomic.AddInt64(&b.refCount, -1) == 0 {
1135 if b.nullBitmap != nil {
1136 b.nullBitmap.Release()
1147 func (b *Int8Builder) Append(v int8) {
1152 func (b *Int8Builder) AppendNull() {
1154 b.UnsafeAppendBoolToBitmap(false)
1157 func (b *Int8Builder) UnsafeAppend(v int8) {
1158 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1159 b.rawData[b.length] = v
1163 func (b *Int8Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1165 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1172 // AppendValues will append the values in the v slice. The valid slice determines which values
1173 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1174 // all values in v are appended and considered valid.
1175 func (b *Int8Builder) AppendValues(v []int8, valid []bool) {
1176 if len(v) != len(valid) && len(valid) != 0 {
1177 panic("len(v) != len(valid) && len(valid) != 0")
1185 arrow.Int8Traits.Copy(b.rawData[b.length:], v)
1186 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1189 func (b *Int8Builder) init(capacity int) {
1190 b.builder.init(capacity)
1192 b.data = memory.NewResizableBuffer(b.mem)
1193 bytesN := arrow.Int8Traits.BytesRequired(capacity)
1194 b.data.Resize(bytesN)
1195 b.rawData = arrow.Int8Traits.CastFromBytes(b.data.Bytes())
1198 // Reserve ensures there is enough space for appending n elements
1199 // by checking the capacity and calling Resize if necessary.
1200 func (b *Int8Builder) Reserve(n int) {
1201 b.builder.reserve(n, b.Resize)
1204 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1205 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1206 func (b *Int8Builder) Resize(n int) {
1208 if n < minBuilderCapacity {
1209 n = minBuilderCapacity
1212 if b.capacity == 0 {
1215 b.builder.resize(nBuilder, b.init)
1216 b.data.Resize(arrow.Int8Traits.BytesRequired(n))
1217 b.rawData = arrow.Int8Traits.CastFromBytes(b.data.Bytes())
1221 // NewArray creates a Int8 array from the memory buffers used by the builder and resets the Int8Builder
1222 // so it can be used to build a new array.
1223 func (b *Int8Builder) NewArray() Interface {
1224 return b.NewInt8Array()
1227 // NewInt8Array creates a Int8 array from the memory buffers used by the builder and resets the Int8Builder
1228 // so it can be used to build a new array.
1229 func (b *Int8Builder) NewInt8Array() (a *Int8) {
1231 a = NewInt8Data(data)
1236 func (b *Int8Builder) newData() (data *Data) {
1237 bytesRequired := arrow.Int8Traits.BytesRequired(b.length)
1238 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1240 b.data.Resize(bytesRequired)
1242 data = NewData(arrow.PrimitiveTypes.Int8, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1254 type Uint8Builder struct {
1261 func NewUint8Builder(mem memory.Allocator) *Uint8Builder {
1262 return &Uint8Builder{builder: builder{refCount: 1, mem: mem}}
1265 // Release decreases the reference count by 1.
1266 // When the reference count goes to zero, the memory is freed.
1267 func (b *Uint8Builder) Release() {
1268 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1270 if atomic.AddInt64(&b.refCount, -1) == 0 {
1271 if b.nullBitmap != nil {
1272 b.nullBitmap.Release()
1283 func (b *Uint8Builder) Append(v uint8) {
1288 func (b *Uint8Builder) AppendNull() {
1290 b.UnsafeAppendBoolToBitmap(false)
1293 func (b *Uint8Builder) UnsafeAppend(v uint8) {
1294 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1295 b.rawData[b.length] = v
1299 func (b *Uint8Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1301 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1308 // AppendValues will append the values in the v slice. The valid slice determines which values
1309 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1310 // all values in v are appended and considered valid.
1311 func (b *Uint8Builder) AppendValues(v []uint8, valid []bool) {
1312 if len(v) != len(valid) && len(valid) != 0 {
1313 panic("len(v) != len(valid) && len(valid) != 0")
1321 arrow.Uint8Traits.Copy(b.rawData[b.length:], v)
1322 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1325 func (b *Uint8Builder) init(capacity int) {
1326 b.builder.init(capacity)
1328 b.data = memory.NewResizableBuffer(b.mem)
1329 bytesN := arrow.Uint8Traits.BytesRequired(capacity)
1330 b.data.Resize(bytesN)
1331 b.rawData = arrow.Uint8Traits.CastFromBytes(b.data.Bytes())
1334 // Reserve ensures there is enough space for appending n elements
1335 // by checking the capacity and calling Resize if necessary.
1336 func (b *Uint8Builder) Reserve(n int) {
1337 b.builder.reserve(n, b.Resize)
1340 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1341 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1342 func (b *Uint8Builder) Resize(n int) {
1344 if n < minBuilderCapacity {
1345 n = minBuilderCapacity
1348 if b.capacity == 0 {
1351 b.builder.resize(nBuilder, b.init)
1352 b.data.Resize(arrow.Uint8Traits.BytesRequired(n))
1353 b.rawData = arrow.Uint8Traits.CastFromBytes(b.data.Bytes())
1357 // NewArray creates a Uint8 array from the memory buffers used by the builder and resets the Uint8Builder
1358 // so it can be used to build a new array.
1359 func (b *Uint8Builder) NewArray() Interface {
1360 return b.NewUint8Array()
1363 // NewUint8Array creates a Uint8 array from the memory buffers used by the builder and resets the Uint8Builder
1364 // so it can be used to build a new array.
1365 func (b *Uint8Builder) NewUint8Array() (a *Uint8) {
1367 a = NewUint8Data(data)
1372 func (b *Uint8Builder) newData() (data *Data) {
1373 bytesRequired := arrow.Uint8Traits.BytesRequired(b.length)
1374 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1376 b.data.Resize(bytesRequired)
1378 data = NewData(arrow.PrimitiveTypes.Uint8, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1390 type TimestampBuilder struct {
1393 dtype *arrow.TimestampType
1395 rawData []arrow.Timestamp
1398 func NewTimestampBuilder(mem memory.Allocator, dtype *arrow.TimestampType) *TimestampBuilder {
1399 return &TimestampBuilder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1402 // Release decreases the reference count by 1.
1403 // When the reference count goes to zero, the memory is freed.
1404 func (b *TimestampBuilder) Release() {
1405 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1407 if atomic.AddInt64(&b.refCount, -1) == 0 {
1408 if b.nullBitmap != nil {
1409 b.nullBitmap.Release()
1420 func (b *TimestampBuilder) Append(v arrow.Timestamp) {
1425 func (b *TimestampBuilder) AppendNull() {
1427 b.UnsafeAppendBoolToBitmap(false)
1430 func (b *TimestampBuilder) UnsafeAppend(v arrow.Timestamp) {
1431 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1432 b.rawData[b.length] = v
1436 func (b *TimestampBuilder) UnsafeAppendBoolToBitmap(isValid bool) {
1438 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1445 // AppendValues will append the values in the v slice. The valid slice determines which values
1446 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1447 // all values in v are appended and considered valid.
1448 func (b *TimestampBuilder) AppendValues(v []arrow.Timestamp, valid []bool) {
1449 if len(v) != len(valid) && len(valid) != 0 {
1450 panic("len(v) != len(valid) && len(valid) != 0")
1458 arrow.TimestampTraits.Copy(b.rawData[b.length:], v)
1459 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1462 func (b *TimestampBuilder) init(capacity int) {
1463 b.builder.init(capacity)
1465 b.data = memory.NewResizableBuffer(b.mem)
1466 bytesN := arrow.TimestampTraits.BytesRequired(capacity)
1467 b.data.Resize(bytesN)
1468 b.rawData = arrow.TimestampTraits.CastFromBytes(b.data.Bytes())
1471 // Reserve ensures there is enough space for appending n elements
1472 // by checking the capacity and calling Resize if necessary.
1473 func (b *TimestampBuilder) Reserve(n int) {
1474 b.builder.reserve(n, b.Resize)
1477 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1478 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1479 func (b *TimestampBuilder) Resize(n int) {
1481 if n < minBuilderCapacity {
1482 n = minBuilderCapacity
1485 if b.capacity == 0 {
1488 b.builder.resize(nBuilder, b.init)
1489 b.data.Resize(arrow.TimestampTraits.BytesRequired(n))
1490 b.rawData = arrow.TimestampTraits.CastFromBytes(b.data.Bytes())
1494 // NewArray creates a Timestamp array from the memory buffers used by the builder and resets the TimestampBuilder
1495 // so it can be used to build a new array.
1496 func (b *TimestampBuilder) NewArray() Interface {
1497 return b.NewTimestampArray()
1500 // NewTimestampArray creates a Timestamp array from the memory buffers used by the builder and resets the TimestampBuilder
1501 // so it can be used to build a new array.
1502 func (b *TimestampBuilder) NewTimestampArray() (a *Timestamp) {
1504 a = NewTimestampData(data)
1509 func (b *TimestampBuilder) newData() (data *Data) {
1510 bytesRequired := arrow.TimestampTraits.BytesRequired(b.length)
1511 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1513 b.data.Resize(bytesRequired)
1515 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1527 type Time32Builder struct {
1530 dtype *arrow.Time32Type
1532 rawData []arrow.Time32
1535 func NewTime32Builder(mem memory.Allocator, dtype *arrow.Time32Type) *Time32Builder {
1536 return &Time32Builder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1539 // Release decreases the reference count by 1.
1540 // When the reference count goes to zero, the memory is freed.
1541 func (b *Time32Builder) Release() {
1542 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1544 if atomic.AddInt64(&b.refCount, -1) == 0 {
1545 if b.nullBitmap != nil {
1546 b.nullBitmap.Release()
1557 func (b *Time32Builder) Append(v arrow.Time32) {
1562 func (b *Time32Builder) AppendNull() {
1564 b.UnsafeAppendBoolToBitmap(false)
1567 func (b *Time32Builder) UnsafeAppend(v arrow.Time32) {
1568 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1569 b.rawData[b.length] = v
1573 func (b *Time32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1575 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1582 // AppendValues will append the values in the v slice. The valid slice determines which values
1583 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1584 // all values in v are appended and considered valid.
1585 func (b *Time32Builder) AppendValues(v []arrow.Time32, valid []bool) {
1586 if len(v) != len(valid) && len(valid) != 0 {
1587 panic("len(v) != len(valid) && len(valid) != 0")
1595 arrow.Time32Traits.Copy(b.rawData[b.length:], v)
1596 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1599 func (b *Time32Builder) init(capacity int) {
1600 b.builder.init(capacity)
1602 b.data = memory.NewResizableBuffer(b.mem)
1603 bytesN := arrow.Time32Traits.BytesRequired(capacity)
1604 b.data.Resize(bytesN)
1605 b.rawData = arrow.Time32Traits.CastFromBytes(b.data.Bytes())
1608 // Reserve ensures there is enough space for appending n elements
1609 // by checking the capacity and calling Resize if necessary.
1610 func (b *Time32Builder) Reserve(n int) {
1611 b.builder.reserve(n, b.Resize)
1614 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1615 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1616 func (b *Time32Builder) Resize(n int) {
1618 if n < minBuilderCapacity {
1619 n = minBuilderCapacity
1622 if b.capacity == 0 {
1625 b.builder.resize(nBuilder, b.init)
1626 b.data.Resize(arrow.Time32Traits.BytesRequired(n))
1627 b.rawData = arrow.Time32Traits.CastFromBytes(b.data.Bytes())
1631 // NewArray creates a Time32 array from the memory buffers used by the builder and resets the Time32Builder
1632 // so it can be used to build a new array.
1633 func (b *Time32Builder) NewArray() Interface {
1634 return b.NewTime32Array()
1637 // NewTime32Array creates a Time32 array from the memory buffers used by the builder and resets the Time32Builder
1638 // so it can be used to build a new array.
1639 func (b *Time32Builder) NewTime32Array() (a *Time32) {
1641 a = NewTime32Data(data)
1646 func (b *Time32Builder) newData() (data *Data) {
1647 bytesRequired := arrow.Time32Traits.BytesRequired(b.length)
1648 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1650 b.data.Resize(bytesRequired)
1652 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1664 type Time64Builder struct {
1667 dtype *arrow.Time64Type
1669 rawData []arrow.Time64
1672 func NewTime64Builder(mem memory.Allocator, dtype *arrow.Time64Type) *Time64Builder {
1673 return &Time64Builder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1676 // Release decreases the reference count by 1.
1677 // When the reference count goes to zero, the memory is freed.
1678 func (b *Time64Builder) Release() {
1679 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1681 if atomic.AddInt64(&b.refCount, -1) == 0 {
1682 if b.nullBitmap != nil {
1683 b.nullBitmap.Release()
1694 func (b *Time64Builder) Append(v arrow.Time64) {
1699 func (b *Time64Builder) AppendNull() {
1701 b.UnsafeAppendBoolToBitmap(false)
1704 func (b *Time64Builder) UnsafeAppend(v arrow.Time64) {
1705 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1706 b.rawData[b.length] = v
1710 func (b *Time64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1712 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1719 // AppendValues will append the values in the v slice. The valid slice determines which values
1720 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1721 // all values in v are appended and considered valid.
1722 func (b *Time64Builder) AppendValues(v []arrow.Time64, valid []bool) {
1723 if len(v) != len(valid) && len(valid) != 0 {
1724 panic("len(v) != len(valid) && len(valid) != 0")
1732 arrow.Time64Traits.Copy(b.rawData[b.length:], v)
1733 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1736 func (b *Time64Builder) init(capacity int) {
1737 b.builder.init(capacity)
1739 b.data = memory.NewResizableBuffer(b.mem)
1740 bytesN := arrow.Time64Traits.BytesRequired(capacity)
1741 b.data.Resize(bytesN)
1742 b.rawData = arrow.Time64Traits.CastFromBytes(b.data.Bytes())
1745 // Reserve ensures there is enough space for appending n elements
1746 // by checking the capacity and calling Resize if necessary.
1747 func (b *Time64Builder) Reserve(n int) {
1748 b.builder.reserve(n, b.Resize)
1751 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1752 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1753 func (b *Time64Builder) Resize(n int) {
1755 if n < minBuilderCapacity {
1756 n = minBuilderCapacity
1759 if b.capacity == 0 {
1762 b.builder.resize(nBuilder, b.init)
1763 b.data.Resize(arrow.Time64Traits.BytesRequired(n))
1764 b.rawData = arrow.Time64Traits.CastFromBytes(b.data.Bytes())
1768 // NewArray creates a Time64 array from the memory buffers used by the builder and resets the Time64Builder
1769 // so it can be used to build a new array.
1770 func (b *Time64Builder) NewArray() Interface {
1771 return b.NewTime64Array()
1774 // NewTime64Array creates a Time64 array from the memory buffers used by the builder and resets the Time64Builder
1775 // so it can be used to build a new array.
1776 func (b *Time64Builder) NewTime64Array() (a *Time64) {
1778 a = NewTime64Data(data)
1783 func (b *Time64Builder) newData() (data *Data) {
1784 bytesRequired := arrow.Time64Traits.BytesRequired(b.length)
1785 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1787 b.data.Resize(bytesRequired)
1789 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1801 type Date32Builder struct {
1805 rawData []arrow.Date32
1808 func NewDate32Builder(mem memory.Allocator) *Date32Builder {
1809 return &Date32Builder{builder: builder{refCount: 1, mem: mem}}
1812 // Release decreases the reference count by 1.
1813 // When the reference count goes to zero, the memory is freed.
1814 func (b *Date32Builder) Release() {
1815 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1817 if atomic.AddInt64(&b.refCount, -1) == 0 {
1818 if b.nullBitmap != nil {
1819 b.nullBitmap.Release()
1830 func (b *Date32Builder) Append(v arrow.Date32) {
1835 func (b *Date32Builder) AppendNull() {
1837 b.UnsafeAppendBoolToBitmap(false)
1840 func (b *Date32Builder) UnsafeAppend(v arrow.Date32) {
1841 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1842 b.rawData[b.length] = v
1846 func (b *Date32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1848 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1855 // AppendValues will append the values in the v slice. The valid slice determines which values
1856 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1857 // all values in v are appended and considered valid.
1858 func (b *Date32Builder) AppendValues(v []arrow.Date32, valid []bool) {
1859 if len(v) != len(valid) && len(valid) != 0 {
1860 panic("len(v) != len(valid) && len(valid) != 0")
1868 arrow.Date32Traits.Copy(b.rawData[b.length:], v)
1869 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1872 func (b *Date32Builder) init(capacity int) {
1873 b.builder.init(capacity)
1875 b.data = memory.NewResizableBuffer(b.mem)
1876 bytesN := arrow.Date32Traits.BytesRequired(capacity)
1877 b.data.Resize(bytesN)
1878 b.rawData = arrow.Date32Traits.CastFromBytes(b.data.Bytes())
1881 // Reserve ensures there is enough space for appending n elements
1882 // by checking the capacity and calling Resize if necessary.
1883 func (b *Date32Builder) Reserve(n int) {
1884 b.builder.reserve(n, b.Resize)
1887 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
1888 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
1889 func (b *Date32Builder) Resize(n int) {
1891 if n < minBuilderCapacity {
1892 n = minBuilderCapacity
1895 if b.capacity == 0 {
1898 b.builder.resize(nBuilder, b.init)
1899 b.data.Resize(arrow.Date32Traits.BytesRequired(n))
1900 b.rawData = arrow.Date32Traits.CastFromBytes(b.data.Bytes())
1904 // NewArray creates a Date32 array from the memory buffers used by the builder and resets the Date32Builder
1905 // so it can be used to build a new array.
1906 func (b *Date32Builder) NewArray() Interface {
1907 return b.NewDate32Array()
1910 // NewDate32Array creates a Date32 array from the memory buffers used by the builder and resets the Date32Builder
1911 // so it can be used to build a new array.
1912 func (b *Date32Builder) NewDate32Array() (a *Date32) {
1914 a = NewDate32Data(data)
1919 func (b *Date32Builder) newData() (data *Data) {
1920 bytesRequired := arrow.Date32Traits.BytesRequired(b.length)
1921 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1923 b.data.Resize(bytesRequired)
1925 data = NewData(arrow.PrimitiveTypes.Date32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1937 type Date64Builder struct {
1941 rawData []arrow.Date64
1944 func NewDate64Builder(mem memory.Allocator) *Date64Builder {
1945 return &Date64Builder{builder: builder{refCount: 1, mem: mem}}
1948 // Release decreases the reference count by 1.
1949 // When the reference count goes to zero, the memory is freed.
1950 func (b *Date64Builder) Release() {
1951 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
1953 if atomic.AddInt64(&b.refCount, -1) == 0 {
1954 if b.nullBitmap != nil {
1955 b.nullBitmap.Release()
1966 func (b *Date64Builder) Append(v arrow.Date64) {
1971 func (b *Date64Builder) AppendNull() {
1973 b.UnsafeAppendBoolToBitmap(false)
1976 func (b *Date64Builder) UnsafeAppend(v arrow.Date64) {
1977 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1978 b.rawData[b.length] = v
1982 func (b *Date64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1984 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1991 // AppendValues will append the values in the v slice. The valid slice determines which values
1992 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
1993 // all values in v are appended and considered valid.
1994 func (b *Date64Builder) AppendValues(v []arrow.Date64, valid []bool) {
1995 if len(v) != len(valid) && len(valid) != 0 {
1996 panic("len(v) != len(valid) && len(valid) != 0")
2004 arrow.Date64Traits.Copy(b.rawData[b.length:], v)
2005 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
2008 func (b *Date64Builder) init(capacity int) {
2009 b.builder.init(capacity)
2011 b.data = memory.NewResizableBuffer(b.mem)
2012 bytesN := arrow.Date64Traits.BytesRequired(capacity)
2013 b.data.Resize(bytesN)
2014 b.rawData = arrow.Date64Traits.CastFromBytes(b.data.Bytes())
2017 // Reserve ensures there is enough space for appending n elements
2018 // by checking the capacity and calling Resize if necessary.
2019 func (b *Date64Builder) Reserve(n int) {
2020 b.builder.reserve(n, b.Resize)
2023 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
2024 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
2025 func (b *Date64Builder) Resize(n int) {
2027 if n < minBuilderCapacity {
2028 n = minBuilderCapacity
2031 if b.capacity == 0 {
2034 b.builder.resize(nBuilder, b.init)
2035 b.data.Resize(arrow.Date64Traits.BytesRequired(n))
2036 b.rawData = arrow.Date64Traits.CastFromBytes(b.data.Bytes())
2040 // NewArray creates a Date64 array from the memory buffers used by the builder and resets the Date64Builder
2041 // so it can be used to build a new array.
2042 func (b *Date64Builder) NewArray() Interface {
2043 return b.NewDate64Array()
2046 // NewDate64Array creates a Date64 array from the memory buffers used by the builder and resets the Date64Builder
2047 // so it can be used to build a new array.
2048 func (b *Date64Builder) NewDate64Array() (a *Date64) {
2050 a = NewDate64Data(data)
2055 func (b *Date64Builder) newData() (data *Data) {
2056 bytesRequired := arrow.Date64Traits.BytesRequired(b.length)
2057 if bytesRequired > 0 && bytesRequired < b.data.Len() {
2059 b.data.Resize(bytesRequired)
2061 data = NewData(arrow.PrimitiveTypes.Date64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
2073 type DurationBuilder struct {
2076 dtype *arrow.DurationType
2078 rawData []arrow.Duration
2081 func NewDurationBuilder(mem memory.Allocator, dtype *arrow.DurationType) *DurationBuilder {
2082 return &DurationBuilder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
2085 // Release decreases the reference count by 1.
2086 // When the reference count goes to zero, the memory is freed.
2087 func (b *DurationBuilder) Release() {
2088 debug.Assert(atomic.LoadInt64(&b.refCount) > 0, "too many releases")
2090 if atomic.AddInt64(&b.refCount, -1) == 0 {
2091 if b.nullBitmap != nil {
2092 b.nullBitmap.Release()
2103 func (b *DurationBuilder) Append(v arrow.Duration) {
2108 func (b *DurationBuilder) AppendNull() {
2110 b.UnsafeAppendBoolToBitmap(false)
2113 func (b *DurationBuilder) UnsafeAppend(v arrow.Duration) {
2114 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
2115 b.rawData[b.length] = v
2119 func (b *DurationBuilder) UnsafeAppendBoolToBitmap(isValid bool) {
2121 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
2128 // AppendValues will append the values in the v slice. The valid slice determines which values
2129 // in v are valid (not null). The valid slice must either be empty or be equal in length to v. If empty,
2130 // all values in v are appended and considered valid.
2131 func (b *DurationBuilder) AppendValues(v []arrow.Duration, valid []bool) {
2132 if len(v) != len(valid) && len(valid) != 0 {
2133 panic("len(v) != len(valid) && len(valid) != 0")
2141 arrow.DurationTraits.Copy(b.rawData[b.length:], v)
2142 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
2145 func (b *DurationBuilder) init(capacity int) {
2146 b.builder.init(capacity)
2148 b.data = memory.NewResizableBuffer(b.mem)
2149 bytesN := arrow.DurationTraits.BytesRequired(capacity)
2150 b.data.Resize(bytesN)
2151 b.rawData = arrow.DurationTraits.CastFromBytes(b.data.Bytes())
2154 // Reserve ensures there is enough space for appending n elements
2155 // by checking the capacity and calling Resize if necessary.
2156 func (b *DurationBuilder) Reserve(n int) {
2157 b.builder.reserve(n, b.Resize)
2160 // Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
2161 // additional memory will be allocated. If n is smaller, the allocated memory may reduced.
2162 func (b *DurationBuilder) Resize(n int) {
2164 if n < minBuilderCapacity {
2165 n = minBuilderCapacity
2168 if b.capacity == 0 {
2171 b.builder.resize(nBuilder, b.init)
2172 b.data.Resize(arrow.DurationTraits.BytesRequired(n))
2173 b.rawData = arrow.DurationTraits.CastFromBytes(b.data.Bytes())
2177 // NewArray creates a Duration array from the memory buffers used by the builder and resets the DurationBuilder
2178 // so it can be used to build a new array.
2179 func (b *DurationBuilder) NewArray() Interface {
2180 return b.NewDurationArray()
2183 // NewDurationArray creates a Duration array from the memory buffers used by the builder and resets the DurationBuilder
2184 // so it can be used to build a new array.
2185 func (b *DurationBuilder) NewDurationArray() (a *Duration) {
2187 a = NewDurationData(data)
2192 func (b *DurationBuilder) newData() (data *Data) {
2193 bytesRequired := arrow.DurationTraits.BytesRequired(b.length)
2194 if bytesRequired > 0 && bytesRequired < b.data.Len() {
2196 b.data.Resize(bytesRequired)
2198 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
2211 _ Builder = (*Int64Builder)(nil)
2212 _ Builder = (*Uint64Builder)(nil)
2213 _ Builder = (*Float64Builder)(nil)
2214 _ Builder = (*Int32Builder)(nil)
2215 _ Builder = (*Uint32Builder)(nil)
2216 _ Builder = (*Float32Builder)(nil)
2217 _ Builder = (*Int16Builder)(nil)
2218 _ Builder = (*Uint16Builder)(nil)
2219 _ Builder = (*Int8Builder)(nil)
2220 _ Builder = (*Uint8Builder)(nil)
2221 _ Builder = (*TimestampBuilder)(nil)
2222 _ Builder = (*Time32Builder)(nil)
2223 _ Builder = (*Time64Builder)(nil)
2224 _ Builder = (*Date32Builder)(nil)
2225 _ Builder = (*Date64Builder)(nil)
2226 _ Builder = (*DurationBuilder)(nil)