-
Notifications
You must be signed in to change notification settings - Fork 146
Prunning expressions can reference rowcount #7589
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
robert3005
wants to merge
1
commit into
develop
Choose a base branch
from
rk/rowcount
base: develop
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| [toolchain] | ||
| channel = "1.91.0" | ||
| components = ["rust-src", "rustfmt", "clippy", "rust-analyzer"] | ||
| profile = "minimal" | ||
| profile = "minimal" |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ pub mod is_sorted; | |
| pub mod last; | ||
| pub mod min_max; | ||
| pub mod nan_count; | ||
| pub mod row_count; | ||
| pub mod sum; | ||
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 |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| use vortex_error::VortexExpect; | ||
| use vortex_error::VortexResult; | ||
|
|
||
| use crate::ArrayRef; | ||
| use crate::Columnar; | ||
| use crate::ExecutionCtx; | ||
| use crate::aggregate_fn::AggregateFnId; | ||
| use crate::aggregate_fn::AggregateFnVTable; | ||
| use crate::aggregate_fn::EmptyOptions; | ||
| use crate::dtype::DType; | ||
| use crate::dtype::Nullability; | ||
| use crate::dtype::PType; | ||
| use crate::scalar::Scalar; | ||
|
|
||
| /// Count the total number of elements in an array, including nulls. | ||
| /// | ||
| /// Applies to all types. Returns a `u64` count. | ||
| /// The identity value is zero. | ||
| /// | ||
| /// Unlike [`Count`][crate::aggregate_fn::fns::count::Count], this aggregate includes | ||
| /// null elements in the total. It is primarily used as a marker inside pruning | ||
| /// predicates that need to refer to the scope row count. | ||
| #[derive(Clone, Debug)] | ||
| pub struct RowCount; | ||
|
|
||
| impl AggregateFnVTable for RowCount { | ||
| type Options = EmptyOptions; | ||
| type Partial = u64; | ||
|
|
||
| fn id(&self) -> AggregateFnId { | ||
| AggregateFnId::new("vortex.row_count") | ||
| } | ||
|
|
||
| fn serialize(&self, _options: &Self::Options) -> VortexResult<Option<Vec<u8>>> { | ||
| unimplemented!("RowCount is not yet serializable"); | ||
| } | ||
|
|
||
| fn return_dtype(&self, _options: &Self::Options, _input_dtype: &DType) -> Option<DType> { | ||
| Some(DType::Primitive(PType::U64, Nullability::NonNullable)) | ||
| } | ||
|
|
||
| fn partial_dtype(&self, options: &Self::Options, input_dtype: &DType) -> Option<DType> { | ||
| self.return_dtype(options, input_dtype) | ||
| } | ||
|
|
||
| fn empty_partial( | ||
| &self, | ||
| _options: &Self::Options, | ||
| _input_dtype: &DType, | ||
| ) -> VortexResult<Self::Partial> { | ||
| Ok(0u64) | ||
| } | ||
|
|
||
| fn combine_partials(&self, partial: &mut Self::Partial, other: Scalar) -> VortexResult<()> { | ||
| let val = other | ||
| .as_primitive() | ||
| .typed_value::<u64>() | ||
| .vortex_expect("row_count partial should not be null"); | ||
| *partial += val; | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn to_scalar(&self, partial: &Self::Partial) -> VortexResult<Scalar> { | ||
| Ok(Scalar::primitive(*partial, Nullability::NonNullable)) | ||
| } | ||
|
|
||
| fn reset(&self, partial: &mut Self::Partial) { | ||
| *partial = 0; | ||
| } | ||
|
|
||
| #[inline] | ||
| fn is_saturated(&self, _partial: &Self::Partial) -> bool { | ||
| false | ||
| } | ||
|
|
||
| fn try_accumulate( | ||
| &self, | ||
| state: &mut Self::Partial, | ||
| batch: &ArrayRef, | ||
| _ctx: &mut ExecutionCtx, | ||
| ) -> VortexResult<bool> { | ||
| *state += batch.len() as u64; | ||
| Ok(true) | ||
| } | ||
|
|
||
| fn accumulate( | ||
| &self, | ||
| _partial: &mut Self::Partial, | ||
| _batch: &Columnar, | ||
| _ctx: &mut ExecutionCtx, | ||
| ) -> VortexResult<()> { | ||
| unreachable!("RowCount::try_accumulate handles all arrays") | ||
| } | ||
|
|
||
| fn finalize(&self, partials: ArrayRef) -> VortexResult<ArrayRef> { | ||
| Ok(partials) | ||
| } | ||
|
|
||
| fn finalize_scalar(&self, partial: &Self::Partial) -> VortexResult<Scalar> { | ||
| self.to_scalar(partial) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use vortex_buffer::buffer; | ||
| use vortex_error::VortexResult; | ||
|
|
||
| use crate::IntoArray; | ||
| use crate::LEGACY_SESSION; | ||
| use crate::VortexSessionExecute; | ||
| use crate::aggregate_fn::Accumulator; | ||
| use crate::aggregate_fn::DynAccumulator; | ||
| use crate::aggregate_fn::EmptyOptions; | ||
| use crate::aggregate_fn::fns::row_count::RowCount; | ||
| use crate::arrays::PrimitiveArray; | ||
|
|
||
| #[test] | ||
| fn row_count_all_valid() -> VortexResult<()> { | ||
| let array = buffer![1i32, 2, 3, 4, 5].into_array(); | ||
| let mut ctx = LEGACY_SESSION.create_execution_ctx(); | ||
| let mut acc = Accumulator::try_new(RowCount, EmptyOptions, array.dtype().clone())?; | ||
| acc.accumulate(&array, &mut ctx)?; | ||
| let result = acc.finish()?; | ||
| assert_eq!(result.as_primitive().typed_value::<u64>(), Some(5)); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn row_count_includes_nulls() -> VortexResult<()> { | ||
| let array = PrimitiveArray::from_option_iter([Some(1i32), None, Some(3), None, Some(5)]) | ||
| .into_array(); | ||
| let mut ctx = LEGACY_SESSION.create_execution_ctx(); | ||
| let mut acc = Accumulator::try_new(RowCount, EmptyOptions, array.dtype().clone())?; | ||
| acc.accumulate(&array, &mut ctx)?; | ||
| let result = acc.finish()?; | ||
| assert_eq!(result.as_primitive().typed_value::<u64>(), Some(5)); | ||
| Ok(()) | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -20,4 +20,5 @@ pub mod operators; | |
| pub mod pack; | ||
| pub mod root; | ||
| pub mod select; | ||
| pub mod stats_expression; | ||
| pub mod zip; | ||
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.