Skip to content

Support general SQL casts from VARIANT #90

Closed

Description

@sdf-jkl

Support CAST, TRY_CAST, and :: from stored or composed Variant values to SQL types, regardless of which expression produced the value. Casts directly around getter UDFs already work; casts from other Variant expressions still need the same conversion semantics.

Landed

Remaining conversion-kernel gaps and the temporary safe-cast null adjustment are tracked in #71. They are separate from the missing SQL cast dispatch here.

Remaining behavior

With functions and the type planner registered:

CREATE TABLE variant_values AS
SELECT parse_json('7') AS v;

-- All should return 7 as INT.
SELECT CAST(v AS INT), TRY_CAST(v AS INT), v::INT
FROM variant_values;

-- Composed expressions should work too.
SELECT CAST(parse_json('7') AS INT);

Reuse Arrow's Variant extraction/conversion kernels and existing typed-getter semantics. Dispatch using source fields and extension metadata; an ordinary struct resembling Variant storage must not be treated as Variant. Assess DataFusion's existing planning/extension APIs before proposing an upstream hook.

Acceptance criteria

  • Stored columns and composed Variant expressions use typed-getter conversion rules across projection and materialization boundaries.
  • Strict casts error on failed conversions; try casts return SQL NULL. Preserve SQL NULL, Variant null, and missing-result semantics consistently with getters.
  • Preserve explicit intermediate conversions, existing getter cast optimizations, and the casts to VARIANT added in Replace cast_to_variant with SQL casts and to_variant_object #105.
  • Keep declared result fields consistent with kernel output. Accept valid binary layouts without converting buffers solely to prefer BinaryView.
  • Add focused SLTs for expression/materialization boundaries, reusing the existing conversion and null fixtures.

Nested Variant getter targets and exposing DataFusion's SQL type-string resolver remain separate follow-ups. Related: #69, #71.

Activity

  1. changed the title [-]Support general SQL casts to and from VARIANT[/-] [+]Support general SQL casts from VARIANT[/+] on Oct 27, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions