-
Notifications
You must be signed in to change notification settings - Fork 153
/
table.go
2157 lines (1928 loc) · 50.8 KB
/
table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package execute
import (
"fmt"
"sort"
"sync/atomic"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/flux"
"github.com/influxdata/flux/array"
"github.com/influxdata/flux/arrow"
"github.com/influxdata/flux/codes"
"github.com/influxdata/flux/internal/errors"
"github.com/influxdata/flux/internal/execute/table"
"github.com/influxdata/flux/memory"
"github.com/influxdata/flux/plan"
"github.com/influxdata/flux/semantic"
"github.com/influxdata/flux/values"
)
const (
DefaultStartColLabel = "_start"
DefaultStopColLabel = "_stop"
DefaultTimeColLabel = "_time"
DefaultValueColLabel = "_value"
)
func GroupKeyForRowOn(i int, cr flux.ColReader, on map[string]bool) flux.GroupKey {
cols := make([]flux.ColMeta, 0, len(on))
vs := make([]values.Value, 0, len(on))
for j, c := range cr.Cols() {
if !on[c.Label] {
continue
}
cols = append(cols, c)
vs = append(vs, ValueForRow(cr, i, j))
}
return NewGroupKey(cols, vs)
}
// CopyTable returns a buffered copy of the table and consumes the
// input table. If the input table is already buffered, it "consumes"
// the input and returns the same table.
//
// The buffered table can then be copied additional times using the
// BufferedTable.Copy method.
//
// This method should be used sparingly if at all. It will retain
// each of the buffers of data coming out of a table so the entire
// table is materialized in memory. For large datasets, this could
// potentially cause a problem. The allocator is meant to catch when
// this happens and prevent it.
func CopyTable(t flux.Table) (flux.BufferedTable, error) {
return table.Copy(t)
}
// AddTableCols adds the columns of b onto builder.
func AddTableCols(t flux.Table, builder TableBuilder) error {
cols := t.Cols()
for _, c := range cols {
if _, err := builder.AddCol(c); err != nil {
return err
}
}
return nil
}
func AddTableKeyCols(key flux.GroupKey, builder TableBuilder) error {
for _, c := range key.Cols() {
if _, err := builder.AddCol(c); err != nil {
return err
}
}
return nil
}
// AddNewCols adds the columns of b onto builder that did not already exist.
// Returns the mapping of builder cols to table cols.
func AddNewTableCols(t flux.Table, builder TableBuilder, colMap []int) ([]int, error) {
cols := t.Cols()
existing := builder.Cols()
if l := len(builder.Cols()); cap(colMap) < l {
colMap = make([]int, len(builder.Cols()))
} else {
colMap = colMap[:l]
}
for j := range colMap {
colMap[j] = -1
}
for j, c := range cols {
found := false
for ej, ec := range existing {
if c.Label == ec.Label {
if c.Type == ec.Type {
colMap[ej] = j
found = true
break
} else {
return nil, fmt.Errorf("schema collision detected: column \"%s\" is both of type %s and %s", c.Label, c.Type, ec.Type)
}
}
}
if !found {
if _, err := builder.AddCol(c); err != nil {
return nil, err
}
colMap = append(colMap, j)
}
}
return colMap, nil
}
// AppendMappedTable appends data from table t onto builder.
// The colMap is a map of builder column index to table column index.
func AppendMappedTable(t flux.Table, builder TableBuilder, colMap []int) error {
if len(t.Cols()) == 0 {
return nil
}
if err := t.Do(func(cr flux.ColReader) error {
return AppendMappedCols(cr, builder, colMap)
}); err != nil {
return err
}
return builder.LevelColumns()
}
// AppendTable appends data from table t onto builder.
// This function assumes builder and t have the same column schema.
func AppendTable(t flux.Table, builder TableBuilder) error {
if len(t.Cols()) == 0 {
return nil
}
return t.Do(func(cr flux.ColReader) error {
return AppendCols(cr, builder)
})
}
// AppendMappedCols appends all columns from cr onto builder.
// The colMap is a map of builder column index to cr column index.
func AppendMappedCols(cr flux.ColReader, builder TableBuilder, colMap []int) error {
if len(colMap) != len(builder.Cols()) {
return errors.New(codes.Internal, "AppendMappedCols: colMap must have an entry for each table builder column")
}
for j := range builder.Cols() {
if colMap[j] >= 0 {
if err := AppendCol(j, colMap[j], cr, builder); err != nil {
return err
}
}
}
return nil
}
// AppendCols appends all columns from cr onto builder.
// This function assumes that builder and cr have the same column schema.
func AppendCols(cr flux.ColReader, builder TableBuilder) error {
for j := range builder.Cols() {
if err := AppendCol(j, j, cr, builder); err != nil {
return err
}
}
return nil
}
// AppendCol append a column from cr onto builder
// The indexes bj and cj are builder and col reader indexes respectively.
func AppendCol(bj, cj int, cr flux.ColReader, builder TableBuilder) error {
if cj < 0 || cj > len(cr.Cols()) {
return errors.New(codes.Internal, "AppendCol column reader index out of bounds")
}
if bj < 0 || bj > len(builder.Cols()) {
return errors.New(codes.Internal, "AppendCol builder index out of bounds")
}
c := cr.Cols()[cj]
switch c.Type {
case flux.TBool:
return builder.AppendBools(bj, cr.Bools(cj))
case flux.TInt:
return builder.AppendInts(bj, cr.Ints(cj))
case flux.TUInt:
return builder.AppendUInts(bj, cr.UInts(cj))
case flux.TFloat:
return builder.AppendFloats(bj, cr.Floats(cj))
case flux.TString:
return builder.AppendStrings(bj, cr.Strings(cj))
case flux.TTime:
return builder.AppendTimes(bj, cr.Times(cj))
default:
PanicUnknownType(c.Type)
}
return nil
}
// AppendRecord appends the record from cr onto builder assuming matching columns.
func AppendRecord(i int, cr flux.ColReader, builder TableBuilder) error {
if !BuilderColsMatchReader(builder, cr) {
return errors.New(codes.Internal, "AppendRecord column schema mismatch")
}
for j := range builder.Cols() {
if err := builder.AppendValue(j, ValueForRow(cr, i, j)); err != nil {
return err
}
}
return nil
}
// AppendMappedRecordWithNulls appends the records from cr onto builder, using colMap as a map of builder index to cr index.
// if an entry in the colMap indicates a mismatched column, the column is created with null values
func AppendMappedRecordWithNulls(i int, cr flux.ColReader, builder TableBuilder, colMap []int) error {
if len(colMap) != len(builder.Cols()) {
return errors.New(codes.Internal, "AppendMappedRecordWithNulls: colMap must have an entry for each table builder column")
}
for j := range builder.Cols() {
var val values.Value
if colMap[j] >= 0 {
val = ValueForRow(cr, i, colMap[j])
if err := builder.AppendValue(j, val); err != nil {
return err
}
} else {
if err := builder.AppendNil(j); err != nil {
return err
}
}
}
return nil
}
// AppendMappedRecordExplicit appends the records from cr onto builder, using colMap as a map of builder index to cr index.
// if an entry in the colMap indicates a mismatched column, no value is appended.
func AppendMappedRecordExplicit(i int, cr flux.ColReader, builder TableBuilder, colMap []int) error {
for j := range builder.Cols() {
if colMap[j] < 0 {
continue
}
if err := builder.AppendValue(j, ValueForRow(cr, i, j)); err != nil {
return err
}
}
return nil
}
// BuilderColsMatchReader returns true if builder and cr have identical column sets (order dependent)
func BuilderColsMatchReader(builder TableBuilder, cr flux.ColReader) bool {
return colsMatch(builder.Cols(), cr.Cols())
}
// TablesEqual takes two flux tables and compares them. Returns false if the tables have different keys, different
// columns, or if the data in any column does not match. Returns true otherwise. This function will consume the
// ColumnReader so if you are calling this from the a Process method, you may need to copy the table if you need to
// iterate over the data for other calculations.
func TablesEqual(left, right flux.Table, alloc memory.Allocator) (bool, error) {
if colsMatch(left.Key().Cols(), right.Key().Cols()) && colsMatch(left.Cols(), right.Cols()) {
eq := true
// rbuffer will buffer out rows from the right table, always holding just enough to do a comparison with the left
// table's ColReader
leftBuffer := NewColListTableBuilder(left.Key(), alloc)
if err := AddTableCols(left, leftBuffer); err != nil {
return false, err
}
if err := AppendTable(left, leftBuffer); err != nil {
return false, err
}
rightBuffer := NewColListTableBuilder(right.Key(), alloc)
if err := AddTableCols(right, rightBuffer); err != nil {
return false, err
}
if err := AppendTable(right, rightBuffer); err != nil {
return false, err
}
if leftBuffer.NRows() != rightBuffer.NRows() {
return false, nil
}
for j, c := range leftBuffer.Cols() {
switch c.Type {
case flux.TBool:
eq = cmp.Equal(leftBuffer.cols[j].(*boolColumnBuilder).data,
rightBuffer.cols[j].(*boolColumnBuilder).data)
case flux.TInt:
eq = cmp.Equal(leftBuffer.cols[j].(*intColumnBuilder).data,
rightBuffer.cols[j].(*intColumnBuilder).data)
case flux.TUInt:
eq = cmp.Equal(leftBuffer.cols[j].(*uintColumnBuilder).data,
rightBuffer.cols[j].(*uintColumnBuilder).data)
case flux.TFloat:
eq = cmp.Equal(leftBuffer.cols[j].(*floatColumnBuilder).data,
rightBuffer.cols[j].(*floatColumnBuilder).data)
case flux.TString:
eq = cmp.Equal(leftBuffer.cols[j].(*stringColumnBuilder).data,
rightBuffer.cols[j].(*stringColumnBuilder).data)
case flux.TTime:
eq = cmp.Equal(leftBuffer.cols[j].(*timeColumnBuilder).data,
rightBuffer.cols[j].(*timeColumnBuilder).data)
default:
PanicUnknownType(c.Type)
}
if !eq {
return false, nil
}
}
return eq, nil
}
return false, nil
}
func colsMatch(left, right []flux.ColMeta) bool {
if len(left) != len(right) {
return false
}
for j, l := range left {
if l != right[j] {
return false
}
}
return true
}
// ColMap writes a mapping of builder index to cols index into colMap.
// When colMap does not have enough capacity a new colMap is allocated.
// The colMap is always returned
func ColMap(colMap []int, builder TableBuilder, cols []flux.ColMeta) []int {
l := len(builder.Cols())
if cap(colMap) < l {
colMap = make([]int, len(builder.Cols()))
} else {
colMap = colMap[:l]
}
for j, c := range builder.Cols() {
colMap[j] = ColIdx(c.Label, cols)
}
return colMap
}
// AppendKeyValues appends the key values to the right columns in the builder.
// The builder is expected to contain the key columns.
func AppendKeyValues(key flux.GroupKey, builder TableBuilder) error {
for j, c := range key.Cols() {
idx := ColIdx(c.Label, builder.Cols())
if idx < 0 {
return fmt.Errorf("group key column %s not found in output table", c.Label)
}
if err := builder.AppendValue(idx, key.Value(j)); err != nil {
return err
}
}
return nil
}
// AppendKeyValuesN runs AppendKeyValues `n` times.
// This is different from
// ```
//
// for i := 0; i < n; i++ {
// AppendKeyValues(key, builder)
// }
//
// ```
// Because it saves the overhead of calculating the column mapping `n` times.
func AppendKeyValuesN(key flux.GroupKey, builder TableBuilder, n int) error {
for j, c := range key.Cols() {
idx := ColIdx(c.Label, builder.Cols())
if idx < 0 {
return fmt.Errorf("group key column %s not found in output table", c.Label)
}
for i := 0; i < n; i++ {
if err := builder.AppendValue(idx, key.Value(j)); err != nil {
return err
}
}
}
return nil
}
func ContainsStr(strs []string, str string) bool {
for _, s := range strs {
if str == s {
return true
}
}
return false
}
func ColIdx(label string, cols []flux.ColMeta) int {
for j, c := range cols {
if c.Label == label {
return j
}
}
return -1
}
func HasCol(label string, cols []flux.ColMeta) bool {
return ColIdx(label, cols) >= 0
}
// ValueForRow retrieves a value from an arrow column reader at the given index.
func ValueForRow(cr flux.ColReader, i, j int) values.Value {
t := cr.Cols()[j].Type
switch t {
case flux.TString:
if cr.Strings(j).IsNull(i) {
return values.NewNull(semantic.BasicString)
}
return values.NewString(cr.Strings(j).Value(i))
case flux.TInt:
if cr.Ints(j).IsNull(i) {
return values.NewNull(semantic.BasicInt)
}
return values.NewInt(cr.Ints(j).Value(i))
case flux.TUInt:
if cr.UInts(j).IsNull(i) {
return values.NewNull(semantic.BasicUint)
}
return values.NewUInt(cr.UInts(j).Value(i))
case flux.TFloat:
if cr.Floats(j).IsNull(i) {
return values.NewNull(semantic.BasicFloat)
}
return values.NewFloat(cr.Floats(j).Value(i))
case flux.TBool:
if cr.Bools(j).IsNull(i) {
return values.NewNull(semantic.BasicBool)
}
return values.NewBool(cr.Bools(j).Value(i))
case flux.TTime:
if cr.Times(j).IsNull(i) {
return values.NewNull(semantic.BasicTime)
}
return values.NewTime(values.Time(cr.Times(j).Value(i)))
default:
PanicUnknownType(t)
return values.InvalidValue
}
}
// TableBuilder builds tables that can be used multiple times
type TableBuilder interface {
Key() flux.GroupKey
NRows() int
NCols() int
Cols() []flux.ColMeta
// AddCol increases the size of the table by one column.
// The index of the column is returned.
AddCol(flux.ColMeta) (int, error)
// Set sets the value at the specified coordinates
// The rows and columns must exist before calling set, otherwise Set panics.
SetValue(i, j int, value values.Value) error
SetNil(i, j int) error
// Append will add a single value to the end of a column. Will set the number of
// rows in the table to the size of the new column. It's the caller's job to make sure
// that the expected number of rows in each column is equal.
AppendBool(j int, value bool) error
AppendInt(j int, value int64) error
AppendUInt(j int, value uint64) error
AppendFloat(j int, value float64) error
AppendString(j int, value string) error
AppendTime(j int, value Time) error
AppendValue(j int, value values.Value) error
AppendNil(j int) error
// AppendBools and similar functions will append multiple values to column j. As above,
// it will set the numer of rows in the table to the size of the new column. It's the
// caller's job to make sure that the expected number of rows in each column is equal.
AppendBools(j int, vs *array.Boolean) error
AppendInts(j int, vs *array.Int) error
AppendUInts(j int, vs *array.Uint) error
AppendFloats(j int, vs *array.Float) error
AppendStrings(j int, vs *array.String) error
AppendTimes(j int, vs *array.Int) error
// TODO(adam): determine if there's a useful API for AppendValues
// AppendValues(j int, values []values.Value)
// GrowBools and similar functions will extend column j by n zero-values for the respective type.
// If the column has enough capacity, no reallocation is necessary. If the capacity is insufficient,
// a new slice is allocated with 1.5*newCapacity. As with the Append functions, it is the
// caller's job to make sure that the expected number of rows in each column is equal.
GrowBools(j, n int) error
GrowInts(j, n int) error
GrowUInts(j, n int) error
GrowFloats(j, n int) error
GrowStrings(j, n int) error
GrowTimes(j, n int) error
// LevelColumns will check for columns that are too short and Grow them
// so that each column is of uniform size.
LevelColumns() error
// Sort the rows of the by the values of the columns in the order listed.
Sort(cols []string, desc bool)
// ClearData removes all rows, while preserving the column meta data.
ClearData()
// Release releases any extraneous memory that has been retained.
Release()
// Table returns the table that has been built.
// Further modifications of the builder will not effect the returned table.
Table() (flux.Table, error)
}
type ColListTableBuilder struct {
key flux.GroupKey
colMeta []flux.ColMeta
cols []columnBuilder
nrows int
alloc *Allocator
}
func NewColListTableBuilder(key flux.GroupKey, a memory.Allocator) *ColListTableBuilder {
return &ColListTableBuilder{
key: key,
alloc: &Allocator{Allocator: a},
}
}
func (b *ColListTableBuilder) Key() flux.GroupKey {
return b.key
}
func (b *ColListTableBuilder) NRows() int {
return b.nrows
}
func (b *ColListTableBuilder) Len() int {
return b.nrows
}
func (b *ColListTableBuilder) NCols() int {
return len(b.cols)
}
func (b *ColListTableBuilder) Cols() []flux.ColMeta {
return b.colMeta
}
func (b *ColListTableBuilder) AddCol(c flux.ColMeta) (int, error) {
if ColIdx(c.Label, b.Cols()) >= 0 {
return -1, fmt.Errorf("table builder already has column with label %s", c.Label)
}
newIdx := len(b.cols)
b.colMeta = append(b.colMeta, c)
colBase := columnBuilderBase{
ColMeta: c,
alloc: b.alloc,
nils: make(map[int]bool),
}
switch c.Type {
case flux.TBool:
b.cols = append(b.cols, &boolColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowBools(newIdx, b.NRows()); err != nil {
return -1, err
}
}
case flux.TInt:
b.cols = append(b.cols, &intColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowInts(newIdx, b.NRows()); err != nil {
return -1, err
}
}
case flux.TUInt:
b.cols = append(b.cols, &uintColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowUInts(newIdx, b.NRows()); err != nil {
return -1, err
}
}
case flux.TFloat:
b.cols = append(b.cols, &floatColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowFloats(newIdx, b.NRows()); err != nil {
return -1, err
}
}
case flux.TString:
b.cols = append(b.cols, &stringColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowStrings(newIdx, b.NRows()); err != nil {
return -1, err
}
}
case flux.TTime:
b.cols = append(b.cols, &timeColumnBuilder{
columnBuilderBase: colBase,
})
if b.NRows() > 0 {
if err := b.GrowTimes(newIdx, b.NRows()); err != nil {
return -1, err
}
}
default:
PanicUnknownType(c.Type)
}
return newIdx, nil
}
func (b *ColListTableBuilder) LevelColumns() error {
for idx, c := range b.colMeta {
switch c.Type {
case flux.TBool:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowBools(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
case flux.TInt:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowInts(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
case flux.TUInt:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowUInts(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
case flux.TFloat:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowFloats(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
case flux.TString:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowStrings(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
case flux.TTime:
toGrow := b.NRows() - b.cols[idx].Len()
if toGrow > 0 {
if err := b.GrowTimes(idx, toGrow); err != nil {
return err
}
}
if toGrow < 0 {
_ = fmt.Errorf("column %s is longer than expected length of table", c.Label)
}
default:
PanicUnknownType(c.Type)
}
}
return nil
}
func (b *ColListTableBuilder) SetBool(i int, j int, value bool) error {
if err := b.checkCol(j, flux.TBool); err != nil {
return err
}
b.cols[j].(*boolColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendBool(j int, value bool) error {
if err := b.checkCol(j, flux.TBool); err != nil {
return err
}
col := b.cols[j].(*boolColumnBuilder)
col.data = b.alloc.AppendBools(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendBools(j int, vs *array.Boolean) error {
if err := b.checkCol(j, flux.TBool); err != nil {
return err
}
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.AppendNil(j); err != nil {
return err
}
} else if err := b.AppendBool(j, vs.Value(i)); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) GrowBools(j, n int) error {
if err := b.checkCol(j, flux.TBool); err != nil {
return err
}
col := b.cols[j].(*boolColumnBuilder)
i := len(col.data)
col.data = b.alloc.GrowBools(col.data, n)
b.nrows = len(col.data)
for ; i < b.nrows; i++ {
if err := b.SetNil(i, j); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) SetInt(i int, j int, value int64) error {
if err := b.checkCol(j, flux.TInt); err != nil {
return err
}
b.cols[j].(*intColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendInt(j int, value int64) error {
if err := b.checkCol(j, flux.TInt); err != nil {
return err
}
col := b.cols[j].(*intColumnBuilder)
col.data = b.alloc.AppendInts(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendInts(j int, vs *array.Int) error {
if err := b.checkCol(j, flux.TInt); err != nil {
return err
}
col := b.cols[j].(*intColumnBuilder)
nullOffset := len(col.data)
col.data = b.alloc.AppendInts(col.data, vs.Int64Values()...)
b.nrows = len(col.data)
if vs.NullN() > 0 {
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.SetNil(nullOffset+i, j); err != nil {
return err
}
}
}
}
return nil
}
func (b *ColListTableBuilder) GrowInts(j, n int) error {
if err := b.checkCol(j, flux.TInt); err != nil {
return err
}
col := b.cols[j].(*intColumnBuilder)
i := len(col.data)
col.data = b.alloc.GrowInts(col.data, n)
b.nrows = len(col.data)
for ; i < b.nrows; i++ {
if err := b.SetNil(i, j); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) SetUInt(i int, j int, value uint64) error {
if err := b.checkCol(j, flux.TUInt); err != nil {
return err
}
b.cols[j].(*uintColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendUInt(j int, value uint64) error {
if err := b.checkCol(j, flux.TUInt); err != nil {
return err
}
col := b.cols[j].(*uintColumnBuilder)
col.data = b.alloc.AppendUInts(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendUInts(j int, vs *array.Uint) error {
if err := b.checkCol(j, flux.TUInt); err != nil {
return err
}
col := b.cols[j].(*uintColumnBuilder)
nullOffset := len(col.data)
col.data = b.alloc.AppendUInts(col.data, vs.Uint64Values()...)
b.nrows = len(col.data)
if vs.NullN() > 0 {
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.SetNil(nullOffset+i, j); err != nil {
return err
}
}
}
}
return nil
}
func (b *ColListTableBuilder) GrowUInts(j, n int) error {
if err := b.checkCol(j, flux.TUInt); err != nil {
return err
}
col := b.cols[j].(*uintColumnBuilder)
i := len(col.data)
col.data = b.alloc.GrowUInts(col.data, n)
b.nrows = len(col.data)
for ; i < b.nrows; i++ {
if err := b.SetNil(i, j); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) SetFloat(i int, j int, value float64) error {
if err := b.checkCol(j, flux.TFloat); err != nil {
return err
}
b.cols[j].(*floatColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendFloat(j int, value float64) error {
if err := b.checkCol(j, flux.TFloat); err != nil {
return err
}
col := b.cols[j].(*floatColumnBuilder)
col.data = b.alloc.AppendFloats(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendFloats(j int, vs *array.Float) error {
if err := b.checkCol(j, flux.TFloat); err != nil {
return err
}
col := b.cols[j].(*floatColumnBuilder)
nullOffset := len(col.data)
col.data = b.alloc.AppendFloats(col.data, vs.Float64Values()...)
b.nrows = len(col.data)
if vs.NullN() > 0 {
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.SetNil(nullOffset+i, j); err != nil {
return err
}
}
}
}
return nil
}
func (b *ColListTableBuilder) GrowFloats(j, n int) error {
if err := b.checkCol(j, flux.TFloat); err != nil {
return err
}
col := b.cols[j].(*floatColumnBuilder)
i := len(col.data)
col.data = b.alloc.GrowFloats(col.data, n)
b.nrows = len(col.data)
for ; i < b.nrows; i++ {
if err := b.SetNil(i, j); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) SetString(i int, j int, value string) error {
if err := b.checkCol(j, flux.TString); err != nil {
return err
}
b.cols[j].(*stringColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendString(j int, value string) error {
if err := b.checkCol(j, flux.TString); err != nil {
return err
}
col := b.cols[j].(*stringColumnBuilder)
col.data = b.alloc.AppendStrings(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendStrings(j int, vs *array.String) error {
if err := b.checkCol(j, flux.TString); err != nil {
return err
}
col := b.cols[j].(*stringColumnBuilder)
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.AppendNil(j); err != nil {
return err
}
} else if err := b.AppendString(j, vs.Value(i)); err != nil {
return err
}
}
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) GrowStrings(j, n int) error {
if err := b.checkCol(j, flux.TString); err != nil {
return err
}
col := b.cols[j].(*stringColumnBuilder)
i := len(col.data)
col.data = b.alloc.GrowStrings(col.data, n)
b.nrows = len(col.data)
for ; i < b.nrows; i++ {
if err := b.SetNil(i, j); err != nil {
return err
}
}
return nil
}
func (b *ColListTableBuilder) SetTime(i int, j int, value Time) error {
if err := b.checkCol(j, flux.TTime); err != nil {
return err
}
b.cols[j].(*timeColumnBuilder).data[i] = value
b.cols[j].SetNil(i, false)
return nil
}
func (b *ColListTableBuilder) AppendTime(j int, value Time) error {
if err := b.checkCol(j, flux.TTime); err != nil {
return err
}
col := b.cols[j].(*timeColumnBuilder)
col.data = b.alloc.AppendTimes(col.data, value)
b.nrows = len(col.data)
return nil
}
func (b *ColListTableBuilder) AppendTimes(j int, vs *array.Int) error {
if err := b.checkCol(j, flux.TTime); err != nil {
return err
}
col := b.cols[j].(*timeColumnBuilder)
for i := 0; i < vs.Len(); i++ {
if vs.IsNull(i) {
if err := b.AppendNil(j); err != nil {
return err
}
} else if err := b.AppendTime(j, values.Time(vs.Value(i))); err != nil {