Repository navigation
Expand file tree
/
Copy patharray.go
More file actions
190 lines (165 loc) · 4.78 KB
/
Copy patharray.go
File metadata and controls
190 lines (165 loc) · 4.78 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package array
import (
"github.com/apache/arrow/go/arrow"
"github.com/apache/arrow/go/arrow/array"
"github.com/influxdata/flux/codes"
"github.com/influxdata/flux/internal/errors"
)
//go:generate -command tmpl ../gotool.sh github.com/benbjohnson/tmpl
//go:generate tmpl [email protected] -o builder.gen.go builder.gen.go.tmpl
//go:generate tmpl [email protected] -o repeat.gen.go repeat.gen.go.tmpl
type DataType = arrow.DataType
var (
IntType = arrow.PrimitiveTypes.Int64
UintType = arrow.PrimitiveTypes.Uint64
FloatType = arrow.PrimitiveTypes.Float64
StringType = arrow.BinaryTypes.String
BooleanType = arrow.FixedWidthTypes.Boolean
)
// Interface represents an immutable sequence of values.
//
// This type is derived from the arrow array.Interface interface.
type Interface interface {
// DataType returns the type metadata for this instance.
DataType() DataType
// NullN returns the number of null values in the array.
NullN() int
// NullBitmapBytes returns a byte slice of the validity bitmap.
NullBitmapBytes() []byte
// IsNull returns true if value at index is null.
// NOTE: IsNull will panic if NullBitmapBytes is not empty and 0 > i ≥ Len.
IsNull(i int) bool
// IsValid returns true if value at index is not null.
// NOTE: IsValid will panic if NullBitmapBytes is not empty and 0 > i ≥ Len.
IsValid(i int) bool
// Len returns the number of elements in the array.
Len() int
// Retain increases the reference count by 1.
// Retain may be called simultaneously from multiple goroutines.
Retain()
// Release decreases the reference count by 1.
// Release may be called simultaneously from multiple goroutines.
// When the reference count goes to zero, the memory is freed.
Release()
}
// Builder provides an interface to build arrow arrays.
//
// This type is derived from the arrow array.Builder interface.
type Builder interface {
// Retain increases the reference count by 1.
// Retain may be called simultaneously from multiple goroutines.
Retain()
// Release decreases the reference count by 1.
Release()
// Len returns the number of elements in the array builder.
Len() int
// Cap returns the total number of elements that can be stored
// without allocating additional memory.
Cap() int
// NullN returns the number of null values in the array builder.
NullN() int
// AppendNull adds a new null value to the array being built.
AppendNull()
// Reserve ensures there is enough space for appending n elements
// by checking the capacity and calling Resize if necessary.
Reserve(n int)
// Resize adjusts the space allocated by b to n elements. If n is greater than b.Cap(),
// additional memory will be allocated. If n is smaller, the allocated memory may reduced.
Resize(n int)
// NewArray creates a new array from the memory buffers used
// by the builder and resets the Builder so it can be used to build
// a new array.
NewArray() Interface
}
type String struct {
value string
length int
data *array.Binary
}
func (a *String) DataType() DataType {
return StringType
}
func (a *String) NullN() int {
if a.data != nil {
return a.data.NullN()
}
return 0
}
func (a *String) NullBitmapBytes() []byte {
if a.data != nil {
return a.data.NullBitmapBytes()
}
return nil
}
func (a *String) IsNull(i int) bool {
if a.data != nil {
return a.data.IsNull(i)
}
return false
}
func (a *String) IsValid(i int) bool {
if a.data != nil {
return a.data.IsValid(i)
}
return true
}
func (a *String) Len() int {
if a.data != nil {
return a.data.Len()
}
return a.length
}
func (a *String) Retain() {
if a.data != nil {
a.data.Retain()
}
}
func (a *String) Release() {
if a.data != nil {
a.data.Release()
}
}
func (a *String) Slice(i, j int) Interface {
if a.data != nil {
data := array.NewSliceData(a.data.Data(), int64(i), int64(j))
defer data.Release()
return &String{
data: array.NewBinaryData(data),
}
}
return &String{
value: a.value,
length: j - i,
}
}
func (a *String) Value(i int) string {
if a.data != nil {
return a.data.ValueString(i)
}
return a.value
}
func (a *String) ValueLen(i int) int {
if a.data != nil {
return a.data.ValueLen(i)
}
return len(a.value)
}
type sliceable interface {
Slice(i, j int) Interface
}
// Slice will construct a new slice of the array using the given
// start and stop index. The returned array must be released.
//
// This is functionally equivalent to using array.NewSlice,
// but array.NewSlice will construct an array.String when
// the data type is a string rather than an array.Binary.
func Slice(arr Interface, i, j int) Interface {
if arr, ok := arr.(sliceable); ok {
return arr.Slice(i, j)
}
if arr, ok := arr.(array.Interface); ok {
return array.NewSlice(arr, int64(i), int64(j))
}
err := errors.Newf(codes.Internal, "cannot slice array of type %T", arr)
panic(err)
}