Skip to content
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

Support list in the fuzzer (only for implemented actions) #1735

Merged
merged 23 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use vortex_array::aliases::hash_set::HashSet;
use vortex_array::array::ListEncoding;
use vortex_array::compute::{scalar_at, FilterMask, SearchResult, SearchSortedSide};
use vortex_array::encoding::{Encoding, EncodingRef};
use vortex_array::{ArrayDType, ArrayData, IntoArrayData, NamedTreeCollector};
use vortex_array::{
ArrayChildrenIterator, ArrayDType, ArrayData, IntoArrayData, NamedTreeCollector, ToArrayData,
};
use vortex_buffer::Buffer;
use vortex_sampling_compressor::SamplingCompressor;
use vortex_scalar::arbitrary::random_scalar;
Expand Down Expand Up @@ -187,10 +189,9 @@ fn actions_for_encoding(encoding: EncodingRef) -> HashSet<usize> {
}

fn actions_for_array(array: &ArrayData) -> Vec<usize> {
NamedTreeCollector::visit_all_children(array)
.unwrap()
.iter()
.map(|(_, child)| actions_for_encoding(child.encoding()))
ArrayChildrenIterator::new(array.to_array())
.into_iter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be just array.depth_first_traversal()

.map(|child| actions_for_encoding(child.encoding()))
.fold(ALL_ACTIONS.collect::<Vec<_>>(), |mut acc, actions| {
acc.retain(|a| actions.contains(a));
acc
Expand Down
48 changes: 0 additions & 48 deletions vortex-array/src/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ pub struct NamedChildrenCollector {
children: Vec<(String, ArrayData)>,
}

#[derive(Default, Debug)]
pub struct NamedTreeCollector {
all_children: Vec<(String, ArrayData)>,
}

impl ChildrenCollector {
pub fn children(self) -> Vec<ArrayData> {
self.children
Expand All @@ -30,18 +25,6 @@ impl NamedChildrenCollector {
}
}

impl NamedTreeCollector {
pub fn all_children(self) -> Vec<(String, ArrayData)> {
self.all_children
}

pub fn visit_all_children(array: &ArrayData) -> VortexResult<Vec<(String, ArrayData)>> {
let mut collector = NamedTreeCollector::default();
array.encoding().accept(array, &mut collector)?;
Ok(collector.all_children)
}
}

impl ArrayVisitor for ChildrenCollector {
fn visit_child(&mut self, _name: &str, array: &ArrayData) -> VortexResult<()> {
self.children.push(array.clone());
Expand All @@ -55,34 +38,3 @@ impl ArrayVisitor for NamedChildrenCollector {
Ok(())
}
}

impl ArrayVisitor for NamedTreeCollector {
fn visit_child(&mut self, name: &str, array: &ArrayData) -> VortexResult<()> {
self.all_children.push((name.to_string(), array.clone()));
array.encoding().accept(array, self)?;
Ok(())
}
}

#[cfg(test)]
mod tests {

use crate::array::{ChunkedArray, ListArray, PrimitiveArray};
use crate::validity::Validity;
use crate::{IntoArrayData, NamedTreeCollector};

#[test]
fn nested_collect() {
let list = ListArray::try_new(
PrimitiveArray::from_iter(vec![1i32, 2, 3]).into_array(),
PrimitiveArray::from_iter(vec![0i32, 2, 3]).into_array(),
Validity::NonNullable,
)
.unwrap()
.into_array();
let chunk = ChunkedArray::from_iter(vec![list]).into_array();

let children = NamedTreeCollector::visit_all_children(&chunk).unwrap();
assert_eq!(children.len(), 4)
}
}
Loading