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
.NullCheckingForGet
.NULL_CHECKING_ENABLED
;
22 import java
.time
.LocalDateTime
;
24 import org
.apache
.arrow
.memory
.BufferAllocator
;
25 import org
.apache
.arrow
.vector
.complex
.impl
.TimeStampNanoReaderImpl
;
26 import org
.apache
.arrow
.vector
.complex
.reader
.FieldReader
;
27 import org
.apache
.arrow
.vector
.holders
.NullableTimeStampNanoHolder
;
28 import org
.apache
.arrow
.vector
.holders
.TimeStampNanoHolder
;
29 import org
.apache
.arrow
.vector
.types
.Types
.MinorType
;
30 import org
.apache
.arrow
.vector
.types
.pojo
.Field
;
31 import org
.apache
.arrow
.vector
.types
.pojo
.FieldType
;
32 import org
.apache
.arrow
.vector
.util
.DateUtility
;
33 import org
.apache
.arrow
.vector
.util
.TransferPair
;
36 * TimeStampNanoVector implements a fixed width vector (8 bytes) of
37 * timestamp (nanosecond resolution) values which could be null. A validity buffer
38 * (bit vector) is maintained to track which elements in the vector are null.
40 public final class TimeStampNanoVector
extends TimeStampVector
{
41 private final FieldReader reader
;
44 * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for
47 * @param name name of the vector
48 * @param allocator allocator for memory management.
50 public TimeStampNanoVector(String name
, BufferAllocator allocator
) {
51 this(name
, FieldType
.nullable(MinorType
.TIMESTAMPNANO
.getType()), allocator
);
55 * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for
58 * @param name name of the vector
59 * @param fieldType type of Field materialized by this vector
60 * @param allocator allocator for memory management.
62 public TimeStampNanoVector(String name
, FieldType fieldType
, BufferAllocator allocator
) {
63 super(name
, fieldType
, allocator
);
64 reader
= new TimeStampNanoReaderImpl(TimeStampNanoVector
.this);
68 * Instantiate a TimeStampNanoVector. This doesn't allocate any memory for
71 * @param field Field materialized by this vector
72 * @param allocator allocator for memory management.
74 public TimeStampNanoVector(Field field
, BufferAllocator allocator
) {
75 super(field
, allocator
);
76 reader
= new TimeStampNanoReaderImpl(TimeStampNanoVector
.this);
80 * Get a reader that supports reading values from this vector.
82 * @return Field Reader for this vector
85 public FieldReader
getReader() {
90 * Get minor type for this vector. The vector holds values belonging
91 * to a particular type.
93 * @return {@link org.apache.arrow.vector.types.Types.MinorType}
96 public MinorType
getMinorType() {
97 return MinorType
.TIMESTAMPNANO
;
101 /*----------------------------------------------------------------*
103 | vector value retrieval methods |
105 *----------------------------------------------------------------*/
109 * Get the element at the given index from the vector and
110 * sets the state in holder. If element at given index
111 * is null, holder.isSet will be zero.
113 * @param index position of element
115 public void get(int index
, NullableTimeStampNanoHolder holder
) {
116 if (NULL_CHECKING_ENABLED
&& isSet(index
) == 0) {
121 holder
.value
= valueBuffer
.getLong((long) index
* TYPE_WIDTH
);
125 * Same as {@link #get(int)}.
127 * @param index position of element
128 * @return element at given index
130 public LocalDateTime
getObject(int index
) {
131 if (isSet(index
) == 0) {
134 final long nanos
= valueBuffer
.getLong((long) index
* TYPE_WIDTH
);
135 return DateUtility
.getLocalDateTimeFromEpochNano(nanos
);
140 /*----------------------------------------------------------------*
142 | vector value setter methods |
144 *----------------------------------------------------------------*/
148 * Set the element at the given index to the value set in data holder.
149 * If the value in holder is not indicated as set, element in the
150 * at the given index will be null.
152 * @param index position of element
153 * @param holder nullable data holder for value of element
155 public void set(int index
, NullableTimeStampNanoHolder holder
) throws IllegalArgumentException
{
156 if (holder
.isSet
< 0) {
157 throw new IllegalArgumentException();
158 } else if (holder
.isSet
> 0) {
159 BitVectorHelper
.setBit(validityBuffer
, index
);
160 setValue(index
, holder
.value
);
162 BitVectorHelper
.unsetBit(validityBuffer
, index
);
167 * Set the element at the given index to the value set in data holder.
169 * @param index position of element
170 * @param holder data holder for value of element
172 public void set(int index
, TimeStampNanoHolder holder
) {
173 BitVectorHelper
.setBit(validityBuffer
, index
);
174 setValue(index
, holder
.value
);
178 * Same as {@link #set(int, NullableTimeStampNanoHolder)} except that it handles the
179 * case when index is greater than or equal to existing
180 * value capacity {@link #getValueCapacity()}.
182 * @param index position of element
183 * @param holder nullable data holder for value of element
185 public void setSafe(int index
, NullableTimeStampNanoHolder holder
) throws IllegalArgumentException
{
191 * Same as {@link #set(int, TimeStampNanoHolder)} except that it handles the
192 * case when index is greater than or equal to existing
193 * value capacity {@link #getValueCapacity()}.
195 * @param index position of element
196 * @param holder data holder for value of element
198 public void setSafe(int index
, TimeStampNanoHolder holder
) {
204 /*----------------------------------------------------------------*
208 *----------------------------------------------------------------*/
212 * Construct a TransferPair comprising of this and a target vector of
215 * @param ref name of the target vector
216 * @param allocator allocator for the target vector
217 * @return {@link TransferPair}
220 public TransferPair
getTransferPair(String ref
, BufferAllocator allocator
) {
221 TimeStampNanoVector to
= new TimeStampNanoVector(ref
,
222 field
.getFieldType(), allocator
);
223 return new TransferImpl(to
);
227 * Construct a TransferPair with a desired target vector of the same type.
229 * @param to target vector
230 * @return {@link TransferPair}
233 public TransferPair
makeTransferPair(ValueVector to
) {
234 return new TransferImpl((TimeStampNanoVector
) to
);