diff --git a/src/metrics/pos_encoded.rs b/src/metrics/pos_encoded.rs index 93285c7506..e836123a36 100644 --- a/src/metrics/pos_encoded.rs +++ b/src/metrics/pos_encoded.rs @@ -18,7 +18,6 @@ pub type PosField = Option>; /// Trait for types that can be position-encoded. pub trait PosEncoded: Sized + Default { fn to_sparse(&self) -> SparseArray; - #[allow(dead_code)] fn from_sparse(arr: &SparseArray) -> Self; } @@ -60,7 +59,6 @@ pub fn f64_to_json(field: &PosField) -> Option { } /// Get a string field from a sparse array at a position. -#[allow(dead_code)] pub fn sparse_get_string(arr: &SparseArray, pos: usize) -> PosField { match arr.get(&pos.to_string()) { None => None, // not-set @@ -71,7 +69,6 @@ pub fn sparse_get_string(arr: &SparseArray, pos: usize) -> PosField { } /// Get a u32 field from a sparse array at a position. -#[allow(dead_code)] pub fn sparse_get_u32(arr: &SparseArray, pos: usize) -> PosField { match arr.get(&pos.to_string()) { None => None, @@ -88,7 +85,6 @@ pub fn sparse_get_u32(arr: &SparseArray, pos: usize) -> PosField { } /// Get a u64 field from a sparse array at a position. -#[allow(dead_code)] pub fn sparse_get_u64(arr: &SparseArray, pos: usize) -> PosField { match arr.get(&pos.to_string()) { None => None, @@ -98,17 +94,6 @@ pub fn sparse_get_u64(arr: &SparseArray, pos: usize) -> PosField { } } -/// Get a f64 field from a sparse array at a position. -#[allow(dead_code)] -pub fn sparse_get_f64(arr: &SparseArray, pos: usize) -> PosField { - match arr.get(&pos.to_string()) { - None => None, - Some(Value::Null) => Some(None), - Some(Value::Number(n)) => n.as_f64().map(Some), - Some(_) => None, - } -} - /// Convert a `PosField>` to JSON array. pub fn vec_string_to_json(field: &PosField>) -> Option { match field { @@ -143,7 +128,6 @@ pub fn vec_u64_to_json(field: &PosField>) -> Option { } /// Get a `Vec` field from a sparse array at a position. -#[allow(dead_code)] pub fn sparse_get_vec_string(arr: &SparseArray, pos: usize) -> PosField> { match arr.get(&pos.to_string()) { None => None, @@ -160,7 +144,6 @@ pub fn sparse_get_vec_string(arr: &SparseArray, pos: usize) -> PosField` field from a sparse array at a position. -#[allow(dead_code)] pub fn sparse_get_vec_u32(arr: &SparseArray, pos: usize) -> PosField> { match arr.get(&pos.to_string()) { None => None, @@ -184,20 +167,6 @@ pub fn sparse_get_vec_u32(arr: &SparseArray, pos: usize) -> PosField> { } } -/// Get a `Vec` field from a sparse array at a position. -#[allow(dead_code)] -pub fn sparse_get_vec_u64(arr: &SparseArray, pos: usize) -> PosField> { - match arr.get(&pos.to_string()) { - None => None, - Some(Value::Null) => Some(None), - Some(Value::Array(arr)) => { - let nums: Vec = arr.iter().filter_map(|v| v.as_u64()).collect(); - Some(Some(nums)) - } - Some(_) => None, - } -} - /// Set a value in a sparse array at a position. /// If value is Some, inserts; if None, does nothing (not-set). pub fn sparse_set(arr: &mut SparseArray, pos: usize, value: Option) { @@ -561,27 +530,6 @@ mod tests { assert_eq!(sparse_get_vec_u32(&arr, 2), Some(Some(vec![10]))); // filters out too-large value } - #[test] - fn test_sparse_get_vec_u64() { - let mut arr = SparseArray::new(); - assert_eq!(sparse_get_vec_u64(&arr, 0), None); - - arr.insert("0".to_string(), Value::Null); - assert_eq!(sparse_get_vec_u64(&arr, 0), Some(None)); - - arr.insert( - "1".to_string(), - Value::Array(vec![ - Value::Number(1000000000000u64.into()), - Value::Number(2000000000000u64.into()), - ]), - ); - assert_eq!( - sparse_get_vec_u64(&arr, 1), - Some(Some(vec![1000000000000u64, 2000000000000u64])) - ); - } - #[test] fn test_sparse_set() { let mut arr = SparseArray::new(); @@ -632,6 +580,5 @@ mod tests { arr.insert("0".to_string(), Value::String("not an array".to_string())); assert_eq!(sparse_get_vec_string(&arr, 0), None); assert_eq!(sparse_get_vec_u32(&arr, 0), None); - assert_eq!(sparse_get_vec_u64(&arr, 0), None); } } diff --git a/src/metrics/types.rs b/src/metrics/types.rs index 43489a7981..fb4b88e474 100644 --- a/src/metrics/types.rs +++ b/src/metrics/types.rs @@ -31,7 +31,6 @@ pub trait EventValues: Sized { fn into_sparse(self) -> SparseArray { self.to_sparse() } - #[allow(dead_code)] fn from_sparse(arr: &SparseArray) -> Self; } @@ -95,17 +94,6 @@ impl MetricEvent { attrs, } } - - /// Create with explicit timestamp (for deserialization/testing). - #[allow(dead_code)] - pub fn with_timestamp(timestamp: u32, values: &V, attrs: SparseArray) -> Self { - Self { - timestamp, - event_id: V::event_id() as u16, - values: values.to_sparse(), - attrs, - } - } } /// Metrics batch for wire format. @@ -176,20 +164,6 @@ mod tests { ); } - #[test] - fn test_metric_event_with_timestamp() { - use crate::metrics::events::CommittedValues; - - let values = CommittedValues::new().human_additions(50); - let mut attrs = SparseArray::new(); - attrs.insert("0".to_string(), Value::String("1.0.0".to_string())); - - let event = MetricEvent::with_timestamp(1700000000, &values, attrs); - - assert_eq!(event.timestamp, 1700000000); - assert_eq!(event.event_id, 1); - } - #[test] fn test_metric_event_id_values() { assert_eq!(MetricEventId::Committed as u16, 1);