Struct Statistics

Source
pub struct Statistics {
    pub num_rows: Precision<usize>,
    pub total_byte_size: Precision<usize>,
    pub column_statistics: Vec<ColumnStatistics>,
}
Expand description

Statistics for a relation Fields are optional and can be inexact because the sources sometimes provide approximate estimates for performance reasons and the transformations output are not always predictable.

Fields§

§num_rows: Precision<usize>

The number of table rows.

§total_byte_size: Precision<usize>

Total bytes of the table rows.

§column_statistics: Vec<ColumnStatistics>

Statistics on a column level.

It must contains a ColumnStatistics for each field in the schema of the table to which the Statistics refer.

Implementations§

Source§

impl Statistics

Source

pub fn new_unknown(schema: &Schema) -> Self

Returns a Statistics instance for the given schema by assigning unknown statistics to each column in the schema.

Source

pub fn unknown_column(schema: &Schema) -> Vec<ColumnStatistics>

Returns an unbounded ColumnStatistics for each field in the schema.

Source

pub fn with_num_rows(self, num_rows: Precision<usize>) -> Self

Set the number of rows

Source

pub fn with_total_byte_size(self, total_byte_size: Precision<usize>) -> Self

Set the total size, in bytes

Source

pub fn add_column_statistics(self, column_stats: ColumnStatistics) -> Self

Add a column to the column statistics

Source

pub fn to_inexact(self) -> Self

If the exactness of a Statistics instance is lost, this function relaxes the exactness of all information by converting them Precision::Inexact.

Source

pub fn project(self, projection: Option<&Vec<usize>>) -> Self

Project the statistics to the given column indices.

For example, if we had statistics for columns {"a", "b", "c"}, projecting to vec![2, 1] would return statistics for columns {"c", "b"}.

Source

pub fn with_fetch( self, schema: SchemaRef, fetch: Option<usize>, skip: usize, n_partitions: usize, ) -> Result<Self>

Calculates the statistics after applying fetch and skip operations.

Here, self denotes per-partition statistics. Use the n_partitions parameter to compute global statistics in a multi-partition setting.

Source

pub fn try_merge_iter<'a, I>(items: I, schema: &Schema) -> Result<Statistics>
where I: IntoIterator<Item = &'a Statistics>,

Summarize zero or more statistics into a single Statistics instance.

The method assumes that all statistics are for the same schema. If not, maybe you can call SchemaMapper::map_column_statistics to make them consistent.

Returns an error if the statistics do not match the specified schemas.

Source

pub fn try_merge(self, other: &Statistics) -> Result<Self>

Merge this Statistics value with another Statistics value.

Returns an error if the statistics do not match (different schemas).

§Example
let stats1 = Statistics::default()
  .with_num_rows(Precision::Exact(1))
  .with_total_byte_size(Precision::Exact(2))
  .add_column_statistics(ColumnStatistics::new_unknown()
     .with_null_count(Precision::Exact(3))
     .with_min_value(Precision::Exact(ScalarValue::from(4)))
     .with_max_value(Precision::Exact(ScalarValue::from(5)))
  );

let stats2 = Statistics::default()
  .with_num_rows(Precision::Exact(10))
  .with_total_byte_size(Precision::Inexact(20))
  .add_column_statistics(ColumnStatistics::new_unknown()
      // absent null count
     .with_min_value(Precision::Exact(ScalarValue::from(40)))
     .with_max_value(Precision::Exact(ScalarValue::from(50)))
  );

let merged_stats = stats1.try_merge(&stats2).unwrap();
let expected_stats = Statistics::default()
  .with_num_rows(Precision::Exact(11))
  .with_total_byte_size(Precision::Inexact(22)) // inexact in stats2 --> inexact
  .add_column_statistics(
    ColumnStatistics::new_unknown()
      .with_null_count(Precision::Absent) // missing from stats2 --> absent
      .with_min_value(Precision::Exact(ScalarValue::from(4)))
      .with_max_value(Precision::Exact(ScalarValue::from(50)))
  );

assert_eq!(merged_stats, expected_stats)

Trait Implementations§

Source§

impl Clone for Statistics

Source§

fn clone(&self) -> Statistics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Statistics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Statistics

Source§

fn default() -> Self

Returns a new Statistics instance with all fields set to unknown and no columns.

Source§

impl Display for Statistics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Statistics

Source§

fn eq(&self, other: &Statistics) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Statistics

Source§

impl StructuralPartialEq for Statistics

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Ungil for T
where T: Send,