use crate::schema::RootDataType;
#[derive(Debug, Clone)]
pub struct ProjectionMask {
indices: Option<Vec<usize>>,
}
impl ProjectionMask {
pub fn all() -> Self {
Self { indices: None }
}
pub fn roots(root_data_type: &RootDataType, indices: impl IntoIterator<Item = usize>) -> Self {
let input_indices = indices.into_iter().collect::<Vec<_>>();
let mut indices = vec![0];
root_data_type
.children()
.iter()
.filter(|col| input_indices.contains(&col.data_type().column_index()))
.for_each(|col| indices.extend(col.data_type().all_indices()));
Self {
indices: Some(indices),
}
}
pub fn named_roots<T>(root_data_type: &RootDataType, names: &[T]) -> Self
where
T: AsRef<str>,
{
let mut indices = vec![0];
let names = names.iter().map(AsRef::as_ref).collect::<Vec<_>>();
root_data_type
.children()
.iter()
.filter(|col| names.contains(&col.name()))
.for_each(|col| indices.extend(col.data_type().all_indices()));
Self {
indices: Some(indices),
}
}
pub fn is_index_projected(&self, index: usize) -> bool {
match &self.indices {
Some(indices) => indices.contains(&index),
None => true,
}
}
}