3737import org .apache .arrow .flatbuf .Precision ;
3838
3939/**
40- * Nullable${minor.class } implements a vector of values which could be null. Elements in the vector
40+ * ${className } implements a vector of values which could be null. Elements in the vector
4141 * are first checked against a fixed length vector of boolean values. Then the element is retrieved
4242 * from the base class (if not null).
4343 *
4747public final class $ {className } extends BaseDataValueVector implements <#if type .major == "VarLen ">VariableWidth <#else >FixedWidth </#if >Vector , NullableVector , FieldVector {
4848 private static final org .slf4j .Logger logger = org .slf4j .LoggerFactory .getLogger ($ {className }.class );
4949
50- private final FieldReader reader = new $ {minor .class }ReaderImpl (Nullable$ { minor . class } Vector .this );
50+ private final FieldReader reader = new $ {minor .class }ReaderImpl ($ { className } .this );
5151
5252 private final String bitsField = "$bits$" ;
5353 private final String valuesField = "$values$" ;
@@ -67,7 +67,7 @@ public final class ${className} extends BaseDataValueVector implements <#if type
6767
6868 public $ {className }(String name , BufferAllocator allocator , int precision , int scale ) {
6969 super (name , allocator );
70- values = new $ {minor . class } Vector (valuesField , allocator , precision , scale );
70+ values = new $ {valuesName } (valuesField , allocator , precision , scale );
7171 this .precision = precision ;
7272 this .scale = scale ;
7373 mutator = new Mutator ();
@@ -81,7 +81,7 @@ public final class ${className} extends BaseDataValueVector implements <#if type
8181 <#else >
8282 public $ {className }(String name , BufferAllocator allocator ) {
8383 super (name , allocator );
84- values = new $ {minor . class } Vector (valuesField , allocator );
84+ values = new $ {valuesName } (valuesField , allocator );
8585 mutator = new Mutator ();
8686 accessor = new Accessor ();
8787 <#if minor .class == "TinyInt" ||
@@ -144,6 +144,13 @@ public List<FieldVector> getChildrenFromFields() {
144144
145145 @ Override
146146 public void loadFieldBuffers (ArrowFieldNode fieldNode , List <ArrowBuf > ownBuffers ) {
147+ <#if type .major = "VarLen" >
148+ // variable width values: truncate offset vector buffer to size (#1)
149+ org .apache .arrow .vector .BaseDataValueVector .truncateBufferBasedOnSize (ownBuffers , 1 , values .offsetVector .getBufferSizeFor (fieldNode .getLength () + 1 ));
150+ <#else >
151+ // fixed width values truncate value vector to size (#1)
152+ org .apache .arrow .vector .BaseDataValueVector .truncateBufferBasedOnSize (ownBuffers , 1 , values .getBufferSizeFor (fieldNode .getLength ()));
153+ </#if >
147154 org .apache .arrow .vector .BaseDataValueVector .load (fieldNode , getFieldInnerVectors (), ownBuffers );
148155 bits .valueCount = fieldNode .getLength ();
149156 }
@@ -229,13 +236,6 @@ public void setInitialCapacity(int numRecords) {
229236 values .setInitialCapacity (numRecords );
230237 }
231238
232- // @Override
233- // public SerializedField.Builder getMetadataBuilder() {
234- // return super.getMetadataBuilder()
235- // .addChild(bits.getMetadata())
236- // .addChild(values.getMetadata());
237- // }
238-
239239 @ Override
240240 public void allocateNew () {
241241 if (!allocateNewSafe ()){
@@ -329,20 +329,6 @@ public void zeroVector() {
329329 }
330330 </#if>
331331
332-
333- // @Override
334- // public void load(SerializedField metadata, ArrowBuf buffer) {
335- // clear();
336- // the bits vector is the first child (the order in which the children are added in getMetadataBuilder is significant)
337- // final SerializedField bitsField = metadata.getChild(0);
338- // bits.load(bitsField, buffer);
339- //
340- // final int capacity = buffer.capacity();
341- // final int bitsLength = bitsField.getBufferLength();
342- // final SerializedField valuesField = metadata.getChild(1);
343- // values.load(valuesField, buffer.slice(bitsLength, capacity - bitsLength));
344- // }
345-
346332 @Override
347333 public TransferPair getTransferPair(BufferAllocator allocator){
348334 return new TransferImpl(name, allocator);
@@ -356,10 +342,10 @@ public TransferPair getTransferPair(String ref, BufferAllocator allocator){
356342
357343 @Override
358344 public TransferPair makeTransferPair(ValueVector to) {
359- return new TransferImpl((Nullable${minor.class}Vector ) to);
345+ return new TransferImpl((${className} ) to);
360346 }
361347
362- public void transferTo(Nullable${minor.class}Vector target){
348+ public void transferTo(${className} target){
363349 bits.transferTo(target.bits);
364350 values.transferTo(target.values);
365351 <#if type.major == " VarLen ">
@@ -368,7 +354,7 @@ public void transferTo(Nullable${minor.class}Vector target){
368354 clear();
369355 }
370356
371- public void splitAndTransferTo(int startIndex, int length, Nullable${minor.class}Vector target) {
357+ public void splitAndTransferTo(int startIndex, int length, ${className} target) {
372358 bits.splitAndTransferTo(startIndex, length, target.bits);
373359 values.splitAndTransferTo(startIndex, length, target.values);
374360 <#if type.major == " VarLen ">
@@ -377,22 +363,22 @@ public void splitAndTransferTo(int startIndex, int length, Nullable${minor.class
377363 }
378364
379365 private class TransferImpl implements TransferPair {
380- Nullable${minor.class}Vector to;
366+ ${className} to;
381367
382368 public TransferImpl(String name, BufferAllocator allocator){
383369 <#if minor.class == " Decimal ">
384- to = new Nullable${minor.class}Vector (name, allocator, precision, scale);
370+ to = new ${className} (name, allocator, precision, scale);
385371 <#else>
386- to = new Nullable${minor.class}Vector (name, allocator);
372+ to = new ${className} (name, allocator);
387373 </#if>
388374 }
389375
390- public TransferImpl(Nullable${minor.class}Vector to){
376+ public TransferImpl(${className} to){
391377 this.to = to;
392378 }
393379
394380 @Override
395- public Nullable${minor.class}Vector getTo(){
381+ public ${className} getTo(){
396382 return to;
397383 }
398384
@@ -408,7 +394,7 @@ public void splitAndTransfer(int startIndex, int length) {
408394
409395 @Override
410396 public void copyValueSafe(int fromIndex, int toIndex) {
411- to.copyFromSafe(fromIndex, toIndex, Nullable${minor.class}Vector .this);
397+ to.copyFromSafe(fromIndex, toIndex, ${className} .this);
412398 }
413399 }
414400
@@ -422,22 +408,22 @@ public Mutator getMutator(){
422408 return mutator;
423409 }
424410
425- public void copyFrom(int fromIndex, int thisIndex, Nullable${minor.class}Vector from){
411+ public void copyFrom(int fromIndex, int thisIndex, ${className} from){
426412 final Accessor fromAccessor = from.getAccessor();
427413 if (!fromAccessor.isNull(fromIndex)) {
428414 mutator.set(thisIndex, fromAccessor.get(fromIndex));
429415 }
430416 }
431417
432- public void copyFromSafe(int fromIndex, int thisIndex, ${minor.class}Vector from){
418+ public void copyFromSafe(int fromIndex, int thisIndex, ${valuesName} from){
433419 <#if type.major == " VarLen ">
434420 mutator.fillEmpties(thisIndex);
435421 </#if>
436422 values.copyFromSafe(fromIndex, thisIndex, from);
437423 bits.getMutator().setSafe(thisIndex, 1);
438424 }
439425
440- public void copyFromSafe(int fromIndex, int thisIndex, Nullable${minor.class}Vector from){
426+ public void copyFromSafe(int fromIndex, int thisIndex, ${className} from){
441427 <#if type.major == " VarLen ">
442428 mutator.fillEmpties(thisIndex);
443429 </#if>
@@ -640,7 +626,7 @@ public void set(int index, ${minor.class}Holder holder){
640626 }
641627
642628 public boolean isSafe(int outIndex) {
643- return outIndex < Nullable${minor.class}Vector .this.getValueCapacity();
629+ return outIndex < ${className} .this.getValueCapacity();
644630 }
645631
646632 <#assign fields = minor.fields!type.fields />
0 commit comments