Skip to content

Commit

Permalink
populate IPC stats from those constructed on input array
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcasale committed May 7, 2024
1 parent 25f5440 commit 0e5bd21
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 169 deletions.
39 changes: 6 additions & 33 deletions vortex-array/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{Debug, Formatter};

use enum_iterator::all;
use itertools::Itertools;
use log::info;
use log::warn;
use vortex_buffer::Buffer;
use vortex_dtype::{DType, Nullability};
use vortex_error::{vortex_bail, vortex_err, VortexError, VortexResult};
Expand Down Expand Up @@ -208,20 +208,18 @@ impl Statistics for ArrayView<'_> {
/// We want to avoid any sort of allocation on instantiation of the ArrayView, so we
/// do not allocate a stats_set to cache values.
fn set(&self, _stat: Stat, _value: Scalar) {
info!("Cannot write stats to a view")
warn!("Cannot write stats to a view")
}

fn compute(&self, stat: Stat) -> Option<Scalar> {
if let Some(s) = self.get(stat) {
return Some(s);
}

let calculated = self
.to_array()
self.to_array()
.with_dyn(|a| a.compute_statistics(stat))
.ok()?;

calculated.into_iter().for_each(|(k, v)| self.set(k, v));
self.get(stat)
}

Expand Down Expand Up @@ -262,36 +260,11 @@ impl<'v> IntoArray<'v> for ArrayView<'v> {
#[derive(Debug)]
pub struct ViewContext {
encodings: Vec<EncodingRef>,
stats: Vec<Stat>,
}

impl ViewContext {
pub fn new(encodings: Vec<EncodingRef>, stats: Vec<Stat>) -> Self {
Self { encodings, stats }
}

pub fn set_stats(&mut self, to_enable: &[Stat]) {
self.stats.clear();
self.stats.extend(to_enable)
}

pub fn stats(&self) -> &[Stat] {
self.stats.as_ref()
}

pub fn default_stats() -> Vec<Stat> {
vec![
Stat::Max,
Stat::Min,
Stat::IsSorted,
Stat::IsStrictSorted,
Stat::IsConstant,
Stat::BitWidthFreq,
Stat::TrailingZeroFreq,
Stat::NullCount,
Stat::RunCount,
Stat::TrueCount,
]
pub fn new(encodings: Vec<EncodingRef>) -> Self {
Self { encodings }
}

pub fn encodings(&self) -> &[EncodingRef] {
Expand All @@ -318,6 +291,6 @@ impl Default for ViewContext {

impl From<&Context> for ViewContext {
fn from(value: &Context) -> Self {
ViewContext::new(value.encodings().collect_vec(), Self::default_stats())
ViewContext::new(value.encodings().collect_vec())
}
}
Loading

0 comments on commit 0e5bd21

Please sign in to comment.