[Variant] Add variant to arrow for Date64/Timestamp(Second/Millisecond)/Time32/Time64#8950
Merged
alamb merged 3 commits intoapache:mainfrom Dec 11, 2025
Merged
Conversation
69bb43b to
1af7a22
Compare
klion26
commented
Dec 4, 2025
| }); | ||
| impl_primitive_from_variant!(datatypes::Time64MicrosecondType, as_time_utc, |v| { | ||
| (v.num_seconds_from_midnight() * 1_000_000 + v.nanosecond() / 1_000) as i64 | ||
| Some((v.num_seconds_from_midnight() * 1_000_000 + v.nanosecond() / 1_000) as i64) |
Member
Author
There was a problem hiding this comment.
We don't need to handle the case v.nanosecond() % 1000 != 0 here. Thanks for variant_array::canonicalize_and_verify_data_type, we can assume that the input here is always Time64(TimeUnit::Microsecond)(No Time32 or Time64(TimeUnitNanosecond))
alamb
approved these changes
Dec 10, 2025
| Some(datatypes::Date64Type::from_naive_date(v)) | ||
| }); | ||
| impl_primitive_from_variant!(datatypes::Time32SecondType, as_time_utc, |v| { | ||
| // Return None if there are leftover nanoseconds |
Contributor
There was a problem hiding this comment.
this makes sense to me -- we return None because we can't cast without losing precision
Member
Author
|
|
||
| perfectly_shredded_variant_array_fn!(perfectly_shredded_time_variant_array_for_time32, || { | ||
| Time64MicrosecondArray::from(vec![ | ||
| Some(1234), // This can't be cast to Time32 |
Contributor
There was a problem hiding this comment.
it can cast, but the cast is not lossless
Member
Author
There was a problem hiding this comment.
Yes, updated the comment to make it more clearly.
Contributor
|
Thanks @klion26 |
Member
Author
|
@alamb Thanks for the review and merging! |
This was referenced Jan 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
What changes are included in this PR?
Add support for variant to arrow primitive types(for the remaining arrow primitive types), and some tests to cover them.
For the behavior that can't be cast safely, I'll continue to track them in #8086 and #8873
- else None
- else None
- else None
- else Nnoe
Are these changes tested?
Added some new tests
Are there any user-facing changes?
No