Skip to content

Commit

Permalink
Fix valueCount when loading NullVector
Browse files Browse the repository at this point in the history
We should set `valueCount` when loading `NullVector`. Unfortunately there's no `nullCount` field.
  • Loading branch information
sunchao committed Mar 17, 2023
1 parent 8abb941 commit 5f78a8c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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 @@ -462,6 +462,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
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 @@ -192,6 +212,7 @@ public List<FieldVector> getChildrenFromFields() {
@Override
public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) {
Preconditions.checkArgument(ownBuffers.isEmpty(), "Null vector has no buffers");
this.valueCount = fieldNode.getLength();
}

@Override
Expand Down

0 comments on commit 5f78a8c

Please sign in to comment.