jbonofre commented on code in PR #1379:
URL: https://github.com/apache/arrow-java/pull/1379#discussion_r4492168592


##########
vector/src/main/java/org/apache/arrow/vector/types/Types.java:
##########
@@ -164,7 +164,7 @@ public enum MinorType {
       @Override
       public FieldVector getNewVector(
           Field field, BufferAllocator allocator, CallBack 
schemaChangeCallback) {
-        return new NullVector(field.getName());
+        return new NullVector(field);

Review Comment:
   This change makes a `NullVector` created from a schema keep its nullability. 
But `NullVector` transfer pairs still create a plain nullable vector 
(`TransferImpl(String ref)` -> `new NullVector(ref)`, and 
`getTransferPair(Field, ...)` only uses `field.getName()`). So the source and 
target of a transfer now have different fields.
   
   That breaks code that worked before. `VectorSchemaRoot.slice()` uses 
`getTransferPair(allocator)`, and `VectorSchemaRootAppender` compares 
nullability, so this now throws `IllegalArgumentException: Vector schema roots 
have different schemas.`:
   
   ```java
   Schema schema = new Schema(List.of(
       new Field("n", FieldType.notNullable(ArrowType.Null.INSTANCE), null)));
   try (VectorSchemaRoot root = VectorSchemaRoot.create(schema, allocator);
        VectorSchemaRoot target = VectorSchemaRoot.create(schema, allocator)) {
     root.setRowCount(3);
     try (VectorSchemaRoot slice = root.slice(0, 2)) {
       VectorSchemaRootAppender.append(target, slice);
     }
   }
   ```
   
   Before this PR, both sides were nullable, so this worked.
   
   Could you also update `NullVector` so its transfer pairs keep the field? 
Something like:
   
   ```java
   @Override
   public TransferPair getTransferPair(String ref, BufferAllocator allocator) {
     return new TransferImpl(new NullVector(ref, field.getFieldType()));
   }
   @Override
   public TransferPair getTransferPair(Field field, BufferAllocator allocator) {
     return new TransferImpl(new NullVector(field));
   }
   ```



-- 
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]

Reply via email to