-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathorc_test.go
160 lines (139 loc) · 3.36 KB
/
orc_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
package orc
import (
"compress/gzip"
"encoding/json"
"fmt"
"os"
"path"
"reflect"
"testing"
"time"
)
func TestReadExamples(t *testing.T) {
testCases := []struct {
expected string
example string
}{
{
expected: "decimal.jsn.gz",
example: "decimal.orc",
},
{
expected: "TestOrcFile.test1.jsn.gz",
example: "TestOrcFile.test1.orc",
},
{
expected: "orc_split_elim.jsn.gz",
example: "orc_split_elim.orc",
},
{
expected: "orc-file-11-format.jsn.gz",
example: "orc-file-11-format.orc",
},
{
expected: "TestOrcFile.emptyFile.jsn.gz",
example: "TestOrcFile.emptyFile.orc",
},
// {
// expected: "nulls-at-end-snappy.jsn.gz",
// example: "nulls-at-end-snappy.orc",
// },
// {
// expected: "TestOrcFile.testUnionAndTimestamp.jsn.gz",
// example: "TestOrcFile.testUnionAndTimestamp.orc",
// },
{
expected: "TestOrcFile.testSnappy.jsn.gz",
example: "TestOrcFile.testSnappy.orc",
},
// {
// expected: "TestOrcFile.testDate2038.jsn.gz",
// example: "TestOrcFile.testDate2038.orc",
// },
// {
// expected: "TestOrcFile.testDate1900.jsn.gz",
// example: "TestOrcFile.testDate1900.orc",
// },
{
expected: "TestOrcFile.columnProjection.jsn.gz",
example: "TestOrcFile.columnProjection.orc",
},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("comparing %s to %s", tc.expected, tc.example), func(t *testing.T) {
e, err := loadExpected(tc.expected)
if err != nil {
t.Fatal(err)
}
r, err := Open(path.Join("./examples/", tc.example))
if err != nil {
t.Fatal(err)
}
// Log out the schema description, helps in the event of a test failure.
t.Log(r.Schema().String())
c := r.Select("*")
var rowNum int
for c.Stripes() {
for c.Next() {
rowData := c.Row()[0].(Struct)
// We have to perform some coercion so that the values match
// the JSON values in the formatted example files.
for col, val := range rowData {
switch ty := val.(type) {
case Date:
rowData[col] = ty.UTC().Format("2006-01-02")
case time.Time:
rowData[col] = ty.UTC().Format("2006-01-02 15:04:05.0")
case []byte:
values := make([]uint, len(ty))
for j := range ty {
values[j] = uint(ty[j])
}
rowData[col] = values
}
}
row, err := json.Marshal(rowData)
if err != nil {
t.Fatal(err)
}
var m map[string]interface{}
err = json.Unmarshal(row, &m)
if err != nil {
t.Fatal(err)
}
for col, val := range e[rowNum] {
if actualVal, ok := m[col]; ok {
if !reflect.DeepEqual(val, actualVal) {
t.Fatalf("Test failed on row %v column `%s`, expected %v (%T) got %v (%T)", rowNum, col, val, val, actualVal, actualVal)
}
} else {
t.Fatalf("Test failed, column %s expected but not present", col)
}
}
rowNum++
}
}
})
}
}
func loadExpected(filename string) ([]map[string]interface{}, error) {
f, err := os.Open(path.Join("./examples/expected", filename))
if err != nil {
return nil, err
}
r, err := gzip.NewReader(f)
if err != nil {
return nil, err
}
d := json.NewDecoder(r)
var results []map[string]interface{}
for d.More() {
var row map[string]interface{}
err := d.Decode(&row)
if err != nil {
return nil, err
}
results = append(results, row)
}
return results, nil
}