-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: remove stale Interval -> Int64 arm from can_cast_types #10939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dylanpulver
wants to merge
1
commit into
apache:main
Choose a base branch
from
dylanpulver:fix-can-cast-interval-to-int64
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,13 +321,10 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool { | |
| (_, Duration(_)) if from_type.is_numeric() => true, | ||
| (Duration(_), _) if to_type.is_numeric() => true, | ||
| (Duration(_), Duration(_)) => true, | ||
| (Interval(from_type), Int64) => { | ||
| match from_type { | ||
| YearMonth => true, | ||
| DayTime => true, | ||
| MonthDayNano => false, // Native type is i128 | ||
| } | ||
| } | ||
| // Note: there is deliberately no `(Interval(_), Int64)` arm. No interval unit has an | ||
| // unambiguous `i64` value (`YearMonth` is a count of months, `DayTime` packs days and | ||
| // milliseconds, `MonthDayNano` is 128 bits wide), and `cast_with_options` implements no | ||
| // such cast. Cast via `Duration` instead. | ||
| (Int32, Interval(to_type)) => match to_type { | ||
| YearMonth => true, | ||
| DayTime => false, | ||
|
|
@@ -12451,6 +12448,60 @@ mod tests { | |
| assert_eq!(casted_array.value(0), IntervalMonthDayNano::new(0, 123, 0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_can_cast_interval_to_int64_matches_cast() { | ||
|
Comment on lines
+12451
to
+12452
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar Idea for these test, I think we can add one test that asserts
|
||
| // `can_cast_types` used to report `true` for `Interval(YearMonth)` and | ||
| // `Interval(DayTime)` to `Int64` even though `cast_with_options` implements no such | ||
| // cast. Assert the two agree for every interval unit rather than hard coding the | ||
| // expected answer. | ||
| let arrays: Vec<ArrayRef> = vec![ | ||
| Arc::new(IntervalYearMonthArray::from(vec![12])), | ||
| Arc::new(IntervalDayTimeArray::from(vec![IntervalDayTime::new(1, 2)])), | ||
| Arc::new(IntervalMonthDayNanoArray::from(vec![ | ||
| IntervalMonthDayNano::new(1, 2, 3), | ||
| ])), | ||
| ]; | ||
| for array in arrays { | ||
| let from = array.data_type(); | ||
| assert_eq!( | ||
| can_cast_types(from, &DataType::Int64), | ||
| cast(&array, &DataType::Int64).is_ok(), | ||
| "can_cast_types disagrees with cast for {from} -> Int64" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cast_union_to_int64_skips_uncastable_interval_child() { | ||
| // `resolve_child_array` picks the first child that `can_cast_types` accepts, so an | ||
| // over-permissive answer for `Interval -> Int64` made the union cast pick the interval | ||
| // child and fail, instead of the `Utf8` child that can actually be cast. | ||
| let fields = UnionFields::try_new( | ||
| [0, 1], | ||
| [ | ||
| Field::new("iv", DataType::Interval(IntervalUnit::YearMonth), true), | ||
| Field::new("s", DataType::Utf8, true), | ||
| ], | ||
| ) | ||
| .unwrap(); | ||
| let union = UnionArray::try_new( | ||
| fields, | ||
| vec![0, 1, 0].into(), | ||
| None, | ||
| vec![ | ||
| Arc::new(IntervalYearMonthArray::from(vec![Some(12), None, Some(24)])), | ||
| Arc::new(StringArray::from(vec![None, Some("77"), None])), | ||
| ], | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| let casted = cast(&union, &DataType::Int64).unwrap(); | ||
| let casted = casted.as_primitive::<Int64Type>(); | ||
| assert!(casted.is_null(0)); | ||
| assert_eq!(casted.value(1), 77); | ||
| assert!(casted.is_null(2)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_cast_below_unixtimestamp() { | ||
| let valid = StringArray::from(vec![ | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -507,7 +507,7 @@ fn get_all_types() -> Vec<DataType> { | |
| Int8, | ||
| Int16, | ||
| Int32, | ||
| UInt64, | ||
| Int64, | ||
| UInt8, | ||
| UInt16, | ||
| UInt32, | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is strictly needed. we don't need to explain why certain cast don't exist.
if you think its still warranted I think we should shorted this.