-
Notifications
You must be signed in to change notification settings - Fork 120
Remove duplicate ValidityVTable logic #5975
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b89f49c
ExpressionArray
gatesn 21f718a
Merge branch 'develop' into ngates/remove-duplicate-validity-logic
gatesn 2a0c1da
Use sum
gatesn 49fa716
Merge develop
gatesn 7a307df
Merge develop
gatesn 2d389fa
Merge develop
gatesn b04d12d
Merge develop
gatesn 19aa52c
Merge branch 'develop' into ngates/remove-duplicate-validity-logic
gatesn a8f9801
Only check for ConstantVTable
gatesn 6a79c78
Merge branch 'develop' into ngates/remove-duplicate-validity-logic
gatesn 2091083
Only check for ConstantVTable
gatesn bf754d3
Remove EncodeVTable
gatesn f01ca89
Fix is not null
gatesn 9fb9fed
Fix is not null
gatesn 75ae280
Fix is not null
gatesn c475858
Fix is not null
gatesn 36d04e3
Fix is not null
gatesn 48dd238
Fix is not null
gatesn 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
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
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 |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ use crate::arrays::StructVTable; | |
| use crate::arrays::VarBinVTable; | ||
| use crate::arrays::VarBinViewVTable; | ||
| use crate::builders::ArrayBuilder; | ||
| use crate::compute; | ||
| use crate::compute::ComputeFn; | ||
| use crate::compute::InvocationArgs; | ||
| use crate::compute::Output; | ||
|
|
@@ -145,12 +146,14 @@ pub trait Array: | |
|
|
||
| /// Returns whether all items in the array are valid. | ||
| /// | ||
| /// This is usually cheaper than computing a precise `valid_count`. | ||
| /// This is usually cheaper than computing a precise `valid_count`, but may return false | ||
| /// negatives. | ||
| fn all_valid(&self) -> bool; | ||
|
|
||
| /// Returns whether the array is all invalid. | ||
| /// | ||
| /// This is usually cheaper than computing a precise `invalid_count`. | ||
| /// This is usually cheaper than computing a precise `invalid_count`, but may return false | ||
| /// negatives. | ||
| fn all_invalid(&self) -> bool; | ||
|
|
||
| /// Returns the number of valid elements in the array. | ||
|
|
@@ -545,19 +548,38 @@ impl<V: VTable> Array for ArrayAdapter<V> { | |
| if index >= self.len() { | ||
| vortex_panic!(OutOfBounds: index, 0, self.len()); | ||
| } | ||
| <V::ValidityVTable as ValidityVTable<V>>::is_valid(&self.0, index) | ||
| match self | ||
| .validity() | ||
| .vortex_expect("Failed to get validity for is_valid") | ||
| { | ||
| Validity::NonNullable | Validity::AllValid => true, | ||
| Validity::AllInvalid => false, | ||
| Validity::Array(a) => a | ||
| .scalar_at(index) | ||
| .as_bool() | ||
| .value() | ||
| .vortex_expect("validity must be non-nullable"), | ||
| } | ||
| } | ||
|
|
||
| fn is_invalid(&self, index: usize) -> bool { | ||
| !self.is_valid(index) | ||
| } | ||
|
|
||
| fn all_valid(&self) -> bool { | ||
| <V::ValidityVTable as ValidityVTable<V>>::all_valid(&self.0) | ||
| match self.validity().vortex_expect("Failed to get validity") { | ||
| Validity::NonNullable | Validity::AllValid => true, | ||
| Validity::AllInvalid => false, | ||
| Validity::Array(a) => a.statistics().compute_min::<bool>().unwrap_or(false), | ||
| } | ||
| } | ||
|
|
||
| fn all_invalid(&self) -> bool { | ||
| <V::ValidityVTable as ValidityVTable<V>>::all_invalid(&self.0) | ||
| match self.validity().vortex_expect("Failed to get validity") { | ||
| Validity::NonNullable | Validity::AllValid => false, | ||
| Validity::AllInvalid => true, | ||
| Validity::Array(a) => !a.statistics().compute_max::<bool>().unwrap_or(true), | ||
| } | ||
| } | ||
|
|
||
| fn valid_count(&self) -> usize { | ||
|
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. This will be null count soon right? |
||
|
|
@@ -567,7 +589,19 @@ impl<V: VTable> Array for ArrayAdapter<V> { | |
| return self.len() - invalid_count; | ||
| } | ||
|
|
||
| let count = <V::ValidityVTable as ValidityVTable<V>>::valid_count(&self.0); | ||
| let count = match self | ||
| .validity() | ||
| .vortex_expect("Failed to get validity for valid_count") | ||
| { | ||
| Validity::NonNullable | Validity::AllValid => self.len(), | ||
| Validity::AllInvalid => 0, | ||
| Validity::Array(a) => { | ||
| let sum = compute::sum(&a).vortex_expect("Failed to compute sum for valid count"); | ||
| sum.as_primitive() | ||
| .as_::<usize>() | ||
| .vortex_expect("Sum must be non-nullable") | ||
| } | ||
| }; | ||
| assert!(count <= self.len(), "Valid count exceeds array length"); | ||
|
|
||
| self.statistics() | ||
|
|
@@ -577,33 +611,34 @@ impl<V: VTable> Array for ArrayAdapter<V> { | |
| } | ||
|
|
||
| fn invalid_count(&self) -> usize { | ||
| if let Some(Precision::Exact(invalid_count)) = | ||
| self.statistics().get_as::<usize>(Stat::NullCount) | ||
| { | ||
| return invalid_count; | ||
| } | ||
|
|
||
| let count = <V::ValidityVTable as ValidityVTable<V>>::invalid_count(&self.0); | ||
| assert!(count <= self.len(), "Invalid count exceeds array length"); | ||
|
|
||
| self.statistics() | ||
| .set(Stat::NullCount, Precision::exact(count)); | ||
|
|
||
| count | ||
| self.len() - self.valid_count() | ||
| } | ||
|
|
||
| fn validity(&self) -> VortexResult<Validity> { | ||
| if self.dtype().is_nullable() { | ||
| <V::ValidityVTable as ValidityVTable<V>>::validity(&self.0) | ||
| let validity = <V::ValidityVTable as ValidityVTable<V>>::validity(&self.0)?; | ||
| if let Validity::Array(array) = &validity { | ||
| vortex_ensure!(array.len() == self.len(), "Validity array length mismatch"); | ||
| vortex_ensure!( | ||
| matches!(array.dtype(), DType::Bool(Nullability::NonNullable)), | ||
| "Validity array for must be non-nullable boolean: {}", | ||
| self.to_array().display_tree(), | ||
| ); | ||
| } | ||
| Ok(validity) | ||
| } else { | ||
| Ok(Validity::NonNullable) | ||
| } | ||
| } | ||
|
|
||
| fn validity_mask(&self) -> Mask { | ||
| let mask = <V::ValidityVTable as ValidityVTable<V>>::validity_mask(&self.0); | ||
| assert_eq!(mask.len(), self.len(), "Validity mask length mismatch"); | ||
| mask | ||
| match self.validity().vortex_expect("Failed to get validity") { | ||
| Validity::NonNullable | Validity::AllValid => Mask::new_true(self.len()), | ||
| Validity::AllInvalid => Mask::new_false(self.len()), | ||
| Validity::Array(a) => a | ||
| .try_to_mask_fill_null_false() | ||
| .vortex_expect("Failed to get validity mask"), | ||
| } | ||
| } | ||
|
|
||
| fn to_canonical(&self) -> VortexResult<Canonical> { | ||
|
|
||
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
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.
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 looks like it might be very expensive?