Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkMyCar committed Jun 21, 2024
1 parent 1e3fb8f commit 852cf34
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
15 changes: 10 additions & 5 deletions src/persist-types/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ impl ColumnarStats {
pub fn downcast<T: Data>(&self) -> Option<T::Stats> {
T::Stats::downcast(self)
}

/// Returns the inner [`ColumnStatKinds`] if `nulls` is [`None`].
pub fn non_null_values(&self) -> Option<&ColumnStatKinds> {
match self.nulls {
None => Some(&self.values),
Some(_) => None,
}
}
}

impl DynStats for ColumnarStats {
Expand Down Expand Up @@ -255,7 +263,7 @@ pub trait ColumnStats<T: Data>: DynStats {
/// [`ColumnarStats`] contains `Self`.
///
/// Note: This method is intended to help bridge the gap between [`Data`]
/// and [`crate::Schema2`].
/// and [`crate::columnar::Schema2`].
fn downcast(stats: &ColumnarStats) -> Option<Self>
where
Self: Sized;
Expand Down Expand Up @@ -398,10 +406,7 @@ impl<T: Data> ColumnStats<T> for NoneStats {
where
Self: Sized,
{
if stats.nulls.is_some() {
return None;
}
match &stats.values {
match stats.non_null_values()? {
ColumnStatKinds::None => Some(NoneStats),
_ => None,
}
Expand Down
5 changes: 1 addition & 4 deletions src/persist-types/src/stats/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ impl ColumnStats<Vec<u8>> for BytesStats {
where
Self: Sized,
{
if stats.nulls.is_some() {
return None;
}
match &stats.values {
match stats.non_null_values()? {
ColumnStatKinds::Bytes(bytes) => Some(bytes.clone()),
_ => None,
}
Expand Down
5 changes: 1 addition & 4 deletions src/persist-types/src/stats/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ macro_rules! stats_primitive {
where
Self: Sized,
{
if stats.nulls.is_some() {
return None;
}
match &stats.values {
match stats.non_null_values()? {
ColumnStatKinds::Primitive(PrimitiveStatsVariants::$variant(prim)) => {
Some(prim.clone())
}
Expand Down
5 changes: 1 addition & 4 deletions src/persist-types/src/stats/structured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ impl ColumnStats<DynStruct> for StructStats {
where
Self: Sized,
{
if stats.nulls.is_some() {
return None;
}
match &stats.values {
match stats.non_null_values()? {
ColumnStatKinds::Struct(inner) => Some(inner.clone()),
_ => None,
}
Expand Down

0 comments on commit 852cf34

Please sign in to comment.