]>
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; | |
19 | ||
20 | import static org.apache.arrow.vector.complex.BaseRepeatedValueVector.DATA_VECTOR_NAME; | |
21 | ||
22 | import java.util.Collections; | |
23 | import java.util.Iterator; | |
24 | import java.util.List; | |
25 | ||
26 | import org.apache.arrow.memory.ArrowBuf; | |
27 | import org.apache.arrow.memory.BufferAllocator; | |
28 | import org.apache.arrow.memory.OutOfMemoryException; | |
29 | import org.apache.arrow.memory.util.hash.ArrowBufHasher; | |
30 | import org.apache.arrow.util.Preconditions; | |
31 | import org.apache.arrow.vector.compare.VectorVisitor; | |
32 | import org.apache.arrow.vector.complex.impl.NullReader; | |
33 | import org.apache.arrow.vector.complex.reader.FieldReader; | |
34 | import org.apache.arrow.vector.ipc.message.ArrowFieldNode; | |
35 | import org.apache.arrow.vector.types.Types; | |
36 | import org.apache.arrow.vector.types.pojo.ArrowType; | |
37 | import org.apache.arrow.vector.types.pojo.Field; | |
38 | import org.apache.arrow.vector.types.pojo.FieldType; | |
39 | import org.apache.arrow.vector.util.CallBack; | |
40 | import org.apache.arrow.vector.util.TransferPair; | |
41 | ||
42 | /** | |
43 | * A null type vector. | |
44 | */ | |
45 | public class NullVector implements FieldVector { | |
46 | ||
47 | private int valueCount; | |
48 | ||
49 | protected Field field; | |
50 | ||
51 | /** | |
52 | * Instantiate a NullVector. | |
53 | * | |
54 | * @param name name of the vector | |
55 | */ | |
56 | public NullVector(String name) { | |
57 | this(name, FieldType.nullable(Types.MinorType.NULL.getType())); | |
58 | } | |
59 | ||
60 | /** | |
61 | * Instantiate a NullVector. | |
62 | * | |
63 | * @param name name of the vector | |
64 | * @param fieldType type of Field materialized by this vector. | |
65 | */ | |
66 | public NullVector(String name, FieldType fieldType) { | |
67 | this(new Field(name, fieldType, null)); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Instantiate a NullVector. | |
72 | * | |
73 | * @param field field materialized by this vector. | |
74 | */ | |
75 | public NullVector(Field field) { | |
76 | this.valueCount = 0; | |
77 | this.field = field; | |
78 | } | |
79 | ||
80 | @Deprecated | |
81 | public NullVector() { | |
82 | this(new Field(DATA_VECTOR_NAME, FieldType.nullable(new ArrowType.Null()), null)); | |
83 | } | |
84 | ||
85 | @Override | |
86 | public void close() { | |
87 | } | |
88 | ||
89 | @Override | |
90 | public void clear() { | |
91 | } | |
92 | ||
93 | @Override | |
94 | public void reset() { | |
95 | } | |
96 | ||
97 | @Override | |
98 | public Field getField() { | |
99 | return field; | |
100 | } | |
101 | ||
102 | @Override | |
103 | public Types.MinorType getMinorType() { | |
104 | return Types.MinorType.NULL; | |
105 | } | |
106 | ||
107 | @Override | |
108 | public TransferPair getTransferPair(BufferAllocator allocator) { | |
109 | return getTransferPair(null, allocator); | |
110 | } | |
111 | ||
112 | @Override | |
113 | public Iterator<ValueVector> iterator() { | |
114 | return Collections.emptyIterator(); | |
115 | } | |
116 | ||
117 | @Override | |
118 | public int getBufferSize() { | |
119 | return 0; | |
120 | } | |
121 | ||
122 | @Override | |
123 | public int getBufferSizeFor(final int valueCount) { | |
124 | return 0; | |
125 | } | |
126 | ||
127 | @Override | |
128 | public ArrowBuf[] getBuffers(boolean clear) { | |
129 | return new ArrowBuf[0]; | |
130 | } | |
131 | ||
132 | @Override | |
133 | public void allocateNew() throws OutOfMemoryException { | |
134 | allocateNewSafe(); | |
135 | } | |
136 | ||
137 | @Override | |
138 | public boolean allocateNewSafe() { | |
139 | return true; | |
140 | } | |
141 | ||
142 | @Override | |
143 | public void reAlloc() { | |
144 | } | |
145 | ||
146 | @Override | |
147 | public BufferAllocator getAllocator() { | |
148 | throw new UnsupportedOperationException("Tried to get allocator from NullVector"); | |
149 | } | |
150 | ||
151 | @Override | |
152 | public void setInitialCapacity(int numRecords) { | |
153 | } | |
154 | ||
155 | @Override | |
156 | public int getValueCapacity() { | |
157 | return this.valueCount; | |
158 | } | |
159 | ||
160 | @Override | |
161 | public TransferPair getTransferPair(String ref, BufferAllocator allocator) { | |
162 | return new TransferImpl(); | |
163 | } | |
164 | ||
165 | @Override | |
166 | public TransferPair getTransferPair(String ref, BufferAllocator allocator, CallBack callBack) { | |
167 | return getTransferPair(ref, allocator); | |
168 | } | |
169 | ||
170 | @Override | |
171 | public TransferPair makeTransferPair(ValueVector target) { | |
172 | return new TransferImpl((NullVector) target); | |
173 | } | |
174 | ||
175 | @Override | |
176 | public FieldReader getReader() { | |
177 | return NullReader.INSTANCE; | |
178 | } | |
179 | ||
180 | @Override | |
181 | public void initializeChildrenFromFields(List<Field> children) { | |
182 | if (!children.isEmpty()) { | |
183 | throw new IllegalArgumentException("Null vector has no children"); | |
184 | } | |
185 | } | |
186 | ||
187 | @Override | |
188 | public List<FieldVector> getChildrenFromFields() { | |
189 | return Collections.emptyList(); | |
190 | } | |
191 | ||
192 | @Override | |
193 | public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) { | |
194 | Preconditions.checkArgument(ownBuffers.isEmpty(), "Null vector has no buffers"); | |
195 | } | |
196 | ||
197 | @Override | |
198 | public List<ArrowBuf> getFieldBuffers() { | |
199 | return Collections.emptyList(); | |
200 | } | |
201 | ||
202 | /** | |
203 | * Get the inner vectors. | |
204 | * | |
205 | * @deprecated This API will be removed as the current implementations no longer support inner vectors. | |
206 | * | |
207 | * @return the inner vectors for this field as defined by the TypeLayout | |
208 | */ | |
209 | @Deprecated | |
210 | @Override | |
211 | public List<BufferBacked> getFieldInnerVectors() { | |
212 | return Collections.emptyList(); | |
213 | } | |
214 | ||
215 | @Override | |
216 | public long getValidityBufferAddress() { | |
217 | throw new UnsupportedOperationException(); | |
218 | } | |
219 | ||
220 | @Override | |
221 | public long getDataBufferAddress() { | |
222 | throw new UnsupportedOperationException(); | |
223 | } | |
224 | ||
225 | @Override | |
226 | public long getOffsetBufferAddress() { | |
227 | throw new UnsupportedOperationException(); | |
228 | } | |
229 | ||
230 | @Override | |
231 | public ArrowBuf getValidityBuffer() { | |
232 | throw new UnsupportedOperationException(); | |
233 | } | |
234 | ||
235 | @Override | |
236 | public ArrowBuf getDataBuffer() { | |
237 | throw new UnsupportedOperationException(); | |
238 | } | |
239 | ||
240 | @Override | |
241 | public ArrowBuf getOffsetBuffer() { | |
242 | throw new UnsupportedOperationException(); | |
243 | } | |
244 | ||
245 | @Override | |
246 | public int getValueCount() { | |
247 | return this.valueCount; | |
248 | } | |
249 | ||
250 | @Override | |
251 | public void setValueCount(int valueCount) { | |
252 | this.valueCount = valueCount; | |
253 | } | |
254 | ||
255 | @Override | |
256 | public Object getObject(int index) { | |
257 | return null; | |
258 | } | |
259 | ||
260 | @Override | |
261 | public int getNullCount() { | |
262 | return this.valueCount; | |
263 | } | |
264 | ||
265 | @Override | |
266 | public boolean isNull(int index) { | |
267 | return true; | |
268 | } | |
269 | ||
270 | @Override | |
271 | public int hashCode(int index) { | |
272 | return 31 * valueCount; | |
273 | } | |
274 | ||
275 | @Override | |
276 | public int hashCode(int index, ArrowBufHasher hasher) { | |
277 | return 31 * valueCount; | |
278 | } | |
279 | ||
280 | @Override | |
281 | public <OUT, IN> OUT accept(VectorVisitor<OUT, IN> visitor, IN value) { | |
282 | return visitor.visit(this, value); | |
283 | } | |
284 | ||
285 | @Override | |
286 | public void copyFrom(int fromIndex, int thisIndex, ValueVector from) { | |
287 | throw new UnsupportedOperationException(); | |
288 | } | |
289 | ||
290 | @Override | |
291 | public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) { | |
292 | throw new UnsupportedOperationException(); | |
293 | } | |
294 | ||
295 | @Override | |
296 | public String getName() { | |
297 | return this.getField().getName(); | |
298 | } | |
299 | ||
300 | private class TransferImpl implements TransferPair { | |
301 | NullVector to; | |
302 | ||
303 | public TransferImpl(String ref) { | |
304 | to = new NullVector(ref); | |
305 | } | |
306 | ||
307 | @Deprecated | |
308 | public TransferImpl() { | |
309 | to = new NullVector(); | |
310 | } | |
311 | ||
312 | public TransferImpl(NullVector to) { | |
313 | this.to = to; | |
314 | } | |
315 | ||
316 | @Override | |
317 | public NullVector getTo() { | |
318 | return to; | |
319 | } | |
320 | ||
321 | @Override | |
322 | public void transfer() { | |
323 | to.valueCount = valueCount; | |
324 | } | |
325 | ||
326 | @Override | |
327 | public void splitAndTransfer(int startIndex, int length) { | |
328 | to.valueCount = length; | |
329 | } | |
330 | ||
331 | @Override | |
332 | public void copyValueSafe(int fromIndex, int toIndex) { | |
333 | if (toIndex > to.valueCount) { | |
334 | to.valueCount = toIndex; | |
335 | } | |
336 | } | |
337 | } | |
338 | } |