Skip to content

Commit ea68cd5

Browse files
committed
add tests for time 32 array
1 parent 83eb131 commit ea68cd5

2 files changed

Lines changed: 140 additions & 2 deletions

File tree

go/arrow/array/numeric_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,133 @@ func TestFloat64SliceDataWithNull(t *testing.T) {
134134
t.Fatalf("got=%v, want=%v", got, want)
135135
}
136136
}
137+
138+
func TestNewTime32Data(t *testing.T) {
139+
data := []arrow.Time32{
140+
arrow.Time32(1),
141+
arrow.Time32(2),
142+
arrow.Time32(4),
143+
arrow.Time32(8),
144+
arrow.Time32(16),
145+
}
146+
147+
dtype := arrow.FixedWidthTypes.Time32s
148+
ad := array.NewData(dtype, len(data),
149+
[]*memory.Buffer{nil, memory.NewBufferBytes(arrow.Time32Traits.CastToBytes(data))},
150+
nil, 0, 0,
151+
)
152+
t32a := array.NewTime32Data(ad)
153+
154+
assert.Equal(t, len(data), t32a.Len(), "unexpected Len()")
155+
assert.Equal(t, data, t32a.Time32Values(), "unexpected Float64Values()")
156+
}
157+
158+
func TestTime32SliceData(t *testing.T) {
159+
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
160+
defer pool.AssertSize(t, 0)
161+
162+
const (
163+
beg = 2
164+
end = 4
165+
)
166+
167+
var (
168+
vs = []arrow.Time32{
169+
arrow.Time32(1),
170+
arrow.Time32(2),
171+
arrow.Time32(4),
172+
arrow.Time32(8),
173+
arrow.Time32(16),
174+
}
175+
sub = vs[beg:end]
176+
)
177+
178+
dtype := arrow.FixedWidthTypes.Time32s
179+
b := array.NewTime32Builder(pool, dtype.(*arrow.Time32Type))
180+
defer b.Release()
181+
182+
for _, v := range vs {
183+
b.Append(v)
184+
}
185+
186+
arr := b.NewArray().(*array.Time32)
187+
defer arr.Release()
188+
189+
if got, want := arr.Len(), len(vs); got != want {
190+
t.Fatalf("got=%d, want=%d", got, want)
191+
}
192+
193+
if got, want := arr.Time32Values(), vs; !reflect.DeepEqual(got, want) {
194+
t.Fatalf("got=%v, want=%v", got, want)
195+
}
196+
197+
slice := array.NewSlice(arr, beg, end).(*array.Time32)
198+
defer slice.Release()
199+
200+
if got, want := slice.Len(), len(sub); got != want {
201+
t.Fatalf("got=%d, want=%d", got, want)
202+
}
203+
204+
if got, want := slice.Time32Values(), sub; !reflect.DeepEqual(got, want) {
205+
t.Fatalf("got=%v, want=%v", got, want)
206+
}
207+
}
208+
209+
func TestTime32SliceDataWithNull(t *testing.T) {
210+
pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
211+
defer pool.AssertSize(t, 0)
212+
213+
const (
214+
beg = 2
215+
end = 5
216+
)
217+
218+
var (
219+
valids = []bool{true, true, true, false, true, true}
220+
vs = []arrow.Time32{
221+
arrow.Time32(1),
222+
arrow.Time32(2),
223+
arrow.Time32(3),
224+
arrow.Time32(0),
225+
arrow.Time32(4),
226+
arrow.Time32(5),
227+
}
228+
sub = vs[beg:end]
229+
)
230+
231+
dtype := arrow.FixedWidthTypes.Time32s
232+
b := array.NewTime32Builder(pool, dtype.(*arrow.Time32Type))
233+
defer b.Release()
234+
235+
b.AppendValues(vs, valids)
236+
237+
arr := b.NewArray().(*array.Time32)
238+
defer arr.Release()
239+
240+
if got, want := arr.Len(), len(valids); got != want {
241+
t.Fatalf("got=%d, want=%d", got, want)
242+
}
243+
244+
if got, want := arr.NullN(), 1; got != want {
245+
t.Fatalf("got=%d, want=%d", got, want)
246+
}
247+
248+
if got, want := arr.Time32Values(), vs; !reflect.DeepEqual(got, want) {
249+
t.Fatalf("got=%v, want=%v", got, want)
250+
}
251+
252+
slice := array.NewSlice(arr, beg, end).(*array.Time32)
253+
defer slice.Release()
254+
255+
if got, want := slice.NullN(), 1; got != want {
256+
t.Errorf("got=%d, want=%d", got, want)
257+
}
258+
259+
if got, want := slice.Len(), len(sub); got != want {
260+
t.Fatalf("got=%d, want=%d", got, want)
261+
}
262+
263+
if got, want := slice.Time32Values(), sub; !reflect.DeepEqual(got, want) {
264+
t.Fatalf("got=%v, want=%v", got, want)
265+
}
266+
}

go/arrow/datatype_fixedwidth.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ func (*Time64Type) BitWidth() int { return 64 }
7474

7575
var (
7676
FixedWidthTypes = struct {
77-
Boolean FixedWidthDataType
77+
Boolean FixedWidthDataType
78+
Time32s FixedWidthDataType
79+
Time32ms FixedWidthDataType
80+
Time32µs FixedWidthDataType
81+
Time32ns FixedWidthDataType
7882
}{
79-
Boolean: &BooleanType{},
83+
Boolean: &BooleanType{},
84+
Time32s: &Time32Type{Unit: Second},
85+
Time32ms: &Time32Type{Unit: Millisecond},
86+
Time32µs: &Time32Type{Unit: Microsecond},
87+
Time32ns: &Time32Type{Unit: Nanosecond},
8088
}
8189
)

0 commit comments

Comments
 (0)