Skip to content

[Java] Type-ids in UnionVector are erroneously coupled to the Arrow types of the underlying vectors #108

Description

@jarohen

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

re: https://lists.apache.org/thread/z89xlvw7v1rwq89gknflhsj3c65x20kd

It seems that the UnionVector implementation (particularly initializeChildrenFromFields (#29848), getVector, getVectorByType, setSafe etc) assumes that the type-id is always based on the ArrowType, but the Schema.fbs spec is more lenient - users have the choice to use whatever type-ids they require.

For example, in XTDB, we're trying to represent an algebraic data type (ADT) of 'put', 'delete' and 'erase' events as a sparse union. Delete and erase have the same type, so UnionVector currently expects them to be the same type-id (whereas, in DenseUnionVector, we can use type-ids 0, 1 and 2).

Would there be an appetite for (potentially relatively significant) changes to UnionVector to make it behave this way? We could perhaps consider bringing it more in line with DenseUnionVector which seems closer to the spec. Would be happy to work on it if so.

Cheers,

James/Finn (@FiV0)

Component(s)

Java

Activity

  1. pitrou commented on Apr 3, 2024

    @pitrou
    Member

    Would there be an appetite for (potentially relatively significant) changes to UnionVector to make it behave this way? We could perhaps consider bringing it more in line with DenseUnionVector which seems closer to the spec.

    +1. It would of course be better if a way of doing this without breaking compatibility with existing Java code is found.

    cc @lidavidm @vibhatha @jduo

  2. lidavidm commented on Apr 3, 2024

    @lidavidm
    Member

    Are you speaking of significant API changes, or significant implementation changes? The latter is fine so long as existing tests pass.

  3. pitrou commented on Apr 3, 2024

    @pitrou
    Member

    I'm thinking of significant API changes.

  4. FiV0 commented on Apr 3, 2024

    @FiV0
    Contributor

    I think there need to be significant (breaking) API changes if you want to make it spec compliant.

  5. vibhatha commented on Apr 3, 2024

    @vibhatha
    Contributor

    +1 for implementation changes preserving compatibility and current test coverage.
    Any idea on the maginitude of this change?

  6. vibhatha commented on Apr 3, 2024

    @vibhatha
    Contributor

    If this is spec compliant, meaning it changes the existing spec, would it require a vote on ML?

  7. FiV0 commented on Apr 3, 2024

    @FiV0
    Contributor

    This may sound harsh, but for me the current UnionVector API is broken in the light of the mailing list discussion above. Even looking at the first test of UnionVector, a line like
    https://github.com/apache/arrow/blob/41a989c81616aea103e554521fa6d6209ffa248d/java/vector/src/test/java/org/apache/arrow/vector/TestUnionVector.java#L78
    doesn't make sense. You could probably make a lot of the methods that exist work with only internal changes, but I would still argue for deprecation to discourage future use.

    Any idea on the maginitude of this change?

    A significant rewrite of UnionVector. I might even start from scratch basing it more on the DenseUnionVector implementation.

  8. pitrou commented on Apr 3, 2024

    @pitrou
    Member

    Yes, we should definitely deprecate the ill-designed APIs. But it's better if they can still work as originally until people migrate their code to the new APIs.

  9. vibhatha commented on Apr 3, 2024

    @vibhatha
    Contributor

    @pitrou I agree with that. Would it be possible to introduce a new API (as required by the discussed change) and leave the older API in deprecate mode and eventually let the migration happen at user end?

  10. pitrou commented on Apr 3, 2024

    @pitrou
    Member

    That's what I'm suggesting, yes.

  11. transferred this issue fromapache/arrowon Nov 26, 2024
  12. nbauernfeind commented on Feb 4, 2025

    @nbauernfeind
    Contributor

    Are there any plans on fixing this? It's inconvenient that UnionVector#setType and DenseUnionVector#setTypeId deviate from one another.

  13. lidavidm commented on Feb 4, 2025

    @lidavidm
    Member

    Unfortunately there's just very little maintainer power for arrow-java and what's left is mostly focused on trying to keep things running (e.g. trying to set up release processes again now that we've split the repo) :/

  14. lidavidm commented on Feb 4, 2025

    @lidavidm
    Member

    It frustrates me too and I wish I had time to help out and fix things, improve the library, keep Arrow abreast of things like the new native memory interface, etc. but that's just not happening with my current development time/goals

  15. nbauernfeind commented on Feb 4, 2025

    @nbauernfeind
    Contributor

    Thanks for sharing; I totally understand the very real issue of not having enough resources.

  16. lidavidm commented on Feb 4, 2025

    @lidavidm
    Member

    It's doubly frustrating because I feel like the Java library gets certain design decisions right vs the other implementations 😬

    Unfortunately we probably need some sponsor or champion to fund development...The lack of maintainers is also sort of self-perpetuating since there's not many people to review things in the first place

  17. jbonofre commented on Feb 4, 2025

    @jbonofre
    Member

    Maybe I can take a look after the releases. I think arrow-Java needs some love (and I have a lot of love to give :)).

  18. self-assigned this
    on Feb 17, 2025
  19. martin-traverse commented on Mar 25, 2025

    @martin-traverse
    Contributor

    Just to add to this, the union vector writers could also use revisiting as part of this work. The dense writer seems to have a bug where the child writers are not initialized. But more generally both writers have a lot of things in them that the format spec doesn't talk about.

  20. added a commit that references this issue on Apr 23, 2025
  21. added a commit that references this issue on Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions