Skip to content

Commit

Permalink
GH-34610: [Java] Fix valueCount and field name when loading/transferr…
Browse files Browse the repository at this point in the history
…ing NullVector (#38973)

### Rationale for this change

This is a follow up of #34611 (thanks @ sunchao)
We should set `valueCount` when loading `NullVector`. Unfortunately there's no `nullCount` field.

### What changes are included in this PR?

* `valueCount` added to NullVector
* `name` added to NullVector's TransferPair

### Are these changes tested?

Yes. unit tested.

### Are there any user-facing changes?

Yes, a NullVector with a non-null name will maintain the name when transferred via `TransferPair` instead of defaulting to the default name `$data$`.
* Closes: #34610

Authored-by: Chao Sun <sunchao@apple.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
danepitkin authored Nov 29, 2023
1 parent 0940fec commit a31663a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
7 changes: 7 additions & 0 deletions java/c/src/test/java/org/apache/arrow/c/RoundtripTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,13 @@ public void testUInt8Vector() {
}
}

@Test
public void testNullVector() {
try (final NullVector vector = new NullVector("v", 1024)) {
assertTrue(roundtrip(vector, NullVector.class));
}
}

@Test
public void testVarBinaryVector() {
try (final VarBinaryVector vector = new VarBinaryVector("v", allocator)) {
Expand Down
28 changes: 24 additions & 4 deletions java/vector/src/main/java/org/apache/arrow/vector/NullVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public NullVector(String name) {
this(name, FieldType.nullable(Types.MinorType.NULL.getType()));
}

/**
* Instantiate a NullVector with the given number of values.
*
* @param name name of the vector
* @param valueCount number of values (i.e., nulls) in this vector.
*/
public NullVector(String name, int valueCount) {
this(new Field(name, FieldType.nullable(Types.MinorType.NULL.getType()), null), valueCount);
}

/**
* Instantiate a NullVector.
*
Expand All @@ -73,8 +83,18 @@ public NullVector(String name, FieldType fieldType) {
* @param field field materialized by this vector.
*/
public NullVector(Field field) {
this.valueCount = 0;
this(field, 0);
}

/**
* Instantiate a NullVector with the given number of values.
*
* @param field field materialized by this vector.
* @param valueCount number of values (i.e., nulls) in this vector.
*/
public NullVector(Field field, int valueCount) {
this.field = field;
this.valueCount = valueCount;
}

@Deprecated
Expand Down Expand Up @@ -106,7 +126,7 @@ public Types.MinorType getMinorType() {

@Override
public TransferPair getTransferPair(BufferAllocator allocator) {
return getTransferPair((String) null, allocator);
return getTransferPair(getName(), allocator);
}

@Override
Expand Down Expand Up @@ -159,12 +179,12 @@ public int getValueCapacity() {

@Override
public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
return new TransferImpl();
return new TransferImpl(ref);
}

@Override
public TransferPair getTransferPair(Field field, BufferAllocator allocator) {
return new TransferImpl();
return new TransferImpl(field.getName());
}

@Override
Expand Down

0 comments on commit a31663a

Please sign in to comment.