-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtreewriterfactory.go
108 lines (105 loc) · 2.94 KB
/
treewriterfactory.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
package orc
import (
"fmt"
)
func createTreeWriter(codec CompressionCodec, schema *TypeDescription, writers writerMap) (TreeWriter, error) {
id := schema.getID()
var treeWriter TreeWriter
var err error
category := schema.getCategory()
switch category {
case CategoryFloat:
treeWriter, err = NewFloatTreeWriter(category, codec, 4)
if err != nil {
return nil, err
}
case CategoryDouble:
treeWriter, err = NewFloatTreeWriter(category, codec, 8)
if err != nil {
return nil, err
}
case CategoryBoolean:
treeWriter, err = NewBooleanTreeWriter(category, codec)
if err != nil {
return nil, err
}
case CategoryStruct:
// Create a TreeWriter for each child of the struct column.
var children []TreeWriter
for _, child := range schema.children {
childWriter, err := createTreeWriter(codec, child, writers)
if err != nil {
return nil, err
}
children = append(children, childWriter)
}
treeWriter, err = NewStructTreeWriter(category, codec, children)
if err != nil {
return nil, err
}
case CategoryShort, CategoryInt, CategoryLong:
treeWriter, err = NewIntegerTreeWriter(category, codec)
if err != nil {
return nil, err
}
case CategoryVarchar, CategoryString:
treeWriter, err = NewStringTreeWriter(category, codec)
if err != nil {
return nil, err
}
case CategoryList:
if len(schema.children) != 1 {
return nil, fmt.Errorf("unexpected number of children for list column, expected 1 got %v", len(schema.children))
}
child, err := createTreeWriter(codec, schema.children[0], writers)
if err != nil {
return nil, err
}
treeWriter, err = NewListTreeWriter(category, codec, child)
if err != nil {
return nil, err
}
case CategoryMap:
if len(schema.children) != 2 {
return nil, fmt.Errorf("unexpected number of children for map column, expected 2 got %v", len(schema.children))
}
keyWriter, err := createTreeWriter(codec, schema.children[0], writers)
if err != nil {
return nil, err
}
valueWriter, err := createTreeWriter(codec, schema.children[1], writers)
if err != nil {
return nil, err
}
treeWriter, err = NewMapTreeWriter(category, codec, keyWriter, valueWriter)
if err != nil {
return nil, err
}
case CategoryTimestamp:
treeWriter, err = NewTimestampTreeWriter(category, codec)
if err != nil {
return nil, err
}
case CategoryUnion:
// Create a TreeWriter for each child of the unionvalue column.
var children []TreeWriter
for _, child := range schema.children {
childWriter, err := createTreeWriter(codec, child, writers)
if err != nil {
return nil, err
}
children = append(children, childWriter)
}
treeWriter, err = NewUnionTreeWriter(category, codec, children)
case CategoryDate:
treeWriter, err = NewDateTreeWriter(category, codec)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported type: %s", category)
}
writers.add(id, treeWriter)
// Return the TreeWriter
return treeWriter, nil
}