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

[Java] Nullability of struct child vectors not preserved in TransferPair #41686

Closed
FiV0 opened this issue May 16, 2024 · 10 comments
Closed

[Java] Nullability of struct child vectors not preserved in TransferPair #41686

FiV0 opened this issue May 16, 2024 · 10 comments

Comments

@FiV0
Copy link
Contributor

FiV0 commented May 16, 2024

Describe the bug, including details regarding any error messages, version, and platform.

When copying a struct vector via a transfer pair the nullability of the children is not preserved

  @Test
  public void testMakeTransferPairPreserveNullability() {
    Field intField = new Field("int", FieldType.notNullable(MinorType.INT.getType()), null);
    Field structField = new Field("struct", FieldType.notNullable(Struct.INSTANCE), List.of(intField));
    FieldVector vec = structField.createVector(allocator);

    TransferPair tp = vec.getTransferPair(new Field("struct", FieldType.nullable(Struct.INSTANCE), List.of(intField)), allocator);
    tp.transfer();

    FieldVector res = (FieldVector) tp.getTo();

    // passes
    assertEquals(intField, vec.getField().getChildren().get(0));
    // fails
    assertEquals(intField, res.getField().getChildren().get(0));
  }

results in the failure

Expected :int: Int(32, true) not null
Actual   :int: Int(32, true)

Component(s)

Java

@tlm365
Copy link
Contributor

tlm365 commented May 22, 2024

Field structField = new Field("struct", FieldType.notNullable(Struct.INSTANCE), List.of(intField));
FieldVector vec = structField.createVector(allocator);

TransferPair tp = vec.getTransf>erPair(new Field("struct", FieldType.nullable(Struct.INSTANCE), List.of(intField)), allocator);

@FiV0 I don't think it's a bug. The bolding texts above are mismatched and that's the reason for the diff between vec and res.

@vibhatha
Copy link
Collaborator

@tlm365 could you explain

The bolding texts above are mismatched

@tlm365
Copy link
Contributor

tlm365 commented May 22, 2024

@vibhatha the Field he passed when create vec is notNullable:
Field structField = new Field("struct", FieldType.notNullable(Struct.INSTANCE), List.of(intField));
FieldVector vec = structField.createVector(allocator);

but nullable when pass to getTransferPair:
TransferPair tp = vec.getTransferPair(new Field("struct", FieldType.nullable(Struct.INSTANCE), List.of(intField)), allocator);

@vibhatha
Copy link
Collaborator

@vibhatha the Field he passed when create vec is notNullable: Field structField = new Field("struct", FieldType.notNullable(Struct.INSTANCE), List.of(intField)); FieldVector vec = structField.createVector(allocator);

but nullable when pass to getTransferPair: TransferPair tp = vec.getTransferPair(new Field("struct", FieldType.nullable(Struct.INSTANCE), List.of(intField)), allocator);

Oh I didn't catch that. Thanks @tlm365

@FiV0
Copy link
Contributor Author

FiV0 commented May 22, 2024

This is about the nullability of the the child and not the struct. Why should the nullability of a struct affect the nullability of its children?

@vibhatha
Copy link
Collaborator

Hmm, @FiV0 I agree. I also tested it even with adding matching nullability, just for the sake of the argument. But still the issue is there.

@vibhatha
Copy link
Collaborator

I am taking a look at this.

@vibhatha
Copy link
Collaborator

I think the issue is here addVectorAsNullable field is not properly set. This doesn't go to the buffer transfer level, from the type setting level, the nullability is inaccurately set AFAIU from debugging.

@vibhatha
Copy link
Collaborator

I will make a draft PR shortly.

@vibhatha vibhatha self-assigned this May 22, 2024
lidavidm pushed a commit that referenced this issue May 24, 2024
… TransferPair (#41785)

### Rationale for this change

Nullability of the struct child vectors are not preserved in the StructWriter templates. 

### What changes are included in this PR?

- [X] Adding nullability and test cases. 
- [X] Updating to JUNIT5

### Are these changes tested?

New test case added and the change is being validated by existing tests. 

### Are there any user-facing changes?

No
* GitHub Issue: #41686

Authored-by: Vibhatha Lakmal Abeykoon <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
@lidavidm lidavidm added this to the 17.0.0 milestone May 24, 2024
@lidavidm
Copy link
Member

Issue resolved by pull request 41785
#41785

vibhatha added a commit to vibhatha/arrow that referenced this issue May 25, 2024
…ved in TransferPair (apache#41785)

### Rationale for this change

Nullability of the struct child vectors are not preserved in the StructWriter templates. 

### What changes are included in this PR?

- [X] Adding nullability and test cases. 
- [X] Updating to JUNIT5

### Are these changes tested?

New test case added and the change is being validated by existing tests. 

### Are there any user-facing changes?

No
* GitHub Issue: apache#41686

Authored-by: Vibhatha Lakmal Abeykoon <vibhatha@gmail.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants