]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/compare_test.go
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / compare_test.go
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package arrow
18
19 import (
20 "testing"
21 )
22
23 func TestTypeEqual(t *testing.T) {
24 tests := []struct {
25 left, right DataType
26 want bool
27 checkMetadata bool
28 }{
29 {
30 nil, nil, true, false,
31 },
32 {
33 nil, PrimitiveTypes.Uint8, false, false,
34 },
35 {
36 PrimitiveTypes.Float32, nil, false, false,
37 },
38 {
39 PrimitiveTypes.Float64, PrimitiveTypes.Int32, false, false,
40 },
41 {
42 Null, Null, true, false,
43 },
44 {
45 &BinaryType{}, &StringType{}, false, false,
46 },
47 {
48 &Time32Type{Unit: Second}, &Time32Type{Unit: Second}, true, false,
49 },
50 {
51 &Time32Type{Unit: Millisecond}, &Time32Type{Unit: Second}, false, false,
52 },
53 {
54 &Time64Type{Unit: Nanosecond}, &Time64Type{Unit: Nanosecond}, true, false,
55 },
56 {
57 &Time64Type{Unit: Nanosecond}, &Time64Type{Unit: Microsecond}, false, false,
58 },
59 {
60 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Second, TimeZone: "UTC"}, true, false,
61 },
62 {
63 &TimestampType{Unit: Microsecond, TimeZone: "UTC"}, &TimestampType{Unit: Millisecond, TimeZone: "UTC"}, false, false,
64 },
65 {
66 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Second, TimeZone: "CET"}, false, false,
67 },
68 {
69 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Nanosecond, TimeZone: "CET"}, false, false,
70 },
71 {
72 &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, true, false,
73 },
74 {
75 &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, &ListType{elem: Field{Type: PrimitiveTypes.Uint32}}, false, false,
76 },
77 {
78 &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, true, false,
79 },
80 {
81 &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, &ListType{elem: Field{Type: &Time32Type{Unit: Second}}}, false, false,
82 },
83 {
84 &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, true, false,
85 },
86 {
87 &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint8}}}}, false, false,
88 },
89 {
90 &ListType{elem: Field{Type: &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}}}, &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint8}}}}, false, false,
91 },
92 {
93 &StructType{
94 fields: []Field{
95 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
96 },
97 index: map[string]int{"f1": 0},
98 },
99 &StructType{
100 fields: []Field{
101 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
102 },
103 index: map[string]int{"f1": 0},
104 },
105 false, true,
106 },
107 {
108 &StructType{
109 fields: []Field{
110 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: false},
111 },
112 index: map[string]int{"f1": 0},
113 },
114 &StructType{
115 fields: []Field{
116 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
117 },
118 index: map[string]int{"f1": 0},
119 },
120 false, false,
121 },
122 {
123 &StructType{
124 fields: []Field{
125 Field{Name: "f0", Type: PrimitiveTypes.Uint32, Nullable: true},
126 },
127 index: map[string]int{"f0": 0},
128 },
129 &StructType{
130 fields: []Field{
131 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
132 },
133 index: map[string]int{"f1": 0},
134 },
135 false, false,
136 },
137 {
138 &StructType{
139 fields: []Field{
140 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
141 },
142 index: map[string]int{"f1": 0},
143 },
144 &StructType{
145 fields: []Field{
146 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
147 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
148 },
149 index: map[string]int{"f1": 0, "f2": 1},
150 },
151 false, true,
152 },
153 {
154 &StructType{
155 fields: []Field{
156 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
157 },
158 index: map[string]int{"f1": 0},
159 },
160 &StructType{
161 fields: []Field{
162 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
163 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
164 },
165 index: map[string]int{"f1": 0, "f2": 1},
166 },
167 false, false,
168 },
169 {
170 &StructType{
171 fields: []Field{
172 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
173 },
174 index: map[string]int{"f1": 0},
175 },
176 &StructType{
177 fields: []Field{
178 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
179 },
180 index: map[string]int{"f2": 0},
181 },
182 false, false,
183 },
184 {
185 &StructType{
186 fields: []Field{
187 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
188 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
189 },
190 index: map[string]int{"f1": 0, "f2": 1},
191 },
192 &StructType{
193 fields: []Field{
194 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
195 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
196 },
197 index: map[string]int{"f1": 0, "f2": 1},
198 },
199 true, false,
200 },
201 {
202 &StructType{
203 fields: []Field{
204 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
205 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
206 },
207 index: map[string]int{"f1": 0, "f2": 1},
208 },
209 &StructType{
210 fields: []Field{
211 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
212 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
213 },
214 index: map[string]int{"f1": 0, "f2": 1},
215 },
216 true, false,
217 },
218 {
219 &StructType{
220 fields: []Field{
221 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
222 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
223 },
224 index: map[string]int{"f1": 0, "f2": 1},
225 meta: MetadataFrom(map[string]string{"k1": "v1", "k2": "v2"}),
226 },
227 &StructType{
228 fields: []Field{
229 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
230 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
231 },
232 index: map[string]int{"f1": 0, "f2": 1},
233 meta: MetadataFrom(map[string]string{"k2": "v2", "k1": "v1"}),
234 },
235 true, true,
236 },
237 {
238 &StructType{
239 fields: []Field{
240 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
241 },
242 index: map[string]int{"f1": 0},
243 meta: MetadataFrom(map[string]string{"k1": "v1"}),
244 },
245 &StructType{
246 fields: []Field{
247 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
248 },
249 index: map[string]int{"f1": 0},
250 meta: MetadataFrom(map[string]string{"k1": "v2"}),
251 },
252 true, false,
253 },
254 {
255 &StructType{
256 fields: []Field{
257 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true, Metadata: MetadataFrom(map[string]string{"k1": "v1"})},
258 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
259 },
260 index: map[string]int{"f1": 0, "f2": 1},
261 },
262 &StructType{
263 fields: []Field{
264 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true, Metadata: MetadataFrom(map[string]string{"k1": "v2"})},
265 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
266 },
267 index: map[string]int{"f1": 0, "f2": 1},
268 },
269 false, true,
270 },
271 }
272
273 for _, test := range tests {
274 t.Run("", func(t *testing.T) {
275 var got bool
276 if test.checkMetadata {
277 got = TypeEqual(test.left, test.right, CheckMetadata())
278 } else {
279 got = TypeEqual(test.left, test.right)
280 }
281 if got != test.want {
282 t.Fatalf("TypeEqual(%v, %v, %v): got=%v, want=%v", test.left, test.right, test.checkMetadata, got, test.want)
283 }
284 })
285 }
286 }