Skip to content

Commit

Permalink
Is constant to run stats compute
Browse files Browse the repository at this point in the history
  • Loading branch information
gatesn committed Nov 27, 2024
1 parent 630835b commit 0cae9bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions vortex-array/src/array/chunked/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ use crate::stats::{ArrayStatistics, Stat, StatisticsVTable, StatsSet};

impl StatisticsVTable<ChunkedArray> for ChunkedEncoding {
fn compute_statistics(&self, array: &ChunkedArray, stat: Stat) -> VortexResult<StatsSet> {
if stat == Stat::IsConstant {
// Short-circuiting implementation of is_constant
return Ok(StatsSet::from_iter([(
Stat::IsConstant,
is_constant(array).into(),
)]));
}

// for UncompressedSizeInBytes, we end up with sum of chunk uncompressed sizes
// this ignores the `chunk_offsets` array child, so it won't exactly match self.nbytes()
Ok(array
Expand All @@ -22,3 +30,7 @@ impl StatisticsVTable<ChunkedArray> for ChunkedEncoding {
.unwrap_or_default())
}
}

fn is_constant(array: &ChunkedArray) -> bool {
array.chunks().all(|c| c.is_constant())
}
2 changes: 1 addition & 1 deletion vortex-array/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl ArrayData {
/// Return whether the array is constant.
pub fn is_constant(&self) -> bool {
self.statistics()
.get_as::<bool>(Stat::IsConstant)
.compute_as::<bool>(Stat::IsConstant)
.unwrap_or(false)
}

Expand Down
1 change: 1 addition & 0 deletions vortex-file/src/read/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl VortexExpr for RowFilter {
.next()
.vortex_expect("must have at least one predicate")
.evaluate(batch)?;

for expr in filter_iter {
if mask.statistics().compute_true_count().unwrap_or_default() == 0 {
return Ok(ConstantArray::new(false, batch.len()).into_array());
Expand Down

0 comments on commit 0cae9bc

Please sign in to comment.