diff --git a/encodings/fastlanes/src/bitpacking/compress.rs b/encodings/fastlanes/src/bitpacking/compress.rs index 6ce8efae5a..853610dd69 100644 --- a/encodings/fastlanes/src/bitpacking/compress.rs +++ b/encodings/fastlanes/src/bitpacking/compress.rs @@ -24,7 +24,7 @@ pub fn bitpack_encode(array: PrimitiveArray, bit_width: u8) -> VortexResult().unwrap_or_default() < 0 + array.statistics().compute_min::>().unwrap_or_default().unwrap_or_default() < 0 }); if has_negative_values { vortex_bail!("cannot bitpack_encode array containing negative integers") diff --git a/vortex-array/src/stats/mod.rs b/vortex-array/src/stats/mod.rs index 704caf6274..dc9a11a7a1 100644 --- a/vortex-array/src/stats/mod.rs +++ b/vortex-array/src/stats/mod.rs @@ -164,7 +164,10 @@ pub trait Statistics { /// Clear the value of the statistic fn clear(&self, stat: Stat); - /// Computes the value of the stat if it's not present + /// Computes the value of the stat if it's not present. + /// + /// Returns the scalar if compute succeeded, or `None` if the stat is not supported + /// for this array. fn compute(&self, stat: Stat) -> Option; /// Compute all the requested statistics (if not already present) @@ -244,6 +247,9 @@ impl dyn Statistics + '_ { }) } + /// Get or calculate the provided stat, converting the `Scalar` into a typed value. + /// + /// This function will panic if the conversion fails. pub fn compute_as TryFrom<&'a Scalar, Error = VortexError>>( &self, stat: Stat, @@ -275,10 +281,16 @@ impl dyn Statistics + '_ { }) } + /// Get or calculate the minimum value in the array, returning as a typed value. + /// + /// This function will panic if the conversion fails. pub fn compute_min TryFrom<&'a Scalar, Error = VortexError>>(&self) -> Option { self.compute_as(Stat::Min) } + /// Get or calculate the maximum value in the array, returning as a typed value. + /// + /// This function will panic if the conversion fails. pub fn compute_max TryFrom<&'a Scalar, Error = VortexError>>(&self) -> Option { self.compute_as(Stat::Max) } diff --git a/vortex-sampling-compressor/src/compressors/bitpacked.rs b/vortex-sampling-compressor/src/compressors/bitpacked.rs index 53bafdf80f..94f00e9a90 100644 --- a/vortex-sampling-compressor/src/compressors/bitpacked.rs +++ b/vortex-sampling-compressor/src/compressors/bitpacked.rs @@ -66,7 +66,7 @@ impl EncodingCompressor for BitPackedCompressor { // Only arrays with non-negative values can be bit-packed if !parray.ptype().is_unsigned_int() { let has_negative_elements = match_each_integer_ptype!(parray.ptype(), |$P| { - parray.statistics().compute_min::<$P>().unwrap_or_default() < 0 + parray.statistics().compute_min::>().unwrap_or_default().unwrap_or_default() < 0 }); if has_negative_elements { @@ -94,7 +94,7 @@ impl EncodingCompressor for BitPackedCompressor { // Only arrays with non-negative values can be bit-packed if !parray.ptype().is_unsigned_int() { let has_negative_elements = match_each_integer_ptype!(parray.ptype(), |$P| { - parray.statistics().compute_min::<$P>().unwrap_or_default() < 0 + parray.statistics().compute_min::>().unwrap_or_default().unwrap_or_default() < 0 }); if has_negative_elements {