Skip to content

Support native casts to and from VariantType #5430

Description

@peterxcli

What is the problem the feature request solves?

Spark 4.x supports CAST / TRY_CAST between VariantType and a defined set of scalar and nested types, but Comet explicitly rejects every pair involving Variant in CometCast.

Examples that therefore fall back include:

SELECT CAST(v AS STRING), TRY_CAST(v AS ARRAY<INT>) FROM t;
SELECT CAST(id AS VARIANT), CAST(array(1, 2) AS VARIANT) FROM t;

Spark admits casts from Variant through VariantGet.checkDataType and supports the reciprocal cast to Variant for scalar values and supported arrays. Structs and maps use to_variant_object instead. The runtime routes Variant casts through Spark's Variant cast implementation, including generated execution.

Describe the potential solution

Add only Spark-supported Variant pairs to Comet's cast matrix and native cast implementation:

Add focused parity and native-plan tests across supported scalar types, arrays and nested targets, SQL/JSON nulls, invalid conversions, TRY_CAST, aliases, and columns around a Variant-producing result. Spark 3.x compilation and behavior must remain unchanged through the version shim.

Additional context

Related work: #4295, #5407, #5424, #5425, and the dedicated to_variant_object tracker.

Non-goals: comparisons and hash expressions (Spark rejects Variant for both), to_variant_object, parsing JSON, shuffle/spill, C2R, writing, and Python transport.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions