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
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.
18 package org
.apache
.arrow
.vector
.validate
;
20 import static org
.junit
.jupiter
.api
.Assertions
.assertThrows
;
22 import java
.util
.function
.Supplier
;
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
;
77 * Test cases for {@link ValidateVectorTypeVisitor}.
79 public class TestValidateVectorTypeVisitor
{
81 private BufferAllocator allocator
;
83 private ValidateVectorTypeVisitor visitor
= new ValidateVectorTypeVisitor();
87 allocator
= new RootAllocator(Long
.MAX_VALUE
);
91 public void terminate() throws Exception
{
95 private void testPositiveCase(Supplier
<ValueVector
> vectorGenerator
) {
96 try (ValueVector vector
= vectorGenerator
.get();) {
97 vector
.accept(visitor
, null);
101 private void testNegativeCase(Supplier
<ValueVector
> vectorGenerator
) {
102 try (ValueVector vector
= vectorGenerator
.get()) {
103 assertThrows(ValidateUtil
.ValidateException
.class, () -> {
104 vector
.accept(visitor
, null);
110 public void testFixedWidthVectorsPositive() {
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
));
121 testPositiveCase(() -> new BitVector("vector", allocator
));
122 testPositiveCase(() -> new DecimalVector("vector", allocator
, 30, 16));
125 testPositiveCase(() -> new DateDayVector("vector", allocator
));
126 testPositiveCase(() -> new DateMilliVector("vector", allocator
));
128 testPositiveCase(() -> new DurationVector(
129 "vector", FieldType
.nullable(new ArrowType
.Duration(TimeUnit
.SECOND
)), allocator
));
132 testPositiveCase(() -> new Float4Vector("vector", allocator
));
133 testPositiveCase(() -> new Float8Vector("vector", allocator
));
136 testPositiveCase(() -> new IntervalDayVector("vector", allocator
));
137 testPositiveCase(() -> new IntervalYearVector("vector", allocator
));
140 testPositiveCase(() -> new TimeMicroVector("vector", allocator
));
141 testPositiveCase(() -> new TimeMilliVector("vector", allocator
));
142 testPositiveCase(() -> new TimeMicroVector("vector", allocator
));
143 testPositiveCase(() -> new TimeSecVector("vector", allocator
));
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
));
155 testPositiveCase(() -> new FixedSizeBinaryVector("vector", allocator
, 5));
159 public void testFixedWidthVectorsNegative() {
162 () -> new TinyIntVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
164 () -> new SmallIntVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
166 () -> new BigIntVector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
168 () -> new BigIntVector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
170 () -> new UInt1Vector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
172 () -> new UInt2Vector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
174 () -> new UInt4Vector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
176 () -> new UInt8Vector("vector", FieldType
.nullable(Types
.MinorType
.SMALLINT
.getType()), allocator
));
179 () -> new BitVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
181 () -> new DecimalVector("vector", allocator
, 30, -16));
185 () -> new DateDayVector("vector", FieldType
.nullable(Types
.MinorType
.FLOAT4
.getType()), allocator
));
187 () -> new DateMilliVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
189 // float pont vectors
191 () -> new Float4Vector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
193 () -> new Float8Vector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
197 () -> new IntervalDayVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
199 () -> new IntervalYearVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
203 () -> new TimeMilliVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
205 () -> new TimeMicroVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
207 () -> new TimeNanoVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
209 () -> new TimeSecVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
211 // time stamp vectors
213 () -> new TimeStampMicroTZVector("vector", allocator
, null));
215 () -> new TimeStampMicroVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
217 () -> new TimeStampMilliTZVector("vector", allocator
, null));
219 () -> new TimeStampMilliVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
221 () -> new TimeStampNanoTZVector("vector", allocator
, null));
223 () -> new TimeStampNanoVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
225 () -> new TimeStampSecTZVector("vector", allocator
, null));
227 () -> new TimeStampSecVector("vector", FieldType
.nullable(Types
.MinorType
.BIGINT
.getType()), allocator
));
231 public void testVariableWidthVectorsPositive() {
232 testPositiveCase(() -> new VarCharVector("vector", allocator
));
233 testPositiveCase(() -> new VarBinaryVector("vector", allocator
));
237 public void testVariableWidthVectorsNegative() {
239 () -> new VarCharVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
241 () -> new VarBinaryVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
245 public void testLargeVariableWidthVectorsPositive() {
246 testPositiveCase(() -> new LargeVarCharVector("vector", allocator
));
247 testPositiveCase(() -> new LargeVarBinaryVector("vector", allocator
));
251 public void testLargeVariableWidthVectorsNegative() {
253 () -> new LargeVarCharVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
255 () -> new LargeVarBinaryVector("vector", FieldType
.nullable(Types
.MinorType
.INT
.getType()), allocator
));
259 public void testListVector() {
260 testPositiveCase(() -> ListVector
.empty("vector", allocator
));
263 () -> new ListVector("vector", allocator
, FieldType
.nullable(Types
.MinorType
.INT
.getType()), null));
267 public void testLargeListVector() {
268 testPositiveCase(() -> LargeListVector
.empty("vector", allocator
));
271 () -> new LargeListVector("vector", allocator
, FieldType
.nullable(Types
.MinorType
.INT
.getType()), null));
275 public void testFixedSizeListVector() {
276 testPositiveCase(() -> FixedSizeListVector
.empty("vector", 10, allocator
));
280 public void testStructVector() {
281 testPositiveCase(() -> StructVector
.empty("vector", allocator
));
284 () -> new StructVector("vector", allocator
, FieldType
.nullable(Types
.MinorType
.INT
.getType()), null));
288 public void testUnionVector() {
289 testPositiveCase(() -> UnionVector
.empty("vector", allocator
));
293 public void testDenseUnionVector() {
294 testPositiveCase(() -> DenseUnionVector
.empty("vector", allocator
));
298 public void testNullVector() {
299 testPositiveCase(() -> new NullVector("null vec"));