mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-17 16:24:07 +00:00
fix(datatypes): address series foundation review feedback
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -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<i32> 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<CounterResetHint> 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(
|
||||
|
||||
@@ -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<ScalarBuffer<i64>>) -> Result<Self> {
|
||||
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()))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user