Skip to content

Commit e141624

Browse files
committed
use single roundtrip test
1 parent 2956e06 commit e141624

5 files changed

Lines changed: 102 additions & 296 deletions

File tree

types/extensions_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package types
2+
3+
import (
4+
"testing"
5+
6+
"github.com/apache/arrow/go/v12/arrow"
7+
"github.com/apache/arrow/go/v12/arrow/array"
8+
"github.com/apache/arrow/go/v12/arrow/memory"
9+
"github.com/google/uuid"
10+
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
12+
)
13+
14+
func TestValueStrRoundTrip(t *testing.T) {
15+
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
16+
defer mem.AssertSize(t, 0)
17+
18+
cases := []struct {
19+
arr arrow.Array
20+
builder array.Builder
21+
}{
22+
{
23+
arr: func() arrow.Array {
24+
b := NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType()))
25+
defer b.Release()
26+
27+
b.AppendNull()
28+
b.Append(mustParseInet("192.168.0.0/24"))
29+
b.AppendNull()
30+
b.Append(mustParseInet("192.168.0.0/25"))
31+
b.AppendNull()
32+
33+
return b.NewInetArray()
34+
}(),
35+
builder: NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType())),
36+
},
37+
{
38+
arr: func() arrow.Array {
39+
b := NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType()))
40+
defer b.Release()
41+
42+
b.AppendNull()
43+
b.Append(map[string]any{"a": 1, "b": 2})
44+
b.AppendNull()
45+
b.Append([]any{1, 2, 3})
46+
b.AppendNull()
47+
b.Append(map[string]any{"MyKey": "A\u0026B"})
48+
b.AppendNull()
49+
50+
return b.NewJSONArray()
51+
}(),
52+
builder: NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType())),
53+
},
54+
{
55+
arr: func() arrow.Array {
56+
b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
57+
defer b.Release()
58+
59+
b.AppendNull()
60+
b.Append(mustParseMac("00:00:00:00:00:01"))
61+
b.AppendNull()
62+
b.Append(mustParseMac("00:00:00:00:00:02"))
63+
b.AppendNull()
64+
65+
return b.NewMacArray()
66+
}(),
67+
builder: NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType())),
68+
},
69+
{
70+
arr: func() arrow.Array {
71+
b := NewUUIDBuilder(array.NewExtensionBuilder(mem, NewUUIDType()))
72+
defer b.Release()
73+
74+
b.AppendNull()
75+
b.Append(uuid.NameSpaceURL)
76+
b.AppendNull()
77+
b.Append(uuid.NameSpaceDNS)
78+
b.AppendNull()
79+
80+
return b.NewUUIDArray()
81+
}(),
82+
builder: NewUUIDBuilder(array.NewExtensionBuilder(mem, NewUUIDType())),
83+
},
84+
}
85+
86+
for _, tc := range cases {
87+
t.Run(tc.arr.DataType().(arrow.ExtensionType).ExtensionName(), func(t *testing.T) {
88+
defer tc.arr.Release()
89+
defer tc.builder.Release()
90+
t.Helper()
91+
92+
for i := 0; i < tc.arr.Len(); i++ {
93+
assert.NoError(t, tc.builder.AppendValueFromString(tc.arr.ValueStr(i)))
94+
}
95+
96+
arr := tc.builder.NewArray()
97+
defer arr.Release()
98+
99+
require.True(t, array.Equal(tc.arr, arr))
100+
})
101+
}
102+
}

types/inet_test.go

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/apache/arrow/go/v12/arrow/array"
88
"github.com/apache/arrow/go/v12/arrow/memory"
9-
"github.com/stretchr/testify/assert"
109
"github.com/stretchr/testify/require"
1110
)
1211

@@ -63,75 +62,3 @@ func TestInetBuilder(t *testing.T) {
6362
b.Release()
6463
a.Release()
6564
}
66-
67-
func TestInetArray_ValueStr(t *testing.T) {
68-
// 1. create array
69-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
70-
defer mem.AssertSize(t, 0)
71-
72-
b := NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType()))
73-
defer b.Release()
74-
75-
b.AppendNull()
76-
b.Append(mustParseInet("192.168.0.0/24"))
77-
b.AppendNull()
78-
b.Append(mustParseInet("192.168.0.0/25"))
79-
b.AppendNull()
80-
81-
arr := b.NewInetArray()
82-
defer arr.Release()
83-
84-
// 2. create array via AppendValueFromString
85-
b1 := NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType()))
86-
defer b1.Release()
87-
88-
for i := 0; i < arr.Len(); i++ {
89-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
90-
}
91-
92-
arr1 := b1.NewInetArray()
93-
defer arr1.Release()
94-
95-
assert.Equal(t, arr.Len(), arr1.Len())
96-
for i := 0; i < arr.Len(); i++ {
97-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
98-
assert.Equal(t, arr.ValueStr(i), arr1.ValueStr(i))
99-
}
100-
}
101-
102-
func TestInetBuilder_AppendValueFromString(t *testing.T) {
103-
// 1. create array
104-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
105-
defer mem.AssertSize(t, 0)
106-
107-
b := NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType()))
108-
defer b.Release()
109-
110-
b.AppendNull()
111-
b.Append(mustParseInet("192.168.0.0/24"))
112-
b.AppendNull()
113-
b.Append(mustParseInet("192.168.0.0/25"))
114-
b.AppendNull()
115-
116-
arr := b.NewInetArray()
117-
defer arr.Release()
118-
119-
// 2. create array via AppendValueFromString
120-
b1 := NewInetBuilder(array.NewExtensionBuilder(mem, NewInetType()))
121-
defer b1.Release()
122-
123-
for i := 0; i < arr.Len(); i++ {
124-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
125-
}
126-
127-
arr1 := b1.NewInetArray()
128-
defer arr1.Release()
129-
130-
assert.Equal(t, arr.Len(), arr1.Len())
131-
for i := 0; i < arr.Len(); i++ {
132-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
133-
if arr.IsValid(i) {
134-
assert.Exactly(t, arr.Value(i), arr1.Value(i))
135-
}
136-
}
137-
}

types/json_test.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/apache/arrow/go/v12/arrow/array"
99
"github.com/apache/arrow/go/v12/arrow/memory"
1010
"github.com/goccy/go-json"
11-
"github.com/stretchr/testify/assert"
1211
"github.com/stretchr/testify/require"
1312
)
1413

@@ -230,82 +229,6 @@ func TestJSONArray_ValueStrParse(t *testing.T) {
230229
}
231230
}
232231

233-
func TestJSONArray_ValueStr(t *testing.T) {
234-
// 1. create array
235-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
236-
defer mem.AssertSize(t, 0)
237-
238-
b := NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType()))
239-
defer b.Release()
240-
241-
b.AppendNull()
242-
b.Append(map[string]any{"a": 1, "b": 2})
243-
b.AppendNull()
244-
b.Append([]any{1, 2, 3})
245-
b.AppendNull()
246-
b.Append(map[string]any{"MyKey": "A\u0026B"})
247-
b.AppendNull()
248-
249-
arr := b.NewJSONArray()
250-
defer arr.Release()
251-
252-
// 2. create array via AppendValueFromString
253-
b1 := NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType()))
254-
defer b1.Release()
255-
256-
for i := 0; i < arr.Len(); i++ {
257-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
258-
}
259-
260-
arr1 := b1.NewJSONArray()
261-
defer arr1.Release()
262-
263-
assert.Equal(t, arr.Len(), arr1.Len())
264-
for i := 0; i < arr.Len(); i++ {
265-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
266-
assert.Equal(t, arr.ValueStr(i), arr1.ValueStr(i))
267-
}
268-
}
269-
270-
func TestJSONBuilder_AppendValueFromString(t *testing.T) {
271-
// 1. create array
272-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
273-
defer mem.AssertSize(t, 0)
274-
275-
b := NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType()))
276-
defer b.Release()
277-
278-
b.AppendNull()
279-
b.Append(map[string]any{"a": 1, "b": 2})
280-
b.AppendNull()
281-
b.Append([]any{1, 2, 3})
282-
b.AppendNull()
283-
b.Append(map[string]any{"MyKey": "A\u0026B"})
284-
b.AppendNull()
285-
286-
arr := b.NewJSONArray()
287-
defer arr.Release()
288-
289-
// 2. create array via AppendValueFromString
290-
b1 := NewJSONBuilder(array.NewExtensionBuilder(mem, NewJSONType()))
291-
defer b1.Release()
292-
293-
for i := 0; i < arr.Len(); i++ {
294-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
295-
}
296-
297-
arr1 := b1.NewJSONArray()
298-
defer arr1.Release()
299-
300-
assert.Equal(t, arr.Len(), arr1.Len())
301-
for i := 0; i < arr.Len(); i++ {
302-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
303-
if arr.IsValid(i) {
304-
assert.Exactly(t, arr.Value(i), arr1.Value(i))
305-
}
306-
}
307-
}
308-
309232
func TestJSONArray_Value(t *testing.T) {
310233
cases := []struct {
311234
name string

types/mac_test.go

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/apache/arrow/go/v12/arrow/array"
88
"github.com/apache/arrow/go/v12/arrow/memory"
9-
"github.com/stretchr/testify/assert"
109
"github.com/stretchr/testify/require"
1110
)
1211

@@ -63,75 +62,3 @@ func TestMacBuilder(t *testing.T) {
6362
b.Release()
6463
a.Release()
6564
}
66-
67-
func TestMacArray_ValueStr(t *testing.T) {
68-
// 1. create array
69-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
70-
defer mem.AssertSize(t, 0)
71-
72-
b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
73-
defer b.Release()
74-
75-
b.AppendNull()
76-
b.Append(mustParseMac("00:00:00:00:00:01"))
77-
b.AppendNull()
78-
b.Append(mustParseMac("00:00:00:00:00:02"))
79-
b.AppendNull()
80-
81-
arr := b.NewMacArray()
82-
defer arr.Release()
83-
84-
// 2. create array via AppendValueFromString
85-
b1 := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
86-
defer b1.Release()
87-
88-
for i := 0; i < arr.Len(); i++ {
89-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
90-
}
91-
92-
arr1 := b1.NewMacArray()
93-
defer arr1.Release()
94-
95-
assert.Equal(t, arr.Len(), arr1.Len())
96-
for i := 0; i < arr.Len(); i++ {
97-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
98-
assert.Equal(t, arr.ValueStr(i), arr1.ValueStr(i))
99-
}
100-
}
101-
102-
func TestMacBuilder_AppendValueFromString(t *testing.T) {
103-
// 1. create array
104-
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
105-
defer mem.AssertSize(t, 0)
106-
107-
b := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
108-
defer b.Release()
109-
110-
b.AppendNull()
111-
b.Append(mustParseMac("00:00:00:00:00:01"))
112-
b.AppendNull()
113-
b.Append(mustParseMac("00:00:00:00:00:02"))
114-
b.AppendNull()
115-
116-
arr := b.NewMacArray()
117-
defer arr.Release()
118-
119-
// 2. create array via AppendValueFromString
120-
b1 := NewMacBuilder(array.NewExtensionBuilder(mem, NewMacType()))
121-
defer b1.Release()
122-
123-
for i := 0; i < arr.Len(); i++ {
124-
assert.NoError(t, b1.AppendValueFromString(arr.ValueStr(i)))
125-
}
126-
127-
arr1 := b1.NewMacArray()
128-
defer arr1.Release()
129-
130-
assert.Equal(t, arr.Len(), arr1.Len())
131-
for i := 0; i < arr.Len(); i++ {
132-
assert.Equal(t, arr.IsValid(i), arr1.IsValid(i))
133-
if arr.IsValid(i) {
134-
assert.Exactly(t, arr.Value(i), arr1.Value(i))
135-
}
136-
}
137-
}

0 commit comments

Comments
 (0)