diff --git a/src/common/query/src/native_histogram.rs b/src/common/query/src/native_histogram.rs index d8a559a2dc5..05e391419ae 100644 --- a/src/common/query/src/native_histogram.rs +++ b/src/common/query/src/native_histogram.rs @@ -35,6 +35,7 @@ use datafusion::arrow::datatypes::{ }; use datafusion_common::{DataFusionError, Result as DfResult}; use datatypes::data_type::{ConcreteDataType, DataType}; +pub use datatypes::series::histogram::CounterResetHint; use datatypes::types::{StructField, StructType}; pub use encoding::{NativeHistogramError, encode_native_histogram, native_histogram_column_schema}; use once_cell::sync::Lazy; @@ -141,48 +142,6 @@ pub const CUSTOM_BUCKETS_SCHEMA: i32 = -53; const MIN_EXPONENTIAL_SCHEMA: i32 = -4; const MAX_EXPONENTIAL_SCHEMA: i32 = 8; -/// Information carried by a native histogram about a possible counter reset. -/// -/// The persisted and protobuf representation remains an `i32`. Unrecognized -/// values are retained so data written by a newer producer can still round-trip. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum CounterResetHint { - /// The payload must be inspected to determine whether a reset occurred. - Unknown, - /// This is the first histogram after a counter reset. - CounterReset, - /// No counter reset occurred since the previous histogram. - NotCounterReset, - /// This is a gauge histogram, so counter resets do not apply. - Gauge, - /// A value not understood by this version. - Unrecognized(i32), -} - -impl From for CounterResetHint { - fn from(value: i32) -> Self { - match value { - 0 => Self::Unknown, - 1 => Self::CounterReset, - 2 => Self::NotCounterReset, - 3 => Self::Gauge, - value => Self::Unrecognized(value), - } - } -} - -impl From for i32 { - fn from(value: CounterResetHint) -> Self { - match value { - CounterResetHint::Unknown => 0, - CounterResetHint::CounterReset => 1, - CounterResetHint::NotCounterReset => 2, - CounterResetHint::Gauge => 3, - CounterResetHint::Unrecognized(value) => value, - } - } -} - /// Reset hint indicating that the payload must be inspected. pub const UNKNOWN_COUNTER_RESET_HINT: CounterResetHint = CounterResetHint::Unknown; /// Reset hint indicating the first histogram after a counter reset. @@ -1753,6 +1712,21 @@ mod tests { ); } + #[test] + fn datatypes_reset_hints_round_trip_through_native_histogram() { + use datatypes::series::histogram::CounterResetHint as DatatypesCounterResetHint; + + let values = [-1, 0, 1, 2, 3, 77, i32::MIN, i32::MAX]; + for value in values { + let datatypes_hint = DatatypesCounterResetHint::from(value); + let query_hint: CounterResetHint = datatypes_hint; + let mut histogram = histogram(Vec::new(), Vec::new()); + histogram.reset_hint = query_hint; + let datatypes_hint: DatatypesCounterResetHint = histogram.reset_hint; + assert_eq!(i32::from(datatypes_hint), value); + } + } + #[test] fn arrow_round_trip_preserves_unrecognized_reset_hint() { let mut expected = histogram( diff --git a/src/datatypes/src/series/time.rs b/src/datatypes/src/series/time.rs index 66da94684d7..49b222010da 100644 --- a/src/datatypes/src/series/time.rs +++ b/src/datatypes/src/series/time.rs @@ -165,7 +165,10 @@ impl PartialEq for GridRange { impl Eq for GridRange {} /// A timestamp axis represented as a grid or explicit shared Arrow buffers. -#[derive(Clone, Debug, PartialEq, Eq)] +/// +/// Checked constructors validate timestamp ordering. Public payloads are validated again by the +/// downstream series boundary. +#[derive(Clone, Debug)] pub enum TimeAxis { /// A slice of a shared regular evaluation grid. Grid(GridRange), @@ -186,13 +189,9 @@ impl TimeAxis { /// Validates and stores timestamp chunks without concatenating their buffers. pub fn try_from_chunks(chunks: Vec>) -> Result { - let mut total = 0usize; let mut previous = None; let mut nonempty = Vec::new(); for chunk in chunks { - total = total.checked_add(chunk.len()).context(InvalidSeriesSnafu { - reason: "timestamp length overflow".to_string(), - })?; if chunk.windows(2).any(|pair| pair[0] >= pair[1]) || chunk .first() @@ -207,7 +206,6 @@ impl TimeAxis { nonempty.push(chunk); } } - let _ = total; Ok(Self::ExplicitChunks(nonempty.into())) }