jbonofre commented on code in PR #1381:
URL: https://github.com/apache/arrow-java/pull/1381#discussion_r4493107342
##########
vector/src/main/codegen/templates/DenseUnionVector.java:
##########
@@ -631,6 +631,7 @@ private void createTransferPairs() {
to.childVectors[i] = dstVec;
internalTransferPairs[i] = srcVec.makeTransferPair(dstVec);
}
+ to.nextTypeId = nextTypeId;
Review Comment:
This cause a regression for unions whose type ids aren't `0..n-1`, for
example `[5, 10]`, which is what IPC or the C Data interface gives us when the
schema declares type ids.
`createTransferPairs` fills `to.childVectors` at the loop index (0 and 1),
but `setChildVectorValueCounts` reads `childVectors[typeMapFields[i]]`, i.e.
`childVectors[5]` and `childVectors[10]`, which are null on the target. Before
this change `to.nextTypeId` was 0, so that loop never ran. Now any
`setValueCount` on the target after `transfer()` (including through
`VectorSchemaRoot.setRowCount`) throws:
```
java.lang.NullPointerException: Cannot invoke
"org.apache.arrow.vector.ValueVector.setValueCount(int)" because
"this.childVectors[...]" is null
at
org.apache.arrow.vector.complex.DenseUnionVector.setChildVectorValueCounts(DenseUnionVector.java)
at
org.apache.arrow.vector.complex.DenseUnionVector.setValueCount(DenseUnionVector.java)
```
Here's an example to reproduce the regression:
```java
Field field =
new Field(
"u",
FieldType.nullable(new ArrowType.Union(UnionMode.Dense, new int[]
{5, 10})),
asList(
Field.nullable("i", MinorType.INT.getType()),
Field.nullable("b", MinorType.BIT.getType())));
try (DenseUnionVector vector = (DenseUnionVector)
field.createVector(allocator)) {
vector.allocateNew();
vector.setTypeId(0, (byte) 5);
vector.setSafe(0, intHolder(5));
vector.setTypeId(1, (byte) 10);
vector.setSafe(1, bitHolder(true));
vector.setTypeId(2, (byte) 5);
vector.setSafe(2, intHolder(7));
vector.setValueCount(3);
TransferPair pair = vector.getTransferPair(allocator);
try (DenseUnionVector target = (DenseUnionVector) pair.getTo()) {
pair.transfer();
target.setValueCount(3); // NPE
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]