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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
23 func TestTypeEqual(t *testing.T) {
30 nil, nil, true, false,
33 nil, PrimitiveTypes.Uint8, false, false,
36 PrimitiveTypes.Float32, nil, false, false,
39 PrimitiveTypes.Float64, PrimitiveTypes.Int32, false, false,
42 Null, Null, true, false,
45 &BinaryType{}, &StringType{}, false, false,
48 &Time32Type{Unit: Second}, &Time32Type{Unit: Second}, true, false,
51 &Time32Type{Unit: Millisecond}, &Time32Type{Unit: Second}, false, false,
54 &Time64Type{Unit: Nanosecond}, &Time64Type{Unit: Nanosecond}, true, false,
57 &Time64Type{Unit: Nanosecond}, &Time64Type{Unit: Microsecond}, false, false,
60 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Second, TimeZone: "UTC"}, true, false,
63 &TimestampType{Unit: Microsecond, TimeZone: "UTC"}, &TimestampType{Unit: Millisecond, TimeZone: "UTC"}, false, false,
66 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Second, TimeZone: "CET"}, false, false,
69 &TimestampType{Unit: Second, TimeZone: "UTC"}, &TimestampType{Unit: Nanosecond, TimeZone: "CET"}, false, false,
72 &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, true, false,
75 &ListType{elem: Field{Type: PrimitiveTypes.Uint64}}, &ListType{elem: Field{Type: PrimitiveTypes.Uint32}}, false, false,
78 &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, true, false,
81 &ListType{elem: Field{Type: &Time32Type{Unit: Millisecond}}}, &ListType{elem: Field{Type: &Time32Type{Unit: Second}}}, false, false,
84 &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, true, false,
87 &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint16}}}}, &ListType{elem: Field{Type: &ListType{elem: Field{Type: PrimitiveTypes.Uint8}}}}, false, false,
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,
95 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
97 index: map[string]int{"f1": 0},
101 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
103 index: map[string]int{"f1": 0},
110 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: false},
112 index: map[string]int{"f1": 0},
116 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
118 index: map[string]int{"f1": 0},
125 Field{Name: "f0", Type: PrimitiveTypes.Uint32, Nullable: true},
127 index: map[string]int{"f0": 0},
131 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
133 index: map[string]int{"f1": 0},
140 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
142 index: map[string]int{"f1": 0},
146 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
147 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
149 index: map[string]int{"f1": 0, "f2": 1},
156 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
158 index: map[string]int{"f1": 0},
162 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
163 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
165 index: map[string]int{"f1": 0, "f2": 1},
172 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
174 index: map[string]int{"f1": 0},
178 Field{Name: "f2", Type: PrimitiveTypes.Uint32, Nullable: true},
180 index: map[string]int{"f2": 0},
187 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
188 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
190 index: map[string]int{"f1": 0, "f2": 1},
194 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
195 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
197 index: map[string]int{"f1": 0, "f2": 1},
204 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
205 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
207 index: map[string]int{"f1": 0, "f2": 1},
211 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
212 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
214 index: map[string]int{"f1": 0, "f2": 1},
221 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
222 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
224 index: map[string]int{"f1": 0, "f2": 1},
225 meta: MetadataFrom(map[string]string{"k1": "v1", "k2": "v2"}),
229 Field{Name: "f1", Type: PrimitiveTypes.Uint16, Nullable: true},
230 Field{Name: "f2", Type: PrimitiveTypes.Float32, Nullable: false},
232 index: map[string]int{"f1": 0, "f2": 1},
233 meta: MetadataFrom(map[string]string{"k2": "v2", "k1": "v1"}),
240 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
242 index: map[string]int{"f1": 0},
243 meta: MetadataFrom(map[string]string{"k1": "v1"}),
247 Field{Name: "f1", Type: PrimitiveTypes.Uint32, Nullable: true},
249 index: map[string]int{"f1": 0},
250 meta: MetadataFrom(map[string]string{"k1": "v2"}),
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},
260 index: map[string]int{"f1": 0, "f2": 1},
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},
267 index: map[string]int{"f1": 0, "f2": 1},
273 for _, test := range tests {
274 t.Run("", func(t *testing.T) {
276 if test.checkMetadata {
277 got = TypeEqual(test.left, test.right, CheckMetadata())
279 got = TypeEqual(test.left, test.right)
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)