Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-34610: [Java] Fix valueCount when loading NullVector #34611

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, its not obvious to me why this test is failing. I would've expected your change to loadFieldBuffers() to work. Maybe the field comparison is failing? I think you could try passing a custom TypeEqualsVisitor with checkName or checkMetadata disabled to narrow things down on line 155.

return VectorEqualsVisitor.vectorEquals(vector, imported, <custom_visitor_here>);

}
}

@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