-
Notifications
You must be signed in to change notification settings - Fork 0
/
take_record_columns_test.go
94 lines (85 loc) · 2.36 KB
/
take_record_columns_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
package arrowops
import (
"errors"
"fmt"
"testing"
"github.com/apache/arrow/go/v17/arrow"
"github.com/apache/arrow/go/v17/arrow/array"
"github.com/apache/arrow/go/v17/arrow/memory"
)
func TestTakeRecordColumns(t *testing.T) {
mem := memory.NewGoAllocator()
testCases := []struct {
caseName string
recordBldr func() arrow.Record
columns []string
expectedRecordBldr func() arrow.Record
expectedErr error
}{
{
caseName: "allColumns",
recordBldr: func() arrow.Record {
return MockData(mem, 10, "ascending")
},
columns: []string{"a", "b", "c"},
expectedRecordBldr: func() arrow.Record {
return MockData(mem, 10, "ascending")
},
expectedErr: nil,
},
{
caseName: "singleColumn",
recordBldr: func() arrow.Record {
return MockData(mem, 10, "ascending")
},
columns: []string{"a"},
expectedRecordBldr: func() arrow.Record {
recordBldr := array.NewRecordBuilder(mem, arrow.NewSchema([]arrow.Field{{Name: "a", Type: arrow.PrimitiveTypes.Int64}}, nil))
defer recordBldr.Release()
recordBldr.Field(0).(*array.Int64Builder).AppendValues([]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, nil)
return recordBldr.NewRecord()
},
expectedErr: nil,
},
{
caseName: "emptyColumnSlice",
recordBldr: func() arrow.Record {
return MockData(mem, 10, "ascending")
},
columns: []string{},
expectedRecordBldr: func() arrow.Record {
return nil
},
expectedErr: ErrNoColumnsProvided,
},
{
caseName: "columnNotInRecord",
recordBldr: func() arrow.Record {
return MockData(mem, 10, "ascending")
},
columns: []string{"zap"},
expectedRecordBldr: func() arrow.Record {
return nil
},
expectedErr: ErrColumnNotFound,
},
}
for _, testCase := range testCases {
t.Run(fmt.Sprintf("case_%s", testCase.caseName), func(t *testing.T) {
record := testCase.recordBldr()
defer record.Release()
newRecord, err := TakeRecordColumns(record, testCase.columns)
if !errors.Is(err, testCase.expectedErr) {
t.Errorf("expected error:\n%v\ngot\n%v", testCase.expectedErr, err)
}
if err == nil {
defer newRecord.Release()
expectedRecord := testCase.expectedRecordBldr()
defer expectedRecord.Release()
if !RecordsEqual(expectedRecord, newRecord) {
t.Errorf("expected record: %v, got: %v", expectedRecord, newRecord)
}
}
})
}
}