You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Variant] Align cast logic for variant_get to cast kernel #8982
As cast kernel makes lossy=true the default from its introduction(without the flag), so we'll align the behavior to cast kernel here, this one can be used to track this one
changed the title [-][Variant] Support lossy cast for `variant_get`[/-][+][Variant] Align cast logic for `variant_get` to cast kernel[/+]on Jan 23, 2026
@alamb@scovich
The plan is to handle the cast logic within every Variant::as_xx function. Do you think this is the right direction? If so, I'll move forward with it.
The reasons for implementing the cast logic in Variant::as_xx are as follows:
Currently, arrow cast kernels are column-based, while the casts in variant_get are row-based; we can't directly use the cast kernel; we can only reuse the logic in the cast kernel as much as possible.
This requires maintaining the cast logic in two places, but the basic cast logic remains changed little over time, so it should be manageable.
Ultimately, the columnar casts have to cast each individual value, correct? There's just a (really) big difference in the wiring harness around that scalar casting logic? But from what I've seen, the scalar casting logic is embedded in the various columnar kernels, so unifying them would require factoring out a common scalar cast capability?
like Timestamp -> Timestamp, it may not be easy to unify without performance sacrifice(did not find a solution, but need to confirm it), the logic is as follows
I've been looking into that and realized the the variant-specific casts don't allow truncating timestamps while arrow does allow some, I couldn't find any explicit reason why, and would be happy to take on it if that's the desired final behavior here.
My motivation here is that I realized that we currently just pull typed_value only if the types match exactly, but theoretically we could cast it (when supported and according to CastOptions), which should be much faster than going through the row-wise builder.
Activity
[-][Variant] Support loss cast for `variant_get`[/-][+][Variant] Support lossy cast for `variant_get`[/+]klion26 commentedon Jan 23, 2026
As
cast kernelmakeslossy=truethe default from its introduction(without the flag), so we'll align the behavior to cast kernel here, this one can be used to track this one[-][Variant] Support lossy cast for `variant_get`[/-][+][Variant] Align cast logic for `variant_get` to cast kernel[/+]klion26 commentedon Mar 11, 2026
@alamb @scovich
The plan is to handle the cast logic within every
Variant::as_xxfunction. Do you think this is the right direction? If so, I'll move forward with it.The reasons for implementing the cast logic in
Variant::as_xxare as follows:variant_getare row-based; we can't directly use the cast kernel; we can only reuse the logic in the cast kernel as much as possible.scovich commentedon Mar 11, 2026
Ultimately, the columnar casts have to cast each individual value, correct? There's just a (really) big difference in the wiring harness around that scalar casting logic? But from what I've seen, the scalar casting logic is embedded in the various columnar kernels, so unifying them would require factoring out a common scalar cast capability?
klion26 commentedon Mar 13, 2026
@scovich, sorry for the late reply; this notification mail is located in a different folder this time.
Yes, we can unify the common cast logic for most of them, but some may not be easy to unify; we'll unify/reuse the common logic as much as possible.
Int32->Date32cast kernel use(Int32, Date32) => cast_reinterpret_arrays::<Int32Type, Date32Type>(array), but for variant, current isVariant::as_naive_date(will returnNaiveDate) and will doDate32Type::from_naive_date(x)when builder.append(value)Timestamp -> Timestamp, it may not be easy to unify without performance sacrifice(did not find a solution, but need to confirm it), the logic is as followsarrow-rs/arrow-cast/src/cast/mod.rs
Lines 1782 to 1803 in 92a239a
Anyway, seems we need to do the cast logic in
Variant::as_xx, will push one pr to explain it bettersdf-jkl commentedon Apr 6, 2026
@klion26 What's next? 😃
klion26 commentedon Apr 7, 2026
@sdf-jkl Thanks for tagging me, #9564 has been merged, I'll do this for the remaining types
AdamGS commentedon Apr 21, 2026
I've been looking into that and realized the the variant-specific casts don't allow truncating timestamps while arrow does allow some, I couldn't find any explicit reason why, and would be happy to take on it if that's the desired final behavior here.
My motivation here is that I realized that we currently just pull
typed_valueonly if the types match exactly, but theoretically we could cast it (when supported and according toCastOptions), which should be much faster than going through the row-wise builder.sdf-jkl commentedon May 24, 2026
Hey @klion26 @AdamGS, it seems like what's left is:
variant_getandcastkernel for temporal types (Timestamp/Date/Time) #10102BinarySeems like it doesn't need special handlingWe could take it on piece by piece.
klion26 commentedon May 25, 2026
Ah... sorry, Seems my last comment did not submit successfully. Thanks for @sdf-jkl the comment, and @AdamGS I've left some comments in #9862