forked from parquet-go/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_test.go
More file actions
106 lines (101 loc) · 3.04 KB
/
node_test.go
File metadata and controls
106 lines (101 loc) · 3.04 KB
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
package parquet
import (
"reflect"
"testing"
"github.com/parquet-go/parquet-go/compress"
"github.com/parquet-go/parquet-go/encoding"
)
type mockNode struct {
id int
str string
typ func() Type
optional bool
repeated bool
required bool
leaf bool
fields func() []Field
enc func() encoding.Encoding
compression func() compress.Codec
goType func() reflect.Type
}
func (m *mockNode) ID() int { return m.id }
func (m *mockNode) String() string { return m.str }
func (m *mockNode) Type() Type { return m.typ() }
func (m *mockNode) Optional() bool { return m.optional }
func (m *mockNode) Repeated() bool { return m.repeated }
func (m *mockNode) Required() bool { return m.required }
func (m *mockNode) Leaf() bool { return m.leaf }
func (m *mockNode) Fields() []Field { return m.fields() }
func (m *mockNode) Encoding() encoding.Encoding { return m.enc() }
func (m *mockNode) Compression() compress.Codec { return m.compression() }
func (m *mockNode) GoType() reflect.Type { return m.goType() }
func TestEncodingOf(t *testing.T) {
testCases := []struct {
name string
node Node
defaultEncodings map[Kind]encoding.Encoding
expectedEncoding encoding.Encoding
}{
{
name: "node with encoding, no default",
node: &mockNode{
enc: func() encoding.Encoding { return &DeltaBinaryPacked },
typ: func() Type { return Int32Type },
},
defaultEncodings: nil,
expectedEncoding: &DeltaBinaryPacked,
},
{
name: "node with encoding, different default",
node: &mockNode{
enc: func() encoding.Encoding { return &DeltaBinaryPacked },
typ: func() Type { return Int32Type },
},
defaultEncodings: map[Kind]encoding.Encoding{
Int32: &Plain,
},
expectedEncoding: &DeltaBinaryPacked,
},
{
name: "node without encoding, with default",
node: &mockNode{
enc: func() encoding.Encoding { return nil },
typ: func() Type { return ByteArrayType },
},
defaultEncodings: map[Kind]encoding.Encoding{
ByteArray: &DeltaByteArray,
},
expectedEncoding: &DeltaByteArray,
},
{
name: "node without encoding, no default, not ByteArray",
node: &mockNode{
enc: func() encoding.Encoding { return nil },
typ: func() Type { return Int32Type },
},
defaultEncodings: nil,
expectedEncoding: &Plain,
},
{
name: "node without encoding, no default, ByteArray",
node: &mockNode{
enc: func() encoding.Encoding { return nil },
typ: func() Type { return ByteArrayType },
},
defaultEncodings: nil,
expectedEncoding: &DeltaLengthByteArray,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
enc := encodingOf(tc.node, tc.defaultEncodings)
if enc == nil {
t.Error("encodingOf returned nil")
}
if enc.String() != tc.expectedEncoding.String() {
t.Errorf("encodingOf returned %s, but expected %s",
enc.String(), tc.expectedEncoding.String())
}
})
}
}