]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/array/numericbuilder.gen.go
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / array / numericbuilder.gen.go
1 // Code generated by array/numericbuilder.gen.go.tmpl. DO NOT EDIT.
2
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
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18
19 package array
20
21 import (
22 "sync/atomic"
23
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"
28 )
29
30 type Int64Builder struct {
31 builder
32
33 data *memory.Buffer
34 rawData []int64
35 }
36
37 func NewInt64Builder(mem memory.Allocator) *Int64Builder {
38 return &Int64Builder{builder: builder{refCount: 1, mem: mem}}
39 }
40
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")
45
46 if atomic.AddInt64(&b.refCount, -1) == 0 {
47 if b.nullBitmap != nil {
48 b.nullBitmap.Release()
49 b.nullBitmap = nil
50 }
51 if b.data != nil {
52 b.data.Release()
53 b.data = nil
54 b.rawData = nil
55 }
56 }
57 }
58
59 func (b *Int64Builder) Append(v int64) {
60 b.Reserve(1)
61 b.UnsafeAppend(v)
62 }
63
64 func (b *Int64Builder) AppendNull() {
65 b.Reserve(1)
66 b.UnsafeAppendBoolToBitmap(false)
67 }
68
69 func (b *Int64Builder) UnsafeAppend(v int64) {
70 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
71 b.rawData[b.length] = v
72 b.length++
73 }
74
75 func (b *Int64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
76 if isValid {
77 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
78 } else {
79 b.nulls++
80 }
81 b.length++
82 }
83
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")
90 }
91
92 if len(v) == 0 {
93 return
94 }
95
96 b.Reserve(len(v))
97 arrow.Int64Traits.Copy(b.rawData[b.length:], v)
98 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
99 }
100
101 func (b *Int64Builder) init(capacity int) {
102 b.builder.init(capacity)
103
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())
108 }
109
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)
114 }
115
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) {
119 nBuilder := n
120 if n < minBuilderCapacity {
121 n = minBuilderCapacity
122 }
123
124 if b.capacity == 0 {
125 b.init(n)
126 } else {
127 b.builder.resize(nBuilder, b.init)
128 b.data.Resize(arrow.Int64Traits.BytesRequired(n))
129 b.rawData = arrow.Int64Traits.CastFromBytes(b.data.Bytes())
130 }
131 }
132
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()
137 }
138
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) {
142 data := b.newData()
143 a = NewInt64Data(data)
144 data.Release()
145 return
146 }
147
148 func (b *Int64Builder) newData() (data *Data) {
149 bytesRequired := arrow.Int64Traits.BytesRequired(b.length)
150 if bytesRequired > 0 && bytesRequired < b.data.Len() {
151 // trim buffers
152 b.data.Resize(bytesRequired)
153 }
154 data = NewData(arrow.PrimitiveTypes.Int64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
155 b.reset()
156
157 if b.data != nil {
158 b.data.Release()
159 b.data = nil
160 b.rawData = nil
161 }
162
163 return
164 }
165
166 type Uint64Builder struct {
167 builder
168
169 data *memory.Buffer
170 rawData []uint64
171 }
172
173 func NewUint64Builder(mem memory.Allocator) *Uint64Builder {
174 return &Uint64Builder{builder: builder{refCount: 1, mem: mem}}
175 }
176
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")
181
182 if atomic.AddInt64(&b.refCount, -1) == 0 {
183 if b.nullBitmap != nil {
184 b.nullBitmap.Release()
185 b.nullBitmap = nil
186 }
187 if b.data != nil {
188 b.data.Release()
189 b.data = nil
190 b.rawData = nil
191 }
192 }
193 }
194
195 func (b *Uint64Builder) Append(v uint64) {
196 b.Reserve(1)
197 b.UnsafeAppend(v)
198 }
199
200 func (b *Uint64Builder) AppendNull() {
201 b.Reserve(1)
202 b.UnsafeAppendBoolToBitmap(false)
203 }
204
205 func (b *Uint64Builder) UnsafeAppend(v uint64) {
206 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
207 b.rawData[b.length] = v
208 b.length++
209 }
210
211 func (b *Uint64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
212 if isValid {
213 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
214 } else {
215 b.nulls++
216 }
217 b.length++
218 }
219
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")
226 }
227
228 if len(v) == 0 {
229 return
230 }
231
232 b.Reserve(len(v))
233 arrow.Uint64Traits.Copy(b.rawData[b.length:], v)
234 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
235 }
236
237 func (b *Uint64Builder) init(capacity int) {
238 b.builder.init(capacity)
239
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())
244 }
245
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)
250 }
251
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) {
255 nBuilder := n
256 if n < minBuilderCapacity {
257 n = minBuilderCapacity
258 }
259
260 if b.capacity == 0 {
261 b.init(n)
262 } else {
263 b.builder.resize(nBuilder, b.init)
264 b.data.Resize(arrow.Uint64Traits.BytesRequired(n))
265 b.rawData = arrow.Uint64Traits.CastFromBytes(b.data.Bytes())
266 }
267 }
268
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()
273 }
274
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) {
278 data := b.newData()
279 a = NewUint64Data(data)
280 data.Release()
281 return
282 }
283
284 func (b *Uint64Builder) newData() (data *Data) {
285 bytesRequired := arrow.Uint64Traits.BytesRequired(b.length)
286 if bytesRequired > 0 && bytesRequired < b.data.Len() {
287 // trim buffers
288 b.data.Resize(bytesRequired)
289 }
290 data = NewData(arrow.PrimitiveTypes.Uint64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
291 b.reset()
292
293 if b.data != nil {
294 b.data.Release()
295 b.data = nil
296 b.rawData = nil
297 }
298
299 return
300 }
301
302 type Float64Builder struct {
303 builder
304
305 data *memory.Buffer
306 rawData []float64
307 }
308
309 func NewFloat64Builder(mem memory.Allocator) *Float64Builder {
310 return &Float64Builder{builder: builder{refCount: 1, mem: mem}}
311 }
312
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")
317
318 if atomic.AddInt64(&b.refCount, -1) == 0 {
319 if b.nullBitmap != nil {
320 b.nullBitmap.Release()
321 b.nullBitmap = nil
322 }
323 if b.data != nil {
324 b.data.Release()
325 b.data = nil
326 b.rawData = nil
327 }
328 }
329 }
330
331 func (b *Float64Builder) Append(v float64) {
332 b.Reserve(1)
333 b.UnsafeAppend(v)
334 }
335
336 func (b *Float64Builder) AppendNull() {
337 b.Reserve(1)
338 b.UnsafeAppendBoolToBitmap(false)
339 }
340
341 func (b *Float64Builder) UnsafeAppend(v float64) {
342 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
343 b.rawData[b.length] = v
344 b.length++
345 }
346
347 func (b *Float64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
348 if isValid {
349 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
350 } else {
351 b.nulls++
352 }
353 b.length++
354 }
355
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")
362 }
363
364 if len(v) == 0 {
365 return
366 }
367
368 b.Reserve(len(v))
369 arrow.Float64Traits.Copy(b.rawData[b.length:], v)
370 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
371 }
372
373 func (b *Float64Builder) init(capacity int) {
374 b.builder.init(capacity)
375
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())
380 }
381
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)
386 }
387
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) {
391 nBuilder := n
392 if n < minBuilderCapacity {
393 n = minBuilderCapacity
394 }
395
396 if b.capacity == 0 {
397 b.init(n)
398 } else {
399 b.builder.resize(nBuilder, b.init)
400 b.data.Resize(arrow.Float64Traits.BytesRequired(n))
401 b.rawData = arrow.Float64Traits.CastFromBytes(b.data.Bytes())
402 }
403 }
404
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()
409 }
410
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) {
414 data := b.newData()
415 a = NewFloat64Data(data)
416 data.Release()
417 return
418 }
419
420 func (b *Float64Builder) newData() (data *Data) {
421 bytesRequired := arrow.Float64Traits.BytesRequired(b.length)
422 if bytesRequired > 0 && bytesRequired < b.data.Len() {
423 // trim buffers
424 b.data.Resize(bytesRequired)
425 }
426 data = NewData(arrow.PrimitiveTypes.Float64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
427 b.reset()
428
429 if b.data != nil {
430 b.data.Release()
431 b.data = nil
432 b.rawData = nil
433 }
434
435 return
436 }
437
438 type Int32Builder struct {
439 builder
440
441 data *memory.Buffer
442 rawData []int32
443 }
444
445 func NewInt32Builder(mem memory.Allocator) *Int32Builder {
446 return &Int32Builder{builder: builder{refCount: 1, mem: mem}}
447 }
448
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")
453
454 if atomic.AddInt64(&b.refCount, -1) == 0 {
455 if b.nullBitmap != nil {
456 b.nullBitmap.Release()
457 b.nullBitmap = nil
458 }
459 if b.data != nil {
460 b.data.Release()
461 b.data = nil
462 b.rawData = nil
463 }
464 }
465 }
466
467 func (b *Int32Builder) Append(v int32) {
468 b.Reserve(1)
469 b.UnsafeAppend(v)
470 }
471
472 func (b *Int32Builder) AppendNull() {
473 b.Reserve(1)
474 b.UnsafeAppendBoolToBitmap(false)
475 }
476
477 func (b *Int32Builder) UnsafeAppend(v int32) {
478 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
479 b.rawData[b.length] = v
480 b.length++
481 }
482
483 func (b *Int32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
484 if isValid {
485 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
486 } else {
487 b.nulls++
488 }
489 b.length++
490 }
491
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")
498 }
499
500 if len(v) == 0 {
501 return
502 }
503
504 b.Reserve(len(v))
505 arrow.Int32Traits.Copy(b.rawData[b.length:], v)
506 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
507 }
508
509 func (b *Int32Builder) init(capacity int) {
510 b.builder.init(capacity)
511
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())
516 }
517
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)
522 }
523
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) {
527 nBuilder := n
528 if n < minBuilderCapacity {
529 n = minBuilderCapacity
530 }
531
532 if b.capacity == 0 {
533 b.init(n)
534 } else {
535 b.builder.resize(nBuilder, b.init)
536 b.data.Resize(arrow.Int32Traits.BytesRequired(n))
537 b.rawData = arrow.Int32Traits.CastFromBytes(b.data.Bytes())
538 }
539 }
540
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()
545 }
546
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) {
550 data := b.newData()
551 a = NewInt32Data(data)
552 data.Release()
553 return
554 }
555
556 func (b *Int32Builder) newData() (data *Data) {
557 bytesRequired := arrow.Int32Traits.BytesRequired(b.length)
558 if bytesRequired > 0 && bytesRequired < b.data.Len() {
559 // trim buffers
560 b.data.Resize(bytesRequired)
561 }
562 data = NewData(arrow.PrimitiveTypes.Int32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
563 b.reset()
564
565 if b.data != nil {
566 b.data.Release()
567 b.data = nil
568 b.rawData = nil
569 }
570
571 return
572 }
573
574 type Uint32Builder struct {
575 builder
576
577 data *memory.Buffer
578 rawData []uint32
579 }
580
581 func NewUint32Builder(mem memory.Allocator) *Uint32Builder {
582 return &Uint32Builder{builder: builder{refCount: 1, mem: mem}}
583 }
584
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")
589
590 if atomic.AddInt64(&b.refCount, -1) == 0 {
591 if b.nullBitmap != nil {
592 b.nullBitmap.Release()
593 b.nullBitmap = nil
594 }
595 if b.data != nil {
596 b.data.Release()
597 b.data = nil
598 b.rawData = nil
599 }
600 }
601 }
602
603 func (b *Uint32Builder) Append(v uint32) {
604 b.Reserve(1)
605 b.UnsafeAppend(v)
606 }
607
608 func (b *Uint32Builder) AppendNull() {
609 b.Reserve(1)
610 b.UnsafeAppendBoolToBitmap(false)
611 }
612
613 func (b *Uint32Builder) UnsafeAppend(v uint32) {
614 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
615 b.rawData[b.length] = v
616 b.length++
617 }
618
619 func (b *Uint32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
620 if isValid {
621 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
622 } else {
623 b.nulls++
624 }
625 b.length++
626 }
627
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")
634 }
635
636 if len(v) == 0 {
637 return
638 }
639
640 b.Reserve(len(v))
641 arrow.Uint32Traits.Copy(b.rawData[b.length:], v)
642 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
643 }
644
645 func (b *Uint32Builder) init(capacity int) {
646 b.builder.init(capacity)
647
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())
652 }
653
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)
658 }
659
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) {
663 nBuilder := n
664 if n < minBuilderCapacity {
665 n = minBuilderCapacity
666 }
667
668 if b.capacity == 0 {
669 b.init(n)
670 } else {
671 b.builder.resize(nBuilder, b.init)
672 b.data.Resize(arrow.Uint32Traits.BytesRequired(n))
673 b.rawData = arrow.Uint32Traits.CastFromBytes(b.data.Bytes())
674 }
675 }
676
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()
681 }
682
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) {
686 data := b.newData()
687 a = NewUint32Data(data)
688 data.Release()
689 return
690 }
691
692 func (b *Uint32Builder) newData() (data *Data) {
693 bytesRequired := arrow.Uint32Traits.BytesRequired(b.length)
694 if bytesRequired > 0 && bytesRequired < b.data.Len() {
695 // trim buffers
696 b.data.Resize(bytesRequired)
697 }
698 data = NewData(arrow.PrimitiveTypes.Uint32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
699 b.reset()
700
701 if b.data != nil {
702 b.data.Release()
703 b.data = nil
704 b.rawData = nil
705 }
706
707 return
708 }
709
710 type Float32Builder struct {
711 builder
712
713 data *memory.Buffer
714 rawData []float32
715 }
716
717 func NewFloat32Builder(mem memory.Allocator) *Float32Builder {
718 return &Float32Builder{builder: builder{refCount: 1, mem: mem}}
719 }
720
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")
725
726 if atomic.AddInt64(&b.refCount, -1) == 0 {
727 if b.nullBitmap != nil {
728 b.nullBitmap.Release()
729 b.nullBitmap = nil
730 }
731 if b.data != nil {
732 b.data.Release()
733 b.data = nil
734 b.rawData = nil
735 }
736 }
737 }
738
739 func (b *Float32Builder) Append(v float32) {
740 b.Reserve(1)
741 b.UnsafeAppend(v)
742 }
743
744 func (b *Float32Builder) AppendNull() {
745 b.Reserve(1)
746 b.UnsafeAppendBoolToBitmap(false)
747 }
748
749 func (b *Float32Builder) UnsafeAppend(v float32) {
750 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
751 b.rawData[b.length] = v
752 b.length++
753 }
754
755 func (b *Float32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
756 if isValid {
757 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
758 } else {
759 b.nulls++
760 }
761 b.length++
762 }
763
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")
770 }
771
772 if len(v) == 0 {
773 return
774 }
775
776 b.Reserve(len(v))
777 arrow.Float32Traits.Copy(b.rawData[b.length:], v)
778 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
779 }
780
781 func (b *Float32Builder) init(capacity int) {
782 b.builder.init(capacity)
783
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())
788 }
789
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)
794 }
795
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) {
799 nBuilder := n
800 if n < minBuilderCapacity {
801 n = minBuilderCapacity
802 }
803
804 if b.capacity == 0 {
805 b.init(n)
806 } else {
807 b.builder.resize(nBuilder, b.init)
808 b.data.Resize(arrow.Float32Traits.BytesRequired(n))
809 b.rawData = arrow.Float32Traits.CastFromBytes(b.data.Bytes())
810 }
811 }
812
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()
817 }
818
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) {
822 data := b.newData()
823 a = NewFloat32Data(data)
824 data.Release()
825 return
826 }
827
828 func (b *Float32Builder) newData() (data *Data) {
829 bytesRequired := arrow.Float32Traits.BytesRequired(b.length)
830 if bytesRequired > 0 && bytesRequired < b.data.Len() {
831 // trim buffers
832 b.data.Resize(bytesRequired)
833 }
834 data = NewData(arrow.PrimitiveTypes.Float32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
835 b.reset()
836
837 if b.data != nil {
838 b.data.Release()
839 b.data = nil
840 b.rawData = nil
841 }
842
843 return
844 }
845
846 type Int16Builder struct {
847 builder
848
849 data *memory.Buffer
850 rawData []int16
851 }
852
853 func NewInt16Builder(mem memory.Allocator) *Int16Builder {
854 return &Int16Builder{builder: builder{refCount: 1, mem: mem}}
855 }
856
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")
861
862 if atomic.AddInt64(&b.refCount, -1) == 0 {
863 if b.nullBitmap != nil {
864 b.nullBitmap.Release()
865 b.nullBitmap = nil
866 }
867 if b.data != nil {
868 b.data.Release()
869 b.data = nil
870 b.rawData = nil
871 }
872 }
873 }
874
875 func (b *Int16Builder) Append(v int16) {
876 b.Reserve(1)
877 b.UnsafeAppend(v)
878 }
879
880 func (b *Int16Builder) AppendNull() {
881 b.Reserve(1)
882 b.UnsafeAppendBoolToBitmap(false)
883 }
884
885 func (b *Int16Builder) UnsafeAppend(v int16) {
886 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
887 b.rawData[b.length] = v
888 b.length++
889 }
890
891 func (b *Int16Builder) UnsafeAppendBoolToBitmap(isValid bool) {
892 if isValid {
893 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
894 } else {
895 b.nulls++
896 }
897 b.length++
898 }
899
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")
906 }
907
908 if len(v) == 0 {
909 return
910 }
911
912 b.Reserve(len(v))
913 arrow.Int16Traits.Copy(b.rawData[b.length:], v)
914 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
915 }
916
917 func (b *Int16Builder) init(capacity int) {
918 b.builder.init(capacity)
919
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())
924 }
925
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)
930 }
931
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) {
935 nBuilder := n
936 if n < minBuilderCapacity {
937 n = minBuilderCapacity
938 }
939
940 if b.capacity == 0 {
941 b.init(n)
942 } else {
943 b.builder.resize(nBuilder, b.init)
944 b.data.Resize(arrow.Int16Traits.BytesRequired(n))
945 b.rawData = arrow.Int16Traits.CastFromBytes(b.data.Bytes())
946 }
947 }
948
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()
953 }
954
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) {
958 data := b.newData()
959 a = NewInt16Data(data)
960 data.Release()
961 return
962 }
963
964 func (b *Int16Builder) newData() (data *Data) {
965 bytesRequired := arrow.Int16Traits.BytesRequired(b.length)
966 if bytesRequired > 0 && bytesRequired < b.data.Len() {
967 // trim buffers
968 b.data.Resize(bytesRequired)
969 }
970 data = NewData(arrow.PrimitiveTypes.Int16, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
971 b.reset()
972
973 if b.data != nil {
974 b.data.Release()
975 b.data = nil
976 b.rawData = nil
977 }
978
979 return
980 }
981
982 type Uint16Builder struct {
983 builder
984
985 data *memory.Buffer
986 rawData []uint16
987 }
988
989 func NewUint16Builder(mem memory.Allocator) *Uint16Builder {
990 return &Uint16Builder{builder: builder{refCount: 1, mem: mem}}
991 }
992
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")
997
998 if atomic.AddInt64(&b.refCount, -1) == 0 {
999 if b.nullBitmap != nil {
1000 b.nullBitmap.Release()
1001 b.nullBitmap = nil
1002 }
1003 if b.data != nil {
1004 b.data.Release()
1005 b.data = nil
1006 b.rawData = nil
1007 }
1008 }
1009 }
1010
1011 func (b *Uint16Builder) Append(v uint16) {
1012 b.Reserve(1)
1013 b.UnsafeAppend(v)
1014 }
1015
1016 func (b *Uint16Builder) AppendNull() {
1017 b.Reserve(1)
1018 b.UnsafeAppendBoolToBitmap(false)
1019 }
1020
1021 func (b *Uint16Builder) UnsafeAppend(v uint16) {
1022 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1023 b.rawData[b.length] = v
1024 b.length++
1025 }
1026
1027 func (b *Uint16Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1028 if isValid {
1029 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1030 } else {
1031 b.nulls++
1032 }
1033 b.length++
1034 }
1035
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")
1042 }
1043
1044 if len(v) == 0 {
1045 return
1046 }
1047
1048 b.Reserve(len(v))
1049 arrow.Uint16Traits.Copy(b.rawData[b.length:], v)
1050 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1051 }
1052
1053 func (b *Uint16Builder) init(capacity int) {
1054 b.builder.init(capacity)
1055
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())
1060 }
1061
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)
1066 }
1067
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) {
1071 nBuilder := n
1072 if n < minBuilderCapacity {
1073 n = minBuilderCapacity
1074 }
1075
1076 if b.capacity == 0 {
1077 b.init(n)
1078 } else {
1079 b.builder.resize(nBuilder, b.init)
1080 b.data.Resize(arrow.Uint16Traits.BytesRequired(n))
1081 b.rawData = arrow.Uint16Traits.CastFromBytes(b.data.Bytes())
1082 }
1083 }
1084
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()
1089 }
1090
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) {
1094 data := b.newData()
1095 a = NewUint16Data(data)
1096 data.Release()
1097 return
1098 }
1099
1100 func (b *Uint16Builder) newData() (data *Data) {
1101 bytesRequired := arrow.Uint16Traits.BytesRequired(b.length)
1102 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1103 // trim buffers
1104 b.data.Resize(bytesRequired)
1105 }
1106 data = NewData(arrow.PrimitiveTypes.Uint16, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1107 b.reset()
1108
1109 if b.data != nil {
1110 b.data.Release()
1111 b.data = nil
1112 b.rawData = nil
1113 }
1114
1115 return
1116 }
1117
1118 type Int8Builder struct {
1119 builder
1120
1121 data *memory.Buffer
1122 rawData []int8
1123 }
1124
1125 func NewInt8Builder(mem memory.Allocator) *Int8Builder {
1126 return &Int8Builder{builder: builder{refCount: 1, mem: mem}}
1127 }
1128
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")
1133
1134 if atomic.AddInt64(&b.refCount, -1) == 0 {
1135 if b.nullBitmap != nil {
1136 b.nullBitmap.Release()
1137 b.nullBitmap = nil
1138 }
1139 if b.data != nil {
1140 b.data.Release()
1141 b.data = nil
1142 b.rawData = nil
1143 }
1144 }
1145 }
1146
1147 func (b *Int8Builder) Append(v int8) {
1148 b.Reserve(1)
1149 b.UnsafeAppend(v)
1150 }
1151
1152 func (b *Int8Builder) AppendNull() {
1153 b.Reserve(1)
1154 b.UnsafeAppendBoolToBitmap(false)
1155 }
1156
1157 func (b *Int8Builder) UnsafeAppend(v int8) {
1158 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1159 b.rawData[b.length] = v
1160 b.length++
1161 }
1162
1163 func (b *Int8Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1164 if isValid {
1165 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1166 } else {
1167 b.nulls++
1168 }
1169 b.length++
1170 }
1171
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")
1178 }
1179
1180 if len(v) == 0 {
1181 return
1182 }
1183
1184 b.Reserve(len(v))
1185 arrow.Int8Traits.Copy(b.rawData[b.length:], v)
1186 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1187 }
1188
1189 func (b *Int8Builder) init(capacity int) {
1190 b.builder.init(capacity)
1191
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())
1196 }
1197
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)
1202 }
1203
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) {
1207 nBuilder := n
1208 if n < minBuilderCapacity {
1209 n = minBuilderCapacity
1210 }
1211
1212 if b.capacity == 0 {
1213 b.init(n)
1214 } else {
1215 b.builder.resize(nBuilder, b.init)
1216 b.data.Resize(arrow.Int8Traits.BytesRequired(n))
1217 b.rawData = arrow.Int8Traits.CastFromBytes(b.data.Bytes())
1218 }
1219 }
1220
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()
1225 }
1226
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) {
1230 data := b.newData()
1231 a = NewInt8Data(data)
1232 data.Release()
1233 return
1234 }
1235
1236 func (b *Int8Builder) newData() (data *Data) {
1237 bytesRequired := arrow.Int8Traits.BytesRequired(b.length)
1238 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1239 // trim buffers
1240 b.data.Resize(bytesRequired)
1241 }
1242 data = NewData(arrow.PrimitiveTypes.Int8, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1243 b.reset()
1244
1245 if b.data != nil {
1246 b.data.Release()
1247 b.data = nil
1248 b.rawData = nil
1249 }
1250
1251 return
1252 }
1253
1254 type Uint8Builder struct {
1255 builder
1256
1257 data *memory.Buffer
1258 rawData []uint8
1259 }
1260
1261 func NewUint8Builder(mem memory.Allocator) *Uint8Builder {
1262 return &Uint8Builder{builder: builder{refCount: 1, mem: mem}}
1263 }
1264
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")
1269
1270 if atomic.AddInt64(&b.refCount, -1) == 0 {
1271 if b.nullBitmap != nil {
1272 b.nullBitmap.Release()
1273 b.nullBitmap = nil
1274 }
1275 if b.data != nil {
1276 b.data.Release()
1277 b.data = nil
1278 b.rawData = nil
1279 }
1280 }
1281 }
1282
1283 func (b *Uint8Builder) Append(v uint8) {
1284 b.Reserve(1)
1285 b.UnsafeAppend(v)
1286 }
1287
1288 func (b *Uint8Builder) AppendNull() {
1289 b.Reserve(1)
1290 b.UnsafeAppendBoolToBitmap(false)
1291 }
1292
1293 func (b *Uint8Builder) UnsafeAppend(v uint8) {
1294 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1295 b.rawData[b.length] = v
1296 b.length++
1297 }
1298
1299 func (b *Uint8Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1300 if isValid {
1301 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1302 } else {
1303 b.nulls++
1304 }
1305 b.length++
1306 }
1307
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")
1314 }
1315
1316 if len(v) == 0 {
1317 return
1318 }
1319
1320 b.Reserve(len(v))
1321 arrow.Uint8Traits.Copy(b.rawData[b.length:], v)
1322 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1323 }
1324
1325 func (b *Uint8Builder) init(capacity int) {
1326 b.builder.init(capacity)
1327
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())
1332 }
1333
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)
1338 }
1339
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) {
1343 nBuilder := n
1344 if n < minBuilderCapacity {
1345 n = minBuilderCapacity
1346 }
1347
1348 if b.capacity == 0 {
1349 b.init(n)
1350 } else {
1351 b.builder.resize(nBuilder, b.init)
1352 b.data.Resize(arrow.Uint8Traits.BytesRequired(n))
1353 b.rawData = arrow.Uint8Traits.CastFromBytes(b.data.Bytes())
1354 }
1355 }
1356
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()
1361 }
1362
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) {
1366 data := b.newData()
1367 a = NewUint8Data(data)
1368 data.Release()
1369 return
1370 }
1371
1372 func (b *Uint8Builder) newData() (data *Data) {
1373 bytesRequired := arrow.Uint8Traits.BytesRequired(b.length)
1374 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1375 // trim buffers
1376 b.data.Resize(bytesRequired)
1377 }
1378 data = NewData(arrow.PrimitiveTypes.Uint8, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1379 b.reset()
1380
1381 if b.data != nil {
1382 b.data.Release()
1383 b.data = nil
1384 b.rawData = nil
1385 }
1386
1387 return
1388 }
1389
1390 type TimestampBuilder struct {
1391 builder
1392
1393 dtype *arrow.TimestampType
1394 data *memory.Buffer
1395 rawData []arrow.Timestamp
1396 }
1397
1398 func NewTimestampBuilder(mem memory.Allocator, dtype *arrow.TimestampType) *TimestampBuilder {
1399 return &TimestampBuilder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1400 }
1401
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")
1406
1407 if atomic.AddInt64(&b.refCount, -1) == 0 {
1408 if b.nullBitmap != nil {
1409 b.nullBitmap.Release()
1410 b.nullBitmap = nil
1411 }
1412 if b.data != nil {
1413 b.data.Release()
1414 b.data = nil
1415 b.rawData = nil
1416 }
1417 }
1418 }
1419
1420 func (b *TimestampBuilder) Append(v arrow.Timestamp) {
1421 b.Reserve(1)
1422 b.UnsafeAppend(v)
1423 }
1424
1425 func (b *TimestampBuilder) AppendNull() {
1426 b.Reserve(1)
1427 b.UnsafeAppendBoolToBitmap(false)
1428 }
1429
1430 func (b *TimestampBuilder) UnsafeAppend(v arrow.Timestamp) {
1431 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1432 b.rawData[b.length] = v
1433 b.length++
1434 }
1435
1436 func (b *TimestampBuilder) UnsafeAppendBoolToBitmap(isValid bool) {
1437 if isValid {
1438 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1439 } else {
1440 b.nulls++
1441 }
1442 b.length++
1443 }
1444
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")
1451 }
1452
1453 if len(v) == 0 {
1454 return
1455 }
1456
1457 b.Reserve(len(v))
1458 arrow.TimestampTraits.Copy(b.rawData[b.length:], v)
1459 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1460 }
1461
1462 func (b *TimestampBuilder) init(capacity int) {
1463 b.builder.init(capacity)
1464
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())
1469 }
1470
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)
1475 }
1476
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) {
1480 nBuilder := n
1481 if n < minBuilderCapacity {
1482 n = minBuilderCapacity
1483 }
1484
1485 if b.capacity == 0 {
1486 b.init(n)
1487 } else {
1488 b.builder.resize(nBuilder, b.init)
1489 b.data.Resize(arrow.TimestampTraits.BytesRequired(n))
1490 b.rawData = arrow.TimestampTraits.CastFromBytes(b.data.Bytes())
1491 }
1492 }
1493
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()
1498 }
1499
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) {
1503 data := b.newData()
1504 a = NewTimestampData(data)
1505 data.Release()
1506 return
1507 }
1508
1509 func (b *TimestampBuilder) newData() (data *Data) {
1510 bytesRequired := arrow.TimestampTraits.BytesRequired(b.length)
1511 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1512 // trim buffers
1513 b.data.Resize(bytesRequired)
1514 }
1515 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1516 b.reset()
1517
1518 if b.data != nil {
1519 b.data.Release()
1520 b.data = nil
1521 b.rawData = nil
1522 }
1523
1524 return
1525 }
1526
1527 type Time32Builder struct {
1528 builder
1529
1530 dtype *arrow.Time32Type
1531 data *memory.Buffer
1532 rawData []arrow.Time32
1533 }
1534
1535 func NewTime32Builder(mem memory.Allocator, dtype *arrow.Time32Type) *Time32Builder {
1536 return &Time32Builder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1537 }
1538
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")
1543
1544 if atomic.AddInt64(&b.refCount, -1) == 0 {
1545 if b.nullBitmap != nil {
1546 b.nullBitmap.Release()
1547 b.nullBitmap = nil
1548 }
1549 if b.data != nil {
1550 b.data.Release()
1551 b.data = nil
1552 b.rawData = nil
1553 }
1554 }
1555 }
1556
1557 func (b *Time32Builder) Append(v arrow.Time32) {
1558 b.Reserve(1)
1559 b.UnsafeAppend(v)
1560 }
1561
1562 func (b *Time32Builder) AppendNull() {
1563 b.Reserve(1)
1564 b.UnsafeAppendBoolToBitmap(false)
1565 }
1566
1567 func (b *Time32Builder) UnsafeAppend(v arrow.Time32) {
1568 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1569 b.rawData[b.length] = v
1570 b.length++
1571 }
1572
1573 func (b *Time32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1574 if isValid {
1575 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1576 } else {
1577 b.nulls++
1578 }
1579 b.length++
1580 }
1581
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")
1588 }
1589
1590 if len(v) == 0 {
1591 return
1592 }
1593
1594 b.Reserve(len(v))
1595 arrow.Time32Traits.Copy(b.rawData[b.length:], v)
1596 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1597 }
1598
1599 func (b *Time32Builder) init(capacity int) {
1600 b.builder.init(capacity)
1601
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())
1606 }
1607
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)
1612 }
1613
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) {
1617 nBuilder := n
1618 if n < minBuilderCapacity {
1619 n = minBuilderCapacity
1620 }
1621
1622 if b.capacity == 0 {
1623 b.init(n)
1624 } else {
1625 b.builder.resize(nBuilder, b.init)
1626 b.data.Resize(arrow.Time32Traits.BytesRequired(n))
1627 b.rawData = arrow.Time32Traits.CastFromBytes(b.data.Bytes())
1628 }
1629 }
1630
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()
1635 }
1636
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) {
1640 data := b.newData()
1641 a = NewTime32Data(data)
1642 data.Release()
1643 return
1644 }
1645
1646 func (b *Time32Builder) newData() (data *Data) {
1647 bytesRequired := arrow.Time32Traits.BytesRequired(b.length)
1648 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1649 // trim buffers
1650 b.data.Resize(bytesRequired)
1651 }
1652 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1653 b.reset()
1654
1655 if b.data != nil {
1656 b.data.Release()
1657 b.data = nil
1658 b.rawData = nil
1659 }
1660
1661 return
1662 }
1663
1664 type Time64Builder struct {
1665 builder
1666
1667 dtype *arrow.Time64Type
1668 data *memory.Buffer
1669 rawData []arrow.Time64
1670 }
1671
1672 func NewTime64Builder(mem memory.Allocator, dtype *arrow.Time64Type) *Time64Builder {
1673 return &Time64Builder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
1674 }
1675
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")
1680
1681 if atomic.AddInt64(&b.refCount, -1) == 0 {
1682 if b.nullBitmap != nil {
1683 b.nullBitmap.Release()
1684 b.nullBitmap = nil
1685 }
1686 if b.data != nil {
1687 b.data.Release()
1688 b.data = nil
1689 b.rawData = nil
1690 }
1691 }
1692 }
1693
1694 func (b *Time64Builder) Append(v arrow.Time64) {
1695 b.Reserve(1)
1696 b.UnsafeAppend(v)
1697 }
1698
1699 func (b *Time64Builder) AppendNull() {
1700 b.Reserve(1)
1701 b.UnsafeAppendBoolToBitmap(false)
1702 }
1703
1704 func (b *Time64Builder) UnsafeAppend(v arrow.Time64) {
1705 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1706 b.rawData[b.length] = v
1707 b.length++
1708 }
1709
1710 func (b *Time64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1711 if isValid {
1712 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1713 } else {
1714 b.nulls++
1715 }
1716 b.length++
1717 }
1718
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")
1725 }
1726
1727 if len(v) == 0 {
1728 return
1729 }
1730
1731 b.Reserve(len(v))
1732 arrow.Time64Traits.Copy(b.rawData[b.length:], v)
1733 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1734 }
1735
1736 func (b *Time64Builder) init(capacity int) {
1737 b.builder.init(capacity)
1738
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())
1743 }
1744
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)
1749 }
1750
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) {
1754 nBuilder := n
1755 if n < minBuilderCapacity {
1756 n = minBuilderCapacity
1757 }
1758
1759 if b.capacity == 0 {
1760 b.init(n)
1761 } else {
1762 b.builder.resize(nBuilder, b.init)
1763 b.data.Resize(arrow.Time64Traits.BytesRequired(n))
1764 b.rawData = arrow.Time64Traits.CastFromBytes(b.data.Bytes())
1765 }
1766 }
1767
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()
1772 }
1773
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) {
1777 data := b.newData()
1778 a = NewTime64Data(data)
1779 data.Release()
1780 return
1781 }
1782
1783 func (b *Time64Builder) newData() (data *Data) {
1784 bytesRequired := arrow.Time64Traits.BytesRequired(b.length)
1785 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1786 // trim buffers
1787 b.data.Resize(bytesRequired)
1788 }
1789 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1790 b.reset()
1791
1792 if b.data != nil {
1793 b.data.Release()
1794 b.data = nil
1795 b.rawData = nil
1796 }
1797
1798 return
1799 }
1800
1801 type Date32Builder struct {
1802 builder
1803
1804 data *memory.Buffer
1805 rawData []arrow.Date32
1806 }
1807
1808 func NewDate32Builder(mem memory.Allocator) *Date32Builder {
1809 return &Date32Builder{builder: builder{refCount: 1, mem: mem}}
1810 }
1811
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")
1816
1817 if atomic.AddInt64(&b.refCount, -1) == 0 {
1818 if b.nullBitmap != nil {
1819 b.nullBitmap.Release()
1820 b.nullBitmap = nil
1821 }
1822 if b.data != nil {
1823 b.data.Release()
1824 b.data = nil
1825 b.rawData = nil
1826 }
1827 }
1828 }
1829
1830 func (b *Date32Builder) Append(v arrow.Date32) {
1831 b.Reserve(1)
1832 b.UnsafeAppend(v)
1833 }
1834
1835 func (b *Date32Builder) AppendNull() {
1836 b.Reserve(1)
1837 b.UnsafeAppendBoolToBitmap(false)
1838 }
1839
1840 func (b *Date32Builder) UnsafeAppend(v arrow.Date32) {
1841 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1842 b.rawData[b.length] = v
1843 b.length++
1844 }
1845
1846 func (b *Date32Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1847 if isValid {
1848 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1849 } else {
1850 b.nulls++
1851 }
1852 b.length++
1853 }
1854
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")
1861 }
1862
1863 if len(v) == 0 {
1864 return
1865 }
1866
1867 b.Reserve(len(v))
1868 arrow.Date32Traits.Copy(b.rawData[b.length:], v)
1869 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
1870 }
1871
1872 func (b *Date32Builder) init(capacity int) {
1873 b.builder.init(capacity)
1874
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())
1879 }
1880
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)
1885 }
1886
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) {
1890 nBuilder := n
1891 if n < minBuilderCapacity {
1892 n = minBuilderCapacity
1893 }
1894
1895 if b.capacity == 0 {
1896 b.init(n)
1897 } else {
1898 b.builder.resize(nBuilder, b.init)
1899 b.data.Resize(arrow.Date32Traits.BytesRequired(n))
1900 b.rawData = arrow.Date32Traits.CastFromBytes(b.data.Bytes())
1901 }
1902 }
1903
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()
1908 }
1909
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) {
1913 data := b.newData()
1914 a = NewDate32Data(data)
1915 data.Release()
1916 return
1917 }
1918
1919 func (b *Date32Builder) newData() (data *Data) {
1920 bytesRequired := arrow.Date32Traits.BytesRequired(b.length)
1921 if bytesRequired > 0 && bytesRequired < b.data.Len() {
1922 // trim buffers
1923 b.data.Resize(bytesRequired)
1924 }
1925 data = NewData(arrow.PrimitiveTypes.Date32, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
1926 b.reset()
1927
1928 if b.data != nil {
1929 b.data.Release()
1930 b.data = nil
1931 b.rawData = nil
1932 }
1933
1934 return
1935 }
1936
1937 type Date64Builder struct {
1938 builder
1939
1940 data *memory.Buffer
1941 rawData []arrow.Date64
1942 }
1943
1944 func NewDate64Builder(mem memory.Allocator) *Date64Builder {
1945 return &Date64Builder{builder: builder{refCount: 1, mem: mem}}
1946 }
1947
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")
1952
1953 if atomic.AddInt64(&b.refCount, -1) == 0 {
1954 if b.nullBitmap != nil {
1955 b.nullBitmap.Release()
1956 b.nullBitmap = nil
1957 }
1958 if b.data != nil {
1959 b.data.Release()
1960 b.data = nil
1961 b.rawData = nil
1962 }
1963 }
1964 }
1965
1966 func (b *Date64Builder) Append(v arrow.Date64) {
1967 b.Reserve(1)
1968 b.UnsafeAppend(v)
1969 }
1970
1971 func (b *Date64Builder) AppendNull() {
1972 b.Reserve(1)
1973 b.UnsafeAppendBoolToBitmap(false)
1974 }
1975
1976 func (b *Date64Builder) UnsafeAppend(v arrow.Date64) {
1977 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1978 b.rawData[b.length] = v
1979 b.length++
1980 }
1981
1982 func (b *Date64Builder) UnsafeAppendBoolToBitmap(isValid bool) {
1983 if isValid {
1984 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
1985 } else {
1986 b.nulls++
1987 }
1988 b.length++
1989 }
1990
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")
1997 }
1998
1999 if len(v) == 0 {
2000 return
2001 }
2002
2003 b.Reserve(len(v))
2004 arrow.Date64Traits.Copy(b.rawData[b.length:], v)
2005 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
2006 }
2007
2008 func (b *Date64Builder) init(capacity int) {
2009 b.builder.init(capacity)
2010
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())
2015 }
2016
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)
2021 }
2022
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) {
2026 nBuilder := n
2027 if n < minBuilderCapacity {
2028 n = minBuilderCapacity
2029 }
2030
2031 if b.capacity == 0 {
2032 b.init(n)
2033 } else {
2034 b.builder.resize(nBuilder, b.init)
2035 b.data.Resize(arrow.Date64Traits.BytesRequired(n))
2036 b.rawData = arrow.Date64Traits.CastFromBytes(b.data.Bytes())
2037 }
2038 }
2039
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()
2044 }
2045
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) {
2049 data := b.newData()
2050 a = NewDate64Data(data)
2051 data.Release()
2052 return
2053 }
2054
2055 func (b *Date64Builder) newData() (data *Data) {
2056 bytesRequired := arrow.Date64Traits.BytesRequired(b.length)
2057 if bytesRequired > 0 && bytesRequired < b.data.Len() {
2058 // trim buffers
2059 b.data.Resize(bytesRequired)
2060 }
2061 data = NewData(arrow.PrimitiveTypes.Date64, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
2062 b.reset()
2063
2064 if b.data != nil {
2065 b.data.Release()
2066 b.data = nil
2067 b.rawData = nil
2068 }
2069
2070 return
2071 }
2072
2073 type DurationBuilder struct {
2074 builder
2075
2076 dtype *arrow.DurationType
2077 data *memory.Buffer
2078 rawData []arrow.Duration
2079 }
2080
2081 func NewDurationBuilder(mem memory.Allocator, dtype *arrow.DurationType) *DurationBuilder {
2082 return &DurationBuilder{builder: builder{refCount: 1, mem: mem}, dtype: dtype}
2083 }
2084
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")
2089
2090 if atomic.AddInt64(&b.refCount, -1) == 0 {
2091 if b.nullBitmap != nil {
2092 b.nullBitmap.Release()
2093 b.nullBitmap = nil
2094 }
2095 if b.data != nil {
2096 b.data.Release()
2097 b.data = nil
2098 b.rawData = nil
2099 }
2100 }
2101 }
2102
2103 func (b *DurationBuilder) Append(v arrow.Duration) {
2104 b.Reserve(1)
2105 b.UnsafeAppend(v)
2106 }
2107
2108 func (b *DurationBuilder) AppendNull() {
2109 b.Reserve(1)
2110 b.UnsafeAppendBoolToBitmap(false)
2111 }
2112
2113 func (b *DurationBuilder) UnsafeAppend(v arrow.Duration) {
2114 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
2115 b.rawData[b.length] = v
2116 b.length++
2117 }
2118
2119 func (b *DurationBuilder) UnsafeAppendBoolToBitmap(isValid bool) {
2120 if isValid {
2121 bitutil.SetBit(b.nullBitmap.Bytes(), b.length)
2122 } else {
2123 b.nulls++
2124 }
2125 b.length++
2126 }
2127
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")
2134 }
2135
2136 if len(v) == 0 {
2137 return
2138 }
2139
2140 b.Reserve(len(v))
2141 arrow.DurationTraits.Copy(b.rawData[b.length:], v)
2142 b.builder.unsafeAppendBoolsToBitmap(valid, len(v))
2143 }
2144
2145 func (b *DurationBuilder) init(capacity int) {
2146 b.builder.init(capacity)
2147
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())
2152 }
2153
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)
2158 }
2159
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) {
2163 nBuilder := n
2164 if n < minBuilderCapacity {
2165 n = minBuilderCapacity
2166 }
2167
2168 if b.capacity == 0 {
2169 b.init(n)
2170 } else {
2171 b.builder.resize(nBuilder, b.init)
2172 b.data.Resize(arrow.DurationTraits.BytesRequired(n))
2173 b.rawData = arrow.DurationTraits.CastFromBytes(b.data.Bytes())
2174 }
2175 }
2176
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()
2181 }
2182
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) {
2186 data := b.newData()
2187 a = NewDurationData(data)
2188 data.Release()
2189 return
2190 }
2191
2192 func (b *DurationBuilder) newData() (data *Data) {
2193 bytesRequired := arrow.DurationTraits.BytesRequired(b.length)
2194 if bytesRequired > 0 && bytesRequired < b.data.Len() {
2195 // trim buffers
2196 b.data.Resize(bytesRequired)
2197 }
2198 data = NewData(b.dtype, b.length, []*memory.Buffer{b.nullBitmap, b.data}, nil, b.nulls, 0)
2199 b.reset()
2200
2201 if b.data != nil {
2202 b.data.Release()
2203 b.data = nil
2204 b.rawData = nil
2205 }
2206
2207 return
2208 }
2209
2210 var (
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)
2227 )