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
;
20 import static org
.apache
.arrow
.vector
.complex
.BaseRepeatedValueVector
.DATA_VECTOR_NAME
;
22 import java
.util
.Collections
;
23 import java
.util
.Iterator
;
24 import java
.util
.List
;
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
;
45 public class NullVector
implements FieldVector
{
47 private int valueCount
;
49 protected Field field
;
52 * Instantiate a NullVector.
54 * @param name name of the vector
56 public NullVector(String name
) {
57 this(name
, FieldType
.nullable(Types
.MinorType
.NULL
.getType()));
61 * Instantiate a NullVector.
63 * @param name name of the vector
64 * @param fieldType type of Field materialized by this vector.
66 public NullVector(String name
, FieldType fieldType
) {
67 this(new Field(name
, fieldType
, null));
71 * Instantiate a NullVector.
73 * @param field field materialized by this vector.
75 public NullVector(Field field
) {
82 this(new Field(DATA_VECTOR_NAME
, FieldType
.nullable(new ArrowType
.Null()), null));
98 public Field
getField() {
103 public Types
.MinorType
getMinorType() {
104 return Types
.MinorType
.NULL
;
108 public TransferPair
getTransferPair(BufferAllocator allocator
) {
109 return getTransferPair(null, allocator
);
113 public Iterator
<ValueVector
> iterator() {
114 return Collections
.emptyIterator();
118 public int getBufferSize() {
123 public int getBufferSizeFor(final int valueCount
) {
128 public ArrowBuf
[] getBuffers(boolean clear
) {
129 return new ArrowBuf
[0];
133 public void allocateNew() throws OutOfMemoryException
{
138 public boolean allocateNewSafe() {
143 public void reAlloc() {
147 public BufferAllocator
getAllocator() {
148 throw new UnsupportedOperationException("Tried to get allocator from NullVector");
152 public void setInitialCapacity(int numRecords
) {
156 public int getValueCapacity() {
157 return this.valueCount
;
161 public TransferPair
getTransferPair(String ref
, BufferAllocator allocator
) {
162 return new TransferImpl();
166 public TransferPair
getTransferPair(String ref
, BufferAllocator allocator
, CallBack callBack
) {
167 return getTransferPair(ref
, allocator
);
171 public TransferPair
makeTransferPair(ValueVector target
) {
172 return new TransferImpl((NullVector
) target
);
176 public FieldReader
getReader() {
177 return NullReader
.INSTANCE
;
181 public void initializeChildrenFromFields(List
<Field
> children
) {
182 if (!children
.isEmpty()) {
183 throw new IllegalArgumentException("Null vector has no children");
188 public List
<FieldVector
> getChildrenFromFields() {
189 return Collections
.emptyList();
193 public void loadFieldBuffers(ArrowFieldNode fieldNode
, List
<ArrowBuf
> ownBuffers
) {
194 Preconditions
.checkArgument(ownBuffers
.isEmpty(), "Null vector has no buffers");
198 public List
<ArrowBuf
> getFieldBuffers() {
199 return Collections
.emptyList();
203 * Get the inner vectors.
205 * @deprecated This API will be removed as the current implementations no longer support inner vectors.
207 * @return the inner vectors for this field as defined by the TypeLayout
211 public List
<BufferBacked
> getFieldInnerVectors() {
212 return Collections
.emptyList();
216 public long getValidityBufferAddress() {
217 throw new UnsupportedOperationException();
221 public long getDataBufferAddress() {
222 throw new UnsupportedOperationException();
226 public long getOffsetBufferAddress() {
227 throw new UnsupportedOperationException();
231 public ArrowBuf
getValidityBuffer() {
232 throw new UnsupportedOperationException();
236 public ArrowBuf
getDataBuffer() {
237 throw new UnsupportedOperationException();
241 public ArrowBuf
getOffsetBuffer() {
242 throw new UnsupportedOperationException();
246 public int getValueCount() {
247 return this.valueCount
;
251 public void setValueCount(int valueCount
) {
252 this.valueCount
= valueCount
;
256 public Object
getObject(int index
) {
261 public int getNullCount() {
262 return this.valueCount
;
266 public boolean isNull(int index
) {
271 public int hashCode(int index
) {
272 return 31 * valueCount
;
276 public int hashCode(int index
, ArrowBufHasher hasher
) {
277 return 31 * valueCount
;
281 public <OUT
, IN
> OUT
accept(VectorVisitor
<OUT
, IN
> visitor
, IN value
) {
282 return visitor
.visit(this, value
);
286 public void copyFrom(int fromIndex
, int thisIndex
, ValueVector from
) {
287 throw new UnsupportedOperationException();
291 public void copyFromSafe(int fromIndex
, int thisIndex
, ValueVector from
) {
292 throw new UnsupportedOperationException();
296 public String
getName() {
297 return this.getField().getName();
300 private class TransferImpl
implements TransferPair
{
303 public TransferImpl(String ref
) {
304 to
= new NullVector(ref
);
308 public TransferImpl() {
309 to
= new NullVector();
312 public TransferImpl(NullVector to
) {
317 public NullVector
getTo() {
322 public void transfer() {
323 to
.valueCount
= valueCount
;
327 public void splitAndTransfer(int startIndex
, int length
) {
328 to
.valueCount
= length
;
332 public void copyValueSafe(int fromIndex
, int toIndex
) {
333 if (toIndex
> to
.valueCount
) {
334 to
.valueCount
= toIndex
;