Skip to content

[Variant] Support UUID conversion in cast_to_variant #11937

Open

Description

@sdf-jkl

Is your feature request related to a problem or challenge?

This came up while implementing SQL casts to Variant in datafusion-variant.

cast_to_variant and cast_to_variant_with_options cannot distinguish an Arrow UUID column from ordinary FixedSizeBinary(16). The arrow.uuid annotation belongs to the input Field, but these APIs accept only &dyn Array.

The conversion dispatches on the storage data type and converts fixed-size binary values to Variant::Binary. A caller implementing CAST(uuid_column AS VARIANT) therefore cannot preserve UUID semantics through this kernel, even when it has the correctly annotated input field.

This follows from the implementation in Arrow 60.0.0 and remains the case on current main: the fixed-size binary path receives no extension metadata.

Describe the solution you'd like

Allow callers to supply input field information, for example through a conversion entry point accepting &Field and &dyn Array. Use the canonical arrow.uuid annotation to distinguish UUID from ordinary binary:

Input Expected Variant value
FixedSizeBinary(16) annotated with arrow.uuid Variant::Uuid
Unannotated FixedSizeBinary(16) Variant::Binary
Arrow null Arrow null

Honor UUID annotations on nested fields in lists, structs, and maps as well. Existing array-only callers should retain their binary conversion behavior. The exact API shape is open for discussion.

Additional context

Related work addressed UUID metadata in shredded Variant storage:

  • #10015: merged UUID metadata preservation for shredded fields and Parquet writing.

In #10015's discussion, the justification was that a shredded FixedSizeBinary(16) field can only represent UUID: Arrow uses dedicated decimal types, and the shredding specification stores binary as BYTE_ARRAY. The merged change therefore attaches UUID metadata when constructing or canonicalizing those shredded fields.

That inference relies on the input already being shredded Variant storage. Ordinary Arrow inputs to cast_to_variant need their field metadata to distinguish UUID from binary.

Activity

  1. added
    enhancement
    on Oct 27, 2026
  2. codewarnab commented on Nov 1, 2026

    @codewarnab
    Contributor

    take

  3. codewarnab commented on Nov 1, 2026

    @codewarnab
    Contributor

    Before I start, would these two new functions work?

    cast_to_variant_with_field(input, field)
    cast_to_variant_with_field_and_options(input, field, options)

    They would accept the input Field along with the array, so the conversion can read the UUID annotation.

    • A valid arrow.uuid field becomes Variant::Uuid.
    • Ordinary FixedSizeBinary(16) stays Variant::Binary.
    • UUID fields inside lists, structs, and map values are handled too.
    • Null handling stays the same.
    • A field that does not match the array, or has an invalid UUID annotation, returns an error.

    The existing functions would stay unchanged. The first new function would use the same defaults as cast_to_variant.

    Does this look okay, or would you prefer a different API?

  4. sdf-jkl commented on Nov 2, 2026

    @sdf-jkl
    MemberAuthor

    It had so been inconvenient throughout the Variant work to pass Field everywhere just to to pass the extension type around 😢

    I can see no other way without changing the way we propagate the ExtensionType. Though I'd be very interested in proposing such a change.

  5. codewarnab commented on Nov 2, 2026

    @codewarnab
    Contributor

    I see what you mean. I read the discussion in #8730 about the problems and the possible approaches.

    Should I hold off on this issue until there is an agreement on #8730, or should I proceed with the Field-accepting API for now? 🙂

  6. sdf-jkl commented on Nov 2, 2026

    @sdf-jkl
    MemberAuthor

    #8370 haven't been touched in a long time. Getting some attention to it is a good thing and would help us avoid introducing new APIs just to carry Field to the input.

  7. codewarnab commented on Nov 3, 2026

    @codewarnab
    Contributor

    Okay, I’ll dig deeper into #8730 as soon as I have time and share any ideas /plans /questions there.

    You mentioned #8370. Did you mean #8730? I’m assuming it was a typo.

  8. sdf-jkl commented on Nov 27, 2026

    @sdf-jkl
    MemberAuthor

    #12211 fixed the nested children part of the issue for Variant values

  9. codewarnab commented on Nov 27, 2026

    @codewarnab
    Contributor

    I'm going to unassign myself from this one.

    The main question is how the arrow.uuid tag should reach cast_to_variant. One option is new functions that take a Field. The other is the bigger extension type change discussed in #8730. I shared a prototype and some questions on #8730 on Nov 3 but haven't heard back, so I don't have a clear direction to build on.

    #12211 already handles the nested part, so what's left mostly depends on that decision. Someone else is welcome to pick it up, or I can come back to it once the approach is agreed.

  10. codewarnab commented on Nov 27, 2026

    @codewarnab
    Contributor

    untake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions