1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use polars_utils::IdxSize;

use super::{Metadata, MetadataFlags};
use crate::chunked_array::{IntoScalar, PolarsDataType, Scalar};

pub trait MetadataTrait {
    fn get_flags(&self) -> MetadataFlags;
    fn min_value(&self) -> Option<Scalar>;
    fn max_value(&self) -> Option<Scalar>;

    /// Number of unique non-null values
    fn distinct_count(&self) -> Option<IdxSize>;
}

impl<T: PolarsDataType> MetadataTrait for Metadata<T>
where
    T::OwnedPhysical: IntoScalar + Clone,
{
    fn get_flags(&self) -> MetadataFlags {
        self.get_flags()
    }

    fn min_value(&self) -> Option<Scalar> {
        self.get_min_value()
            .map(|v| v.clone().into_scalar(T::get_dtype()).unwrap())
    }

    fn max_value(&self) -> Option<Scalar> {
        self.get_max_value()
            .map(|v| v.clone().into_scalar(T::get_dtype()).unwrap())
    }

    fn distinct_count(&self) -> Option<IdxSize> {
        self.get_distinct_count()
    }
}