-
Notifications
You must be signed in to change notification settings - Fork 130
FilterArray #5610
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
FilterArray #5610
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| use vortex_mask::Mask; | ||
|
|
||
| use crate::ArrayRef; | ||
| use crate::stats::ArrayStats; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct FilterArray { | ||
| pub(super) child: ArrayRef, | ||
| pub(super) mask: Mask, | ||
| pub(super) stats: ArrayStats, | ||
| } |
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,7 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| mod array; | ||
| mod vtable; | ||
|
|
||
| pub use vtable::*; |
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,119 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| use std::hash::Hasher; | ||
|
|
||
| use vortex_buffer::BufferHandle; | ||
| use vortex_dtype::DType; | ||
| use vortex_error::VortexResult; | ||
| use vortex_error::vortex_bail; | ||
| use vortex_mask::Mask; | ||
| use vortex_vector::Vector; | ||
|
|
||
| use crate::Array; | ||
| use crate::ArrayBufferVisitor; | ||
| use crate::ArrayChildVisitor; | ||
| use crate::ArrayEq; | ||
| use crate::ArrayHash; | ||
| use crate::Precision; | ||
| use crate::arrays::filter::array::FilterArray; | ||
| use crate::execution::ExecutionCtx; | ||
| use crate::serde::ArrayChildren; | ||
| use crate::stats::StatsSetRef; | ||
| use crate::vtable; | ||
| use crate::vtable::ArrayId; | ||
| use crate::vtable::ArrayVTable; | ||
| use crate::vtable::ArrayVTableExt; | ||
| use crate::vtable::BaseArrayVTable; | ||
| use crate::vtable::NotSupported; | ||
| use crate::vtable::VTable; | ||
| use crate::vtable::VisitorVTable; | ||
|
|
||
| vtable!(Filter); | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct FilterVTable; | ||
|
|
||
| impl VTable for FilterVTable { | ||
| type Array = FilterArray; | ||
| type Metadata = Mask; | ||
| type ArrayVTable = Self; | ||
| type CanonicalVTable = NotSupported; | ||
| type OperationsVTable = NotSupported; | ||
| type ValidityVTable = NotSupported; | ||
| type VisitorVTable = Self; | ||
| type ComputeVTable = NotSupported; | ||
| type EncodeVTable = NotSupported; | ||
|
|
||
| fn id(&self) -> ArrayId { | ||
| ArrayId::from("vortex.filter") | ||
| } | ||
|
|
||
| fn encoding(_array: &Self::Array) -> ArrayVTable { | ||
| FilterVTable.as_vtable() | ||
| } | ||
|
|
||
| fn metadata(array: &Self::Array) -> VortexResult<Self::Metadata> { | ||
| Ok(array.mask.clone()) | ||
| } | ||
|
|
||
| fn serialize(_metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> { | ||
| Ok(None) | ||
| } | ||
|
|
||
| fn deserialize(_bytes: &[u8]) -> VortexResult<Self::Metadata> { | ||
| vortex_bail!("Filter array is not serializable") | ||
| } | ||
|
|
||
| fn build( | ||
| &self, | ||
| dtype: &DType, | ||
| len: usize, | ||
| metadata: &Self::Metadata, | ||
| _buffers: &[BufferHandle], | ||
| children: &dyn ArrayChildren, | ||
| ) -> VortexResult<Self::Array> { | ||
| let child = children.get(0, dtype, len)?; | ||
| Ok(FilterArray { | ||
| child, | ||
| mask: metadata.clone(), | ||
| stats: Default::default(), | ||
| }) | ||
| } | ||
|
|
||
| fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> { | ||
| let child = array.child.batch_execute(ctx)?; | ||
| Ok(vortex_compute::filter::Filter::filter(&child, &array.mask)) | ||
| } | ||
| } | ||
|
|
||
| impl BaseArrayVTable<FilterVTable> for FilterVTable { | ||
| fn len(array: &FilterArray) -> usize { | ||
| array.mask.true_count() | ||
| } | ||
|
|
||
| fn dtype(array: &FilterArray) -> &DType { | ||
| array.child.dtype() | ||
| } | ||
|
|
||
| fn stats(array: &FilterArray) -> StatsSetRef<'_> { | ||
| array.stats.to_ref(array.as_ref()) | ||
| } | ||
|
|
||
| fn array_hash<H: Hasher>(array: &FilterArray, state: &mut H, precision: Precision) { | ||
| array.child.array_hash(state, precision); | ||
| array.mask.array_hash(state, precision); | ||
| } | ||
|
|
||
| fn array_eq(array: &FilterArray, other: &FilterArray, precision: Precision) -> bool { | ||
| array.child.array_eq(&other.child, precision) && array.mask.array_eq(&other.mask, precision) | ||
| } | ||
| } | ||
|
|
||
| impl VisitorVTable<FilterVTable> for FilterVTable { | ||
| fn visit_buffers(_array: &FilterArray, _visitor: &mut dyn ArrayBufferVisitor) {} | ||
|
|
||
| fn visit_children(array: &FilterArray, visitor: &mut dyn ArrayChildVisitor) { | ||
| visitor.visit_child("child", &array.child); | ||
| } | ||
| } |
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.
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.
would prefer the vtables in different files but if were collapsing them all soon then its not that important