Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions src/metrics/pos_encoded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub type PosField<T> = Option<Option<T>>;
/// 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;
}

Expand Down Expand Up @@ -60,7 +59,6 @@ pub fn f64_to_json(field: &PosField<f64>) -> Option<Value> {
}

/// Get a string field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_string(arr: &SparseArray, pos: usize) -> PosField<String> {
match arr.get(&pos.to_string()) {
None => None, // not-set
Expand All @@ -71,7 +69,6 @@ pub fn sparse_get_string(arr: &SparseArray, pos: usize) -> PosField<String> {
}

/// Get a u32 field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_u32(arr: &SparseArray, pos: usize) -> PosField<u32> {
match arr.get(&pos.to_string()) {
None => None,
Expand All @@ -88,7 +85,6 @@ pub fn sparse_get_u32(arr: &SparseArray, pos: usize) -> PosField<u32> {
}

/// Get a u64 field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_u64(arr: &SparseArray, pos: usize) -> PosField<u64> {
match arr.get(&pos.to_string()) {
None => None,
Expand All @@ -98,17 +94,6 @@ pub fn sparse_get_u64(arr: &SparseArray, pos: usize) -> PosField<u64> {
}
}

/// Get a f64 field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_f64(arr: &SparseArray, pos: usize) -> PosField<f64> {
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<Vec<String>>` to JSON array.
pub fn vec_string_to_json(field: &PosField<Vec<String>>) -> Option<Value> {
match field {
Expand Down Expand Up @@ -143,7 +128,6 @@ pub fn vec_u64_to_json(field: &PosField<Vec<u64>>) -> Option<Value> {
}

/// Get a `Vec<String>` field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_vec_string(arr: &SparseArray, pos: usize) -> PosField<Vec<String>> {
match arr.get(&pos.to_string()) {
None => None,
Expand All @@ -160,7 +144,6 @@ pub fn sparse_get_vec_string(arr: &SparseArray, pos: usize) -> PosField<Vec<Stri
}

/// Get a `Vec<u32>` field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_vec_u32(arr: &SparseArray, pos: usize) -> PosField<Vec<u32>> {
match arr.get(&pos.to_string()) {
None => None,
Expand All @@ -184,20 +167,6 @@ pub fn sparse_get_vec_u32(arr: &SparseArray, pos: usize) -> PosField<Vec<u32>> {
}
}

/// Get a `Vec<u64>` field from a sparse array at a position.
#[allow(dead_code)]
pub fn sparse_get_vec_u64(arr: &SparseArray, pos: usize) -> PosField<Vec<u64>> {
match arr.get(&pos.to_string()) {
None => None,
Some(Value::Null) => Some(None),
Some(Value::Array(arr)) => {
let nums: Vec<u64> = 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<Value>) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
26 changes: 0 additions & 26 deletions src/metrics/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -95,17 +94,6 @@ impl MetricEvent {
attrs,
}
}

/// Create with explicit timestamp (for deserialization/testing).
#[allow(dead_code)]
pub fn with_timestamp<V: EventValues>(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.
Expand Down Expand Up @@ -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);
Expand Down
Loading