]>
Commit | Line | Data |
---|---|---|
1d09f67e TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * 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 | ||
18 | package org.apache.arrow.vector.validate; | |
19 | ||
20 | import static org.junit.jupiter.api.Assertions.assertThrows; | |
21 | ||
22 | import java.util.function.Supplier; | |
23 | ||
24 | import org.apache.arrow.memory.BufferAllocator; | |
25 | import org.apache.arrow.memory.RootAllocator; | |
26 | import org.apache.arrow.vector.BigIntVector; | |
27 | import org.apache.arrow.vector.BitVector; | |
28 | import org.apache.arrow.vector.DateDayVector; | |
29 | import org.apache.arrow.vector.DateMilliVector; | |
30 | import org.apache.arrow.vector.DecimalVector; | |
31 | import org.apache.arrow.vector.DurationVector; | |
32 | import org.apache.arrow.vector.FixedSizeBinaryVector; | |
33 | import org.apache.arrow.vector.Float4Vector; | |
34 | import org.apache.arrow.vector.Float8Vector; | |
35 | import org.apache.arrow.vector.IntVector; | |
36 | import org.apache.arrow.vector.IntervalDayVector; | |
37 | import org.apache.arrow.vector.IntervalYearVector; | |
38 | import org.apache.arrow.vector.LargeVarBinaryVector; | |
39 | import org.apache.arrow.vector.LargeVarCharVector; | |
40 | import org.apache.arrow.vector.NullVector; | |
41 | import org.apache.arrow.vector.SmallIntVector; | |
42 | import org.apache.arrow.vector.TimeMicroVector; | |
43 | import org.apache.arrow.vector.TimeMilliVector; | |
44 | import org.apache.arrow.vector.TimeNanoVector; | |
45 | import org.apache.arrow.vector.TimeSecVector; | |
46 | import org.apache.arrow.vector.TimeStampMicroTZVector; | |
47 | import org.apache.arrow.vector.TimeStampMicroVector; | |
48 | import org.apache.arrow.vector.TimeStampMilliTZVector; | |
49 | import org.apache.arrow.vector.TimeStampMilliVector; | |
50 | import org.apache.arrow.vector.TimeStampNanoTZVector; | |
51 | import org.apache.arrow.vector.TimeStampNanoVector; | |
52 | import org.apache.arrow.vector.TimeStampSecTZVector; | |
53 | import org.apache.arrow.vector.TimeStampSecVector; | |
54 | import org.apache.arrow.vector.TinyIntVector; | |
55 | import org.apache.arrow.vector.UInt1Vector; | |
56 | import org.apache.arrow.vector.UInt2Vector; | |
57 | import org.apache.arrow.vector.UInt4Vector; | |
58 | import org.apache.arrow.vector.UInt8Vector; | |
59 | import org.apache.arrow.vector.ValueVector; | |
60 | import org.apache.arrow.vector.VarBinaryVector; | |
61 | import org.apache.arrow.vector.VarCharVector; | |
62 | import org.apache.arrow.vector.complex.DenseUnionVector; | |
63 | import org.apache.arrow.vector.complex.FixedSizeListVector; | |
64 | import org.apache.arrow.vector.complex.LargeListVector; | |
65 | import org.apache.arrow.vector.complex.ListVector; | |
66 | import org.apache.arrow.vector.complex.StructVector; | |
67 | import org.apache.arrow.vector.complex.UnionVector; | |
68 | import org.apache.arrow.vector.types.TimeUnit; | |
69 | import org.apache.arrow.vector.types.Types; | |
70 | import org.apache.arrow.vector.types.pojo.ArrowType; | |
71 | import org.apache.arrow.vector.types.pojo.FieldType; | |
72 | import org.junit.After; | |
73 | import org.junit.Before; | |
74 | import org.junit.Test; | |
75 | ||
76 | /** | |
77 | * Test cases for {@link ValidateVectorTypeVisitor}. | |
78 | */ | |
79 | public class TestValidateVectorTypeVisitor { | |
80 | ||
81 | private BufferAllocator allocator; | |
82 | ||
83 | private ValidateVectorTypeVisitor visitor = new ValidateVectorTypeVisitor(); | |
84 | ||
85 | @Before | |
86 | public void init() { | |
87 | allocator = new RootAllocator(Long.MAX_VALUE); | |
88 | } | |
89 | ||
90 | @After | |
91 | public void terminate() throws Exception { | |
92 | allocator.close(); | |
93 | } | |
94 | ||
95 | private void testPositiveCase(Supplier<ValueVector> vectorGenerator) { | |
96 | try (ValueVector vector = vectorGenerator.get();) { | |
97 | vector.accept(visitor, null); | |
98 | } | |
99 | } | |
100 | ||
101 | private void testNegativeCase(Supplier<ValueVector> vectorGenerator) { | |
102 | try (ValueVector vector = vectorGenerator.get()) { | |
103 | assertThrows(ValidateUtil.ValidateException.class, () -> { | |
104 | vector.accept(visitor, null); | |
105 | }); | |
106 | } | |
107 | } | |
108 | ||
109 | @Test | |
110 | public void testFixedWidthVectorsPositive() { | |
111 | // integer vectors | |
112 | testPositiveCase(() -> new TinyIntVector("vector", allocator)); | |
113 | testPositiveCase(() -> new SmallIntVector("vector", allocator)); | |
114 | testPositiveCase(() -> new IntVector("vector", allocator)); | |
115 | testPositiveCase(() -> new BigIntVector("vector", allocator)); | |
116 | testPositiveCase(() -> new UInt1Vector("vector", allocator)); | |
117 | testPositiveCase(() -> new UInt2Vector("vector", allocator)); | |
118 | testPositiveCase(() -> new UInt4Vector("vector", allocator)); | |
119 | testPositiveCase(() -> new UInt8Vector("vector", allocator)); | |
120 | ||
121 | testPositiveCase(() -> new BitVector("vector", allocator)); | |
122 | testPositiveCase(() -> new DecimalVector("vector", allocator, 30, 16)); | |
123 | ||
124 | // date vectors | |
125 | testPositiveCase(() -> new DateDayVector("vector", allocator)); | |
126 | testPositiveCase(() -> new DateMilliVector("vector", allocator)); | |
127 | ||
128 | testPositiveCase(() -> new DurationVector( | |
129 | "vector", FieldType.nullable(new ArrowType.Duration(TimeUnit.SECOND)), allocator)); | |
130 | ||
131 | // float vectors | |
132 | testPositiveCase(() -> new Float4Vector("vector", allocator)); | |
133 | testPositiveCase(() -> new Float8Vector("vector", allocator)); | |
134 | ||
135 | // interval vectors | |
136 | testPositiveCase(() -> new IntervalDayVector("vector", allocator)); | |
137 | testPositiveCase(() -> new IntervalYearVector("vector", allocator)); | |
138 | ||
139 | // time vectors | |
140 | testPositiveCase(() -> new TimeMicroVector("vector", allocator)); | |
141 | testPositiveCase(() -> new TimeMilliVector("vector", allocator)); | |
142 | testPositiveCase(() -> new TimeMicroVector("vector", allocator)); | |
143 | testPositiveCase(() -> new TimeSecVector("vector", allocator)); | |
144 | ||
145 | // time stamp vectors | |
146 | testPositiveCase(() -> new TimeStampMicroTZVector("vector", allocator, "cn")); | |
147 | testPositiveCase(() -> new TimeStampMicroVector("vector", allocator)); | |
148 | testPositiveCase(() -> new TimeStampMilliTZVector("vector", allocator, "cn")); | |
149 | testPositiveCase(() -> new TimeStampMilliVector("vector", allocator)); | |
150 | testPositiveCase(() -> new TimeStampNanoTZVector("vector", allocator, "cn")); | |
151 | testPositiveCase(() -> new TimeStampNanoVector("vector", allocator)); | |
152 | testPositiveCase(() -> new TimeStampSecTZVector("vector", allocator, "cn")); | |
153 | testPositiveCase(() -> new TimeStampSecVector("vector", allocator)); | |
154 | ||
155 | testPositiveCase(() -> new FixedSizeBinaryVector("vector", allocator, 5)); | |
156 | } | |
157 | ||
158 | @Test | |
159 | public void testFixedWidthVectorsNegative() { | |
160 | // integer vectors | |
161 | testNegativeCase( | |
162 | () -> new TinyIntVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
163 | testNegativeCase( | |
164 | () -> new SmallIntVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
165 | testNegativeCase( | |
166 | () -> new BigIntVector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
167 | testNegativeCase( | |
168 | () -> new BigIntVector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
169 | testNegativeCase( | |
170 | () -> new UInt1Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
171 | testNegativeCase( | |
172 | () -> new UInt2Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
173 | testNegativeCase( | |
174 | () -> new UInt4Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
175 | testNegativeCase( | |
176 | () -> new UInt8Vector("vector", FieldType.nullable(Types.MinorType.SMALLINT.getType()), allocator)); | |
177 | ||
178 | testNegativeCase( | |
179 | () -> new BitVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
180 | testNegativeCase( | |
181 | () -> new DecimalVector("vector", allocator, 30, -16)); | |
182 | ||
183 | // date vectors | |
184 | testNegativeCase( | |
185 | () -> new DateDayVector("vector", FieldType.nullable(Types.MinorType.FLOAT4.getType()), allocator)); | |
186 | testNegativeCase( | |
187 | () -> new DateMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
188 | ||
189 | // float pont vectors | |
190 | testNegativeCase( | |
191 | () -> new Float4Vector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
192 | testNegativeCase( | |
193 | () -> new Float8Vector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
194 | ||
195 | // interval vectors | |
196 | testNegativeCase( | |
197 | () -> new IntervalDayVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
198 | testNegativeCase( | |
199 | () -> new IntervalYearVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
200 | ||
201 | // time vectors | |
202 | testNegativeCase( | |
203 | () -> new TimeMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
204 | testNegativeCase( | |
205 | () -> new TimeMicroVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
206 | testNegativeCase( | |
207 | () -> new TimeNanoVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
208 | testNegativeCase( | |
209 | () -> new TimeSecVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
210 | ||
211 | // time stamp vectors | |
212 | testNegativeCase( | |
213 | () -> new TimeStampMicroTZVector("vector", allocator, null)); | |
214 | testNegativeCase( | |
215 | () -> new TimeStampMicroVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
216 | testNegativeCase( | |
217 | () -> new TimeStampMilliTZVector("vector", allocator, null)); | |
218 | testNegativeCase( | |
219 | () -> new TimeStampMilliVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
220 | testNegativeCase( | |
221 | () -> new TimeStampNanoTZVector("vector", allocator, null)); | |
222 | testNegativeCase( | |
223 | () -> new TimeStampNanoVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
224 | testNegativeCase( | |
225 | () -> new TimeStampSecTZVector("vector", allocator, null)); | |
226 | testNegativeCase( | |
227 | () -> new TimeStampSecVector("vector", FieldType.nullable(Types.MinorType.BIGINT.getType()), allocator)); | |
228 | } | |
229 | ||
230 | @Test | |
231 | public void testVariableWidthVectorsPositive() { | |
232 | testPositiveCase(() -> new VarCharVector("vector", allocator)); | |
233 | testPositiveCase(() -> new VarBinaryVector("vector", allocator)); | |
234 | } | |
235 | ||
236 | @Test | |
237 | public void testVariableWidthVectorsNegative() { | |
238 | testNegativeCase( | |
239 | () -> new VarCharVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
240 | testNegativeCase( | |
241 | () -> new VarBinaryVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
242 | } | |
243 | ||
244 | @Test | |
245 | public void testLargeVariableWidthVectorsPositive() { | |
246 | testPositiveCase(() -> new LargeVarCharVector("vector", allocator)); | |
247 | testPositiveCase(() -> new LargeVarBinaryVector("vector", allocator)); | |
248 | } | |
249 | ||
250 | @Test | |
251 | public void testLargeVariableWidthVectorsNegative() { | |
252 | testNegativeCase( | |
253 | () -> new LargeVarCharVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
254 | testNegativeCase( | |
255 | () -> new LargeVarBinaryVector("vector", FieldType.nullable(Types.MinorType.INT.getType()), allocator)); | |
256 | } | |
257 | ||
258 | @Test | |
259 | public void testListVector() { | |
260 | testPositiveCase(() -> ListVector.empty("vector", allocator)); | |
261 | ||
262 | testNegativeCase( | |
263 | () -> new ListVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); | |
264 | } | |
265 | ||
266 | @Test | |
267 | public void testLargeListVector() { | |
268 | testPositiveCase(() -> LargeListVector.empty("vector", allocator)); | |
269 | ||
270 | testNegativeCase( | |
271 | () -> new LargeListVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); | |
272 | } | |
273 | ||
274 | @Test | |
275 | public void testFixedSizeListVector() { | |
276 | testPositiveCase(() -> FixedSizeListVector.empty("vector", 10, allocator)); | |
277 | } | |
278 | ||
279 | @Test | |
280 | public void testStructVector() { | |
281 | testPositiveCase(() -> StructVector.empty("vector", allocator)); | |
282 | ||
283 | testNegativeCase( | |
284 | () -> new StructVector("vector", allocator, FieldType.nullable(Types.MinorType.INT.getType()), null)); | |
285 | } | |
286 | ||
287 | @Test | |
288 | public void testUnionVector() { | |
289 | testPositiveCase(() -> UnionVector.empty("vector", allocator)); | |
290 | } | |
291 | ||
292 | @Test | |
293 | public void testDenseUnionVector() { | |
294 | testPositiveCase(() -> DenseUnionVector.empty("vector", allocator)); | |
295 | } | |
296 | ||
297 | @Test | |
298 | public void testNullVector() { | |
299 | testPositiveCase(() -> new NullVector("null vec")); | |
300 | } | |
301 | } |