From 38c61285704e5064a63c9dbb1ac866f18fa130fd Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sun, 8 Sep 2024 08:40:10 -0400 Subject: [PATCH] `stats`: standardize UNDERFLOW and OVERFLOW messages for sum, sum_length & avg_length --- src/cmd/stats.rs | 12 +++++++++--- tests/test_stats.rs | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cmd/stats.rs b/src/cmd/stats.rs index 29a5f9256..a8275e89a 100644 --- a/src/cmd/stats.rs +++ b/src/cmd/stats.rs @@ -470,6 +470,9 @@ pub static STATSDATA_TYPES_ARRAY: [JsonTypes; MAX_STAT_COLUMNS] = [ static INFER_DATE_FLAGS: OnceLock> = OnceLock::new(); static RECORD_COUNT: OnceLock = OnceLock::new(); +pub const OVERFLOW_STRING: &str = "*OVERFLOW*"; +pub const UNDERFLOW_STRING: &str = "*UNDERFLOW*"; + // number of milliseconds per day const MS_IN_DAY: f64 = 86_400_000.0; const MS_IN_DAY_INT: i64 = 86_400_000; @@ -1559,7 +1562,10 @@ impl Stats { 4, )); } else { - pieces.extend_from_slice(&[empty(), empty()]); + pieces.extend_from_slice(&[ + OVERFLOW_STRING.to_string(), + OVERFLOW_STRING.to_string(), + ]); } } else { pieces.extend_from_slice(&[empty(), empty()]); @@ -1961,8 +1967,8 @@ impl TypedSum { match self.integer { // with saturating_add, if this is equal to i64::MAX or i64::MIN // we overflowed/underflowed - i64::MAX => Some((self.stotlen, "OVERFLOW".to_string())), - i64::MIN => Some((self.stotlen, "UNDERFLOW".to_string())), + i64::MAX => Some((self.stotlen, OVERFLOW_STRING.to_string())), + i64::MIN => Some((self.stotlen, UNDERFLOW_STRING.to_string())), _ => { let mut buffer = itoa::Buffer::new(); Some((self.stotlen, buffer.format(self.integer).to_owned())) diff --git a/tests/test_stats.rs b/tests/test_stats.rs index 6790152ab..f5d7fa129 100644 --- a/tests/test_stats.rs +++ b/tests/test_stats.rs @@ -462,7 +462,7 @@ stats_tests!( "1", "2" ], - "OVERFLOW" + "*OVERFLOW*" ); stats_tests!( stats_sum_negative_overflow, @@ -475,7 +475,7 @@ stats_tests!( "-1", "-2" ], - "UNDERFLOW" + "*UNDERFLOW*" ); stats_tests!(stats_min, "min", &["2", "1.1"], "1.1");