-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
column_test.go
790 lines (672 loc) · 19.3 KB
/
column_test.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
// Copyright (c) Roman Atachiants and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
package column
import (
"fmt"
"reflect"
"testing"
"time"
"github.com/kelindar/bitmap"
"github.com/kelindar/column/commit"
"github.com/stretchr/testify/assert"
)
func TestColumns(t *testing.T) {
tests := []struct {
column Column
value interface{}
}{
{column: ForEnum(), value: "mage"},
{column: ForBool(), value: true},
{column: ForString(), value: "test"},
{column: ForInt(), value: int(99)},
{column: ForInt16(), value: int16(99)},
{column: ForInt32(), value: int32(99)},
{column: ForInt64(), value: int64(99)},
{column: ForUint(), value: uint(99)},
{column: ForUint16(), value: uint16(99)},
{column: ForUint32(), value: uint32(99)},
{column: ForUint64(), value: uint64(99)},
{column: ForFloat32(), value: float32(99.5)},
{column: ForFloat64(), value: float64(99.5)},
}
for _, tc := range tests {
t.Run(fmt.Sprintf("%T", tc.column), func(t *testing.T) {
testColumn(t, tc.column, tc.value)
})
t.Run(fmt.Sprintf("%T-put-delete", tc.column), func(t *testing.T) {
testPutDelete(t, tc.column, tc.value)
})
t.Run(fmt.Sprintf("%T-snapshot", tc.column), func(t *testing.T) {
testSnapshot(t, tc.column, tc.value)
})
}
}
// Tests an individual column implementation
func testColumn(t *testing.T, column Column, value interface{}) {
for i := 0; i < 2000; i += 50 {
column.Grow(uint32(i))
}
// Add a value
column.Grow(1)
applyChanges(column, Update{commit.Put, 9, value})
// Assert the value
v, ok := column.Value(9)
assert.Equal(t, 1, column.Index(0).Count())
assert.True(t, column.Contains(9))
assert.Equal(t, value, v)
assert.True(t, ok)
// Apply updates
applyChanges(column, Update{commit.Put, 9, value})
// Assert Numeric
if column, ok := column.(Numeric); ok {
// FilterFloat64
index := bitmap.Bitmap{0xffff}
column.FilterFloat64(0, index, func(v float64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// FilterInt64
index = bitmap.Bitmap{0xffff}
column.FilterInt64(0, index, func(v int64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// FilterUint64
index = bitmap.Bitmap{0xffff}
column.FilterUint64(0, index, func(v uint64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// Atomic Add
applyChanges(column,
Update{Type: commit.Put, Index: 1, Value: value},
Update{Type: commit.Put, Index: 2, Value: value},
Update{Type: commit.Merge, Index: 1, Value: value},
)
assert.True(t, column.Contains(1))
assert.True(t, column.Contains(2))
//v, _ := column.LoadInt64(1)
}
// Assert Textual
if column, ok := column.(Textual); ok {
// LoadString
str, ok := column.LoadString(9)
assert.EqualValues(t, value, str)
assert.True(t, ok)
// FilterFloat64
index := bitmap.Bitmap{0xffff}
column.FilterString(0, index, func(v string) bool {
return false
})
assert.Equal(t, 0, index.Count())
}
// Assert Numeric
if column, ok := column.(Numeric); ok {
// LoadFloat64
f64, ok := column.LoadFloat64(9)
assert.EqualValues(t, value, f64)
assert.True(t, ok)
// FilterFloat64
index := bitmap.Bitmap{0xffff}
column.FilterFloat64(0, index, func(v float64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// LoadInt64
i64, ok := column.LoadInt64(9)
assert.EqualValues(t, value, i64)
assert.True(t, ok)
// FilterInt64
index = bitmap.Bitmap{0xffff}
column.FilterInt64(0, index, func(v int64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// LoadUint64
u64, ok := column.LoadUint64(9)
assert.EqualValues(t, value, u64)
assert.True(t, ok)
// FilterUint64
index = bitmap.Bitmap{0xffff}
column.FilterUint64(0, index, func(v uint64) bool {
return false
})
assert.Equal(t, 0, index.Count())
// Atomic Add
applyChanges(column,
Update{Type: commit.Put, Index: 1, Value: value},
Update{Type: commit.Put, Index: 2, Value: value},
Update{Type: commit.Merge, Index: 1, Value: value},
)
assert.True(t, column.Contains(1))
assert.True(t, column.Contains(2))
}
}
// testPutDelete test a put and a delete
func testPutDelete(t *testing.T, column Column, value interface{}) {
applyChanges(column,
Update{commit.Put, 0, value},
Update{commit.Delete, 0, nil},
)
// Should be deleted
_, ok := column.Value(0)
assert.False(t, ok)
}
// testSnapshot test a snapshot of a column
func testSnapshot(t *testing.T, column Column, value interface{}) {
buf := commit.NewBuffer(8)
column.Snapshot(0, buf)
assert.False(t, buf.IsEmpty())
}
func TestFromKind(t *testing.T) {
for _, v := range []reflect.Kind{
reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Bool, reflect.String,
reflect.Float32, reflect.Float64,
} {
column, err := ForKind(v)
assert.NoError(t, err)
_, ok := column.Value(100)
assert.False(t, ok)
}
}
func applyChanges(column Column, updates ...Update) {
buf := commit.NewBuffer(10)
for _, u := range updates {
buf.PutAny(u.Type, u.Index, u.Value)
}
r := new(commit.Reader)
r.Seek(buf)
column.Apply(0, r)
}
type Update struct {
Type commit.OpType
Index uint32
Value interface{}
}
func TestForString(t *testing.T) {
coll := NewCollection()
coll.CreateColumn("id", ForInt64())
coll.CreateColumn("data", ForString())
coll.CreateIndex("one", "id", func(r Reader) bool {
return r.Int() == 1
})
data := []string{"a", "b", "c", "d"}
for i, d := range data {
_, err := coll.Insert(func(r Row) error {
return r.SetMany(map[string]any{"id": i, "data": d})
})
assert.NoError(t, err)
}
coll.Query(func(txn *Txn) error {
txn.With("one").Range(func(i uint32) {
data, ok := txn.String("data").Get()
assert.True(t, ok)
assert.Equal(t, "b", data)
})
return nil
})
}
func TestForKindInvalid(t *testing.T) {
c, err := ForKind(reflect.Invalid)
assert.Nil(t, c)
assert.Error(t, err)
}
func TestAtKey(t *testing.T) {
const testKey = "key=20"
// Update a name
players := loadPlayers(500)
players.CreateColumn("pk", ForKey())
assert.NoError(t, players.Query(func(txn *Txn) error {
pk := txn.Key()
return txn.Range(func(idx uint32) {
pk.Set(fmt.Sprintf("key=%d", idx))
})
}))
assert.NoError(t, players.QueryKey(testKey, func(r Row) error {
r.SetString("name", "Roman")
return nil
}))
// Read back and assert
assertion := func(r Row) error {
name, _ := r.String("name")
race, _ := r.Enum("race")
assert.Equal(t, "Roman", name)
assert.Equal(t, "elf", race)
return nil
}
assert.NoError(t, players.QueryKey(testKey, assertion))
assert.NoError(t, players.Query(func(txn *Txn) error {
assert.NoError(t, txn.QueryKey(testKey, assertion))
return nil
}))
}
func TestUpdateAtKeyWithoutPK(t *testing.T) {
col := NewCollection()
assert.Error(t, col.QueryKey("test", func(r Row) error {
r.SetEnum("name", "Roman")
return nil
}))
}
func TestSelectAtKeyWithoutPK(t *testing.T) {
col := NewCollection()
assert.Error(t, col.QueryKey("test", func(r Row) error { return nil }))
assert.Error(t, col.InsertKey("test", func(r Row) error { return nil }))
assert.Error(t, col.UpsertKey("test", func(r Row) error { return nil }))
assert.Error(t, col.DeleteKey("test"))
}
func TestBulkUpdateDuplicatePK(t *testing.T) {
col := NewCollection()
col.CreateColumn("key", ForKey())
assert.NoError(t, col.InsertKey("1", func(r Row) error { return nil }))
assert.NoError(t, col.InsertKey("2", func(r Row) error { return nil }))
// If we attempt to change to an already persisted key, we should get an error
assert.NoError(t, col.Query(func(txn *Txn) error {
pk := txn.Key()
assert.Error(t, txn.QueryKey("1", func(Row) error {
return pk.Set("2")
}))
return nil
}))
}
func TestSnapshotBool(t *testing.T) {
input := ForBool()
input.Grow(8)
applyChanges(input,
Update{commit.Put, 2, true},
Update{commit.Put, 5, true},
)
// Snapshot into a new buffer
buf := commit.NewBuffer(8)
input.Snapshot(0, buf)
// Create a new reader and read the column
rdr := commit.NewReader()
rdr.Seek(buf)
output := ForBool()
output.Grow(8)
output.Apply(0, rdr)
assert.Equal(t, input, output)
}
func TestSnapshotIndex(t *testing.T) {
predicateFn := func(Reader) bool {
return true
}
input := newIndex("test", "a", predicateFn)
input.Grow(8)
applyChanges(input.Column,
Update{commit.Put, 2, true},
Update{commit.Put, 5, true},
)
// Snapshot into a new buffer
buf := commit.NewBuffer(8)
input.Column.Snapshot(0, buf)
// Create a new reader and read the column
rdr := commit.NewReader()
rdr.Seek(buf)
output := newIndex("test", "a", predicateFn)
output.Grow(8)
output.Apply(0, rdr)
assert.Equal(t, input.Column.(*columnIndex).fill, output.Column.(*columnIndex).fill)
}
func TestAccessors(t *testing.T) {
tests := []struct {
column Column
value interface{}
access func(*Txn, string) interface{}
}{
{column: ForEnum(), value: "mage", access: func(txn *Txn, n string) interface{} { return txn.Enum(n) }},
{column: ForString(), value: "test", access: func(txn *Txn, n string) interface{} { return txn.String(n) }},
{column: ForInt(), value: int(99), access: func(txn *Txn, n string) interface{} { return txn.Int(n) }},
{column: ForInt16(), value: int16(99), access: func(txn *Txn, n string) interface{} { return txn.Int16(n) }},
{column: ForInt32(), value: int32(99), access: func(txn *Txn, n string) interface{} { return txn.Int32(n) }},
{column: ForInt64(), value: int64(99), access: func(txn *Txn, n string) interface{} { return txn.Int64(n) }},
{column: ForUint(), value: uint(99), access: func(txn *Txn, n string) interface{} { return txn.Uint(n) }},
{column: ForUint16(), value: uint16(99), access: func(txn *Txn, n string) interface{} { return txn.Uint16(n) }},
{column: ForUint32(), value: uint32(99), access: func(txn *Txn, n string) interface{} { return txn.Uint32(n) }},
{column: ForUint64(), value: uint64(99), access: func(txn *Txn, n string) interface{} { return txn.Uint64(n) }},
{column: ForFloat32(), value: float32(99.5), access: func(txn *Txn, n string) interface{} { return txn.Float32(n) }},
{column: ForFloat64(), value: float64(99.5), access: func(txn *Txn, n string) interface{} { return txn.Float64(n) }},
}
for _, tc := range tests {
t.Run(fmt.Sprintf("%T", tc.column), func(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("pk", ForKey()))
assert.NoError(t, col.CreateColumn("column", tc.column))
// Invoke 'Set' method of the accessor
assert.NoError(t, col.QueryAt(0, func(r Row) error {
column := tc.access(r.txn, "column")
assert.Len(t, invoke(column, "Set", tc.value), 0)
return nil
}))
// Invoke 'Get' method of the accessor
assert.NoError(t, col.QueryAt(0, func(r Row) error {
column := tc.access(r.txn, "column")
assert.GreaterOrEqual(t, len(invoke(column, "Get")), 1)
return nil
}))
// If it has 'Add' method, try to invoke it
assert.NoError(t, col.QueryAt(0, func(r Row) error {
column := tc.access(r.txn, "column")
if m := reflect.ValueOf(column).MethodByName("Add"); m.IsValid() {
assert.Len(t, invoke(column, "Add", tc.value), 0)
}
return nil
}))
// Invalid column name should panic
assert.Panics(t, func() {
col.Query(func(txn *Txn) error {
tc.access(txn, "invalid")
return nil
})
})
// Invalid column type should panic
assert.Panics(t, func() {
col.Query(func(txn *Txn) error {
tc.access(txn, "pk")
return nil
})
})
})
}
}
func TestBooleanAccessor(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("active", ForBool()))
assert.NoError(t, col.CreateColumn("name", ForString()))
// Insert a boolean value
_, err := col.Insert(func(r Row) error {
r.txn.Bool("active").Set(true)
r.txn.String("name").Set("Roman")
r.txn.Any("name").Set("Roman")
return nil
})
assert.NoError(t, err)
// Boolean should also work for name
col.QueryAt(0, func(r Row) error {
active := r.txn.Bool("active")
hasName := r.txn.Bool("name")
assert.True(t, active.Get())
assert.True(t, hasName.Get())
name, ok := r.txn.Any("name").Get()
assert.True(t, ok)
assert.Equal(t, "Roman", name)
return nil
})
}
func TestColumnNotFound(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("name", ForString()))
// Boolean column does not exist
assert.Panics(t, func() {
col.QueryAt(0, func(r Row) error {
r.txn.Bool("xxx")
return nil
})
})
// Any column does not exist
assert.Panics(t, func() {
col.QueryAt(0, func(r Row) error {
r.txn.Any("xxx")
return nil
})
})
}
func TestPKAccessor(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("name", ForKey()))
// Insert a primary key value
err := col.InsertKey("Roman", func(r Row) error {
return nil
})
assert.NoError(t, err)
// Check if key is correct
col.QueryAt(0, func(r Row) error {
value, ok := r.txn.Key().Get()
assert.True(t, ok)
assert.Equal(t, "Roman", value)
return nil
})
}
func TestInvalidPKAccessor(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("pk", ForString()))
assert.Panics(t, func() {
col.Query(func(txn *Txn) error {
txn.Key()
return nil
})
})
}
func TestIndexValue(t *testing.T) {
idx := newIndex("a", "b", func(r Reader) bool {
return r.Float() > 100
})
idx.Column.(*columnIndex).fill.Set(0)
_, ok := idx.Value(0)
assert.True(t, ok)
}
func TestDuplicatePK(t *testing.T) {
col := NewCollection()
assert.NoError(t, col.CreateColumn("name", ForKey()))
// Insert a primary key value
assert.NoError(t, col.InsertKey("Roman", func(r Row) error {
return nil
}))
// Insert a duplicate
assert.Error(t, col.InsertKey("Roman", func(r Row) error {
return nil
}))
// Must have one value
assert.Equal(t, 1, col.Count())
}
func TestMergeString(t *testing.T) {
col := NewCollection()
col.CreateColumn("name", ForString())
col.CreateColumn("letters", ForString(WithMerge(func(value, delta string) string {
if len(value) > 0 {
value += ", "
}
return value + delta
})))
idx, _ := col.Insert(func(r Row) error {
r.SetString("name", "Roman")
r.SetString("letters", "a")
return nil
})
col.QueryAt(idx, func(r Row) error {
r.MergeString("name", "Merlin")
r.MergeString("letters", "b")
return nil
})
// Letters must be appended, name overwritten
col.QueryAt(idx, func(r Row) error {
name, _ := r.String("name")
assert.Equal(t, "Merlin", name)
letters, _ := r.String("letters")
assert.Equal(t, "a, b", letters)
return nil
})
}
func TestRecord(t *testing.T) {
col := NewCollection()
col.CreateColumn("ts", ForRecord(func() *time.Time {
return new(time.Time)
}))
col.CreateIndex("recent", "ts", func(r Reader) bool {
var ts time.Time
if err := ts.UnmarshalBinary(r.Bytes()); err == nil {
return ts.After(time.Unix(1667745800, 0))
}
return false
})
// Insert the time, it implements binary marshaler
idx, _ := col.Insert(func(r Row) error {
now := time.Unix(1667745700, 0)
r.SetRecord("ts", &now)
return nil
})
// Index should not have any recent
col.Query(func(txn *Txn) error {
assert.Equal(t, 1, txn.Without("recent").Count())
return nil
})
// We should be able to read back the time
col.QueryAt(idx, func(r Row) error {
now := time.Unix(1667745900, 0)
r.MergeRecord("ts", &now)
return nil
})
// We should be able to read back the time
col.QueryAt(idx, func(r Row) error {
ts, ok := r.Record("ts")
assert.True(t, ok)
assert.Equal(t, "November", ts.(*time.Time).UTC().Month().String())
return nil
})
// Merge should have updated the index as well
col.Query(func(txn *Txn) error {
assert.Equal(t, 1, txn.With("recent").Count())
return nil
})
}
func TestRecord_Errors(t *testing.T) {
col := NewCollection()
col.CreateColumn("id", ForInt64())
col.CreateColumn("ts", ForRecord(func() *time.Time {
return new(time.Time)
}))
// Column "xxx" does not exist
assert.Panics(t, func() {
col.Query(func(txn *Txn) error {
txn.Record("xxx")
return nil
})
})
// Column "id" is not of record type
assert.Panics(t, func() {
col.Query(func(txn *Txn) error {
txn.Record("id")
return nil
})
})
// No value at index 10
col.QueryAt(10, func(r Row) error {
v, ok := r.Record("ts")
assert.Nil(t, v)
assert.False(t, ok)
return nil
})
}
func TestRecordMerge_ErrDecode(t *testing.T) {
col := NewCollection()
col.CreateColumn("record", ForRecord(func() mockRecord {
return mockRecord{
errDecode: true,
}
}))
// Insert the time, it implements binary marshaler
idx, _ := col.Insert(func(r Row) error {
r.SetRecord("record", mockRecord{})
return nil
})
// Merge a record, but will fail on decode
col.QueryAt(idx, func(r Row) error {
assert.NoError(t, r.MergeRecord("record", mockRecord{}))
return nil
})
}
func TestRecordMerge_ErrEncode(t *testing.T) {
col := NewCollection()
col.CreateColumn("record", ForRecord(func() mockRecord {
return mockRecord{
errEncode: true,
}
}))
// Insert the time, it implements binary marshaler
idx, _ := col.Insert(func(r Row) error {
r.SetRecord("record", mockRecord{})
return nil
})
// Merge a record, but will fail on decode
col.QueryAt(idx, func(r Row) error {
assert.NoError(t, r.MergeRecord("record", mockRecord{}))
return nil
})
}
func TestNumberMerge(t *testing.T) {
col := NewCollection()
col.CreateColumn("age", ForInt32(WithMerge(func(v, d int32) int32 {
v -= d
return v
})))
col.CreateIndex("young", "age", func(r Reader) bool {
return r.Int() < 50
})
// Insert the time, it implements binary marshaler
idx, _ := col.Insert(func(r Row) error {
r.SetInt32("age", 100)
return nil
})
for i := 0; i < 7; i++ {
col.QueryAt(idx, func(r Row) error {
r.MergeInt32("age", 10)
return nil
})
}
col.QueryAt(idx, func(r Row) error {
age, _ := r.Int32("age")
assert.Equal(t, int32(30), age)
return nil
})
col.Query(func(txn *Txn) error {
assert.Equal(t, 1, txn.With("young").Count())
return nil
})
}
func TestIssue87(t *testing.T) {
table := NewCollection()
table.CreateColumn("birthdate", ForRecord(func() *time.Time { return new(time.Time) }))
srcDate := time.Date(1999, 3, 2, 12, 0, 0, 0, time.Local)
table.Insert(func(r Row) error {
r.SetRecord("birthdate", srcDate)
return nil
})
table.Query(func(txn *Txn) error {
assert.Equal(t, txn.WithValue("birthdate", func(v any) bool {
return v.(*time.Time).Equal(srcDate)
}).Count(), 1)
return nil
})
}
// Tests the case where a column is created after inserting a large enough amount of data
func TestIssue89(t *testing.T) {
coll := NewCollection()
coll.CreateColumn("foo", ForString())
// Should be larger than a single chunk
for i := 0; i < 16385; i++ {
coll.Insert(func(row Row) error {
row.SetString("foo", fmt.Sprintf("foo-%d", i))
return nil
})
}
// set up a derived column of data, over initial capacity
coll.CreateColumn("bar", ForString())
assert.NoError(t, coll.Query(func(txn *Txn) error {
src := txn.String("foo")
dest := txn.String("bar")
return txn.Range(func(_ uint32) {
value, ok := src.Get()
assert.True(t, ok)
dest.Set("bar-" + value[4:])
})
}))
assert.Equal(t, 16385, coll.Count())
}
func invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
inputs := make([]reflect.Value, len(args))
for i := range args {
inputs[i] = reflect.ValueOf(args[i])
}
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
}