Skip to content

Add Union type casting support to arrow-cast #9225

@friendlymatthew

Description

@friendlymatthew

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Arrow's cast kernel currently doesn't support casting Union types to other types. This blocks useful operations like comparing Union columns with scalar values in query engines like Datafusion (see apache/datafusion#18825)

I propose the following behavior:

When casting Union(Int32, Utf8) to Int32:

  • extract values from the int32 variant
  • non-matching variants (Utf8) become Null

There's also an intermediary cast that could occur, for instance when casting Union(Int32, Utf8) to Int64:

  • extract values from the int32 variant
  • cast them if needed (e.g., Int32 -> int64)
  • non-matching variants (Utf8) become null

This implementation is quite greedy: it finds the matching variant by exact type match first, then by cast-compatibility. (Users can determine precedence by a Union variant's type_id).

Motivation:

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAny new improvement worthy of a entry in the changelog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions