-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix Redundant ScalarValue Boxed Collection #2523
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
95ea4db
unbox scalars
comphead d750e43
Merge branch 'master' into unbox_scalar_merged
comphead 5661512
fix conflicts
comphead 77b3557
fix clippy
comphead 1d883ac
Update datafusion/common/src/scalar.rs
comphead d64f224
Update datafusion/common/src/scalar.rs
comphead 66c8c2f
Merge branch 'apache:master' into unbox_scalar_merged
comphead f957fc3
boxing datatype
comphead b9ea1a5
fixing test
comphead 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
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 |
|---|---|---|
|
|
@@ -170,11 +170,11 @@ mod tests { | |
| #[test] | ||
| fn scalar_list_to_array() { | ||
| let list_array_ref = ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::UInt64(Some(100)), | ||
| ScalarValue::UInt64(None), | ||
| ScalarValue::UInt64(Some(101)), | ||
| ])), | ||
| ]), | ||
| Box::new(DataType::UInt64), | ||
| ) | ||
| .to_array(); | ||
|
|
@@ -606,35 +606,35 @@ mod tests { | |
|
|
||
| assert_eq!( | ||
| List( | ||
| Some(Box::new(vec![Int32(Some(1)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(1)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| ) | ||
| .partial_cmp(&List( | ||
| Some(Box::new(vec![Int32(Some(1)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(1)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| )), | ||
| Some(Ordering::Equal) | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| List( | ||
| Some(Box::new(vec![Int32(Some(10)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(10)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| ) | ||
| .partial_cmp(&List( | ||
| Some(Box::new(vec![Int32(Some(1)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(1)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| )), | ||
| Some(Ordering::Greater) | ||
| ); | ||
|
|
||
| assert_eq!( | ||
| List( | ||
| Some(Box::new(vec![Int32(Some(1)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(1)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| ) | ||
| .partial_cmp(&List( | ||
| Some(Box::new(vec![Int32(Some(10)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(10)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| )), | ||
| Some(Ordering::Less) | ||
|
|
@@ -643,11 +643,11 @@ mod tests { | |
| // For different data type, `partial_cmp` returns None. | ||
| assert_eq!( | ||
| List( | ||
| Some(Box::new(vec![Int64(Some(1)), Int64(Some(5))])), | ||
| Box::new(DataType::Int64), | ||
| Some(vec![Int64(Some(1)), Int64(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
|
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. Why the change in type?
Contributor
Author
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. fixed. Thanks for finding that |
||
| ) | ||
| .partial_cmp(&List( | ||
| Some(Box::new(vec![Int32(Some(1)), Int32(Some(5))])), | ||
| Some(vec![Int32(Some(1)), Int32(Some(5))]), | ||
| Box::new(DataType::Int32), | ||
| )), | ||
| None | ||
|
|
@@ -694,15 +694,15 @@ mod tests { | |
| ); | ||
|
|
||
| let scalar = ScalarValue::Struct( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::Int32(Some(23)), | ||
| ScalarValue::Boolean(Some(false)), | ||
| ScalarValue::Utf8(Some("Hello".to_string())), | ||
| ScalarValue::from(vec![ | ||
| ("e", ScalarValue::from(2i16)), | ||
| ("f", ScalarValue::from(3i64)), | ||
| ]), | ||
| ])), | ||
| ]), | ||
| Box::new(vec![ | ||
| field_a.clone(), | ||
| field_b.clone(), | ||
|
|
@@ -866,24 +866,21 @@ mod tests { | |
|
|
||
| // Define primitive list scalars | ||
| let l0 = ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::from(1i32), | ||
| ScalarValue::from(2i32), | ||
| ScalarValue::from(3i32), | ||
| ])), | ||
| ]), | ||
| Box::new(DataType::Int32), | ||
| ); | ||
|
|
||
| let l1 = ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| ScalarValue::from(4i32), | ||
| ScalarValue::from(5i32), | ||
| ])), | ||
| Some(vec![ScalarValue::from(4i32), ScalarValue::from(5i32)]), | ||
| Box::new(DataType::Int32), | ||
| ); | ||
|
|
||
| let l2 = ScalarValue::List( | ||
| Some(Box::new(vec![ScalarValue::from(6i32)])), | ||
| Some(vec![ScalarValue::from(6i32)]), | ||
| Box::new(DataType::Int32), | ||
| ); | ||
|
|
||
|
|
@@ -928,15 +925,13 @@ mod tests { | |
|
|
||
| // Define list-of-structs scalars | ||
| let nl0 = ScalarValue::List( | ||
| Some(Box::new(vec![s0.clone(), s1.clone()])), | ||
| Some(vec![s0.clone(), s1.clone()]), | ||
| Box::new(s0.get_datatype()), | ||
| ); | ||
|
|
||
| let nl1 = | ||
| ScalarValue::List(Some(Box::new(vec![s2])), Box::new(s0.get_datatype())); | ||
| let nl1 = ScalarValue::List(Some(vec![s2]), Box::new(s0.get_datatype())); | ||
|
|
||
| let nl2 = | ||
| ScalarValue::List(Some(Box::new(vec![s1])), Box::new(s0.get_datatype())); | ||
| let nl2 = ScalarValue::List(Some(vec![s1]), Box::new(s0.get_datatype())); | ||
|
|
||
| // iter_to_array for list-of-struct | ||
| let array = ScalarValue::iter_to_array(vec![nl0, nl1, nl2]).unwrap(); | ||
|
|
@@ -1080,23 +1075,20 @@ mod tests { | |
| fn test_nested_lists() { | ||
| // Define inner list scalars | ||
| let l1 = ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::from(1i32), | ||
| ScalarValue::from(2i32), | ||
| ScalarValue::from(3i32), | ||
| ])), | ||
| ]), | ||
| Box::new(DataType::Int32), | ||
| ), | ||
| ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| ScalarValue::from(4i32), | ||
| ScalarValue::from(5i32), | ||
| ])), | ||
| Some(vec![ScalarValue::from(4i32), ScalarValue::from(5i32)]), | ||
| Box::new(DataType::Int32), | ||
| ), | ||
| ])), | ||
| ]), | ||
| Box::new(DataType::List(Box::new(Field::new( | ||
| "item", | ||
| DataType::Int32, | ||
|
|
@@ -1105,19 +1097,16 @@ mod tests { | |
| ); | ||
|
|
||
| let l2 = ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| Some(vec![ | ||
| ScalarValue::List( | ||
| Some(Box::new(vec![ScalarValue::from(6i32)])), | ||
| Some(vec![ScalarValue::from(6i32)]), | ||
| Box::new(DataType::Int32), | ||
| ), | ||
| ScalarValue::List( | ||
| Some(Box::new(vec![ | ||
| ScalarValue::from(7i32), | ||
| ScalarValue::from(8i32), | ||
| ])), | ||
| Some(vec![ScalarValue::from(7i32), ScalarValue::from(8i32)]), | ||
| Box::new(DataType::Int32), | ||
| ), | ||
| ])), | ||
| ]), | ||
| Box::new(DataType::List(Box::new(Field::new( | ||
| "item", | ||
| DataType::Int32, | ||
|
|
@@ -1126,10 +1115,10 @@ mod tests { | |
| ); | ||
|
|
||
| let l3 = ScalarValue::List( | ||
| Some(Box::new(vec![ScalarValue::List( | ||
| Some(Box::new(vec![ScalarValue::from(9i32)])), | ||
| Some(vec![ScalarValue::List( | ||
| Some(vec![ScalarValue::from(9i32)]), | ||
| Box::new(DataType::Int32), | ||
| )])), | ||
| )]), | ||
| Box::new(DataType::List(Box::new(Field::new( | ||
| "item", | ||
| DataType::Int32, | ||
|
|
||
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
Oops, something went wrong.
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.
👍 this is a nicer implementation
Uh oh!
There was an error while loading. Please reload this page.
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.
clippy complained on
for c in 0..columns.len():)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.
All the better that removing a layer of
Boxing lets clippy fix things more easily 👍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.
A perhaps more idiomatic way to write this would be something like
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.
Yes, thats more concise. Fixed in 2 places.