-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdro.go
170 lines (162 loc) · 4.15 KB
/
dro.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
package drogo
import (
"github.com/apache/arrow/go/v12/arrow"
"github.com/apache/arrow/go/v12/arrow/array"
"github.com/apache/arrow/go/v12/arrow/memory"
)
var (
Int8 = &arrow.Int8Type{}
Int16 = &arrow.Int16Type{}
Int32 = &arrow.Int32Type{}
Int64 = &arrow.Int64Type{}
Float32 = &arrow.Float32Type{}
Float64 = &arrow.Float64Type{}
String = &arrow.StringType{}
Boolean = &arrow.BooleanType{}
)
type Array struct {
dtype arrow.DataType
boolData *array.Boolean
int8Data *array.Int8
int16Data *array.Int16
int32Data *array.Int32
int64Data *array.Int64
float32Data *array.Float32
float64Data *array.Float64
stringData *array.String
}
func (arr *Array) String() string {
switch arr.dtype.(type) {
case *arrow.BooleanType:
return arr.boolData.String()
case *arrow.Int8Type:
return arr.int8Data.String()
case *arrow.Int16Type:
return arr.int16Data.String()
case *arrow.Int32Type:
return arr.int32Data.String()
case *arrow.Int64Type:
return arr.int64Data.String()
case *arrow.Float32Type:
return arr.float32Data.String()
case *arrow.Float64Type:
return arr.float64Data.String()
case *arrow.StringType:
return arr.stringData.String()
default:
panic("Unsupported Arrow type")
}
}
// impl ColumnVector for dro
func (arr Array) Len() int {
switch arr.dtype.(type) {
case *arrow.BooleanType:
return arr.boolData.Len()
case *arrow.Int8Type:
return arr.int8Data.Len()
case *arrow.Int16Type:
return arr.int16Data.Len()
case *arrow.Int32Type:
return arr.int32Data.Len()
case *arrow.Int64Type:
return arr.int64Data.Len()
case *arrow.Float32Type:
return arr.float32Data.Len()
case *arrow.Float64Type:
return arr.float64Data.Len()
case *arrow.StringType:
return arr.stringData.Len()
default:
panic("Unsupported Arrow type")
}
}
func (arr Array) GetValue(i int) any {
switch arr.dtype.(type) {
case *arrow.BooleanType:
return arr.boolData.Value(i)
case *arrow.Int8Type:
return arr.int8Data.Value(i)
case *arrow.Int16Type:
return arr.int16Data.Value(i)
case *arrow.Int32Type:
return arr.int32Data.Value(i)
case *arrow.Int64Type:
return arr.int64Data.Value(i)
case *arrow.Float32Type:
return arr.float32Data.Value(i)
case *arrow.Float64Type:
return arr.float64Data.Value(i)
case *arrow.StringType:
return arr.stringData.Value(i)
default:
panic("Unsupported Arrow type")
}
}
func (arr Array) DataType() arrow.DataType {
return arr.dtype
}
func New(arrowType arrow.DataType, initialCapacity int, data []any) Array {
rootAllocator := memory.NewGoAllocator()
out := Array{dtype: arrowType}
switch arrowType.(type) {
case *arrow.BooleanType:
vs := array.NewBooleanBuilder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(bool))
}
out.boolData = vs.NewBooleanArray()
case *arrow.Int8Type:
vs := array.NewInt8Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(int8))
}
out.int8Data = vs.NewInt8Array()
case *arrow.Int16Type:
vs := array.NewInt16Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(int16))
}
out.int16Data = vs.NewInt16Array()
case *arrow.Int32Type:
vs := array.NewInt32Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(int32))
}
out.int32Data = vs.NewInt32Array()
case *arrow.Int64Type:
vs := array.NewInt64Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(int64))
}
out.int64Data = vs.NewInt64Array()
case *arrow.Float32Type:
vs := array.NewFloat32Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(float32))
}
out.float32Data = vs.NewFloat32Array()
case *arrow.Float64Type:
vs := array.NewFloat64Builder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(float64))
}
out.float64Data = vs.NewFloat64Array()
case *arrow.StringType:
vs := array.NewStringBuilder(rootAllocator)
vs.Reserve(initialCapacity)
for _, v := range data {
vs.Append(v.(string))
}
out.stringData = vs.NewStringArray()
default:
panic("Unsupported Arrow type")
}
return out
}