Skip to content

Commit

Permalink
stats: standardize UNDERFLOW and OVERFLOW messages for sum, sum_len…
Browse files Browse the repository at this point in the history
…gth & avg_length
  • Loading branch information
jqnatividad committed Sep 8, 2024
1 parent c9e239d commit 38c6128
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ pub static STATSDATA_TYPES_ARRAY: [JsonTypes; MAX_STAT_COLUMNS] = [
static INFER_DATE_FLAGS: OnceLock<Vec<bool>> = OnceLock::new();
static RECORD_COUNT: OnceLock<u64> = 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;
Expand Down Expand Up @@ -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()]);
Expand Down Expand Up @@ -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()))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ stats_tests!(
"1",
"2"
],
"OVERFLOW"
"*OVERFLOW*"
);
stats_tests!(
stats_sum_negative_overflow,
Expand All @@ -475,7 +475,7 @@ stats_tests!(
"-1",
"-2"
],
"UNDERFLOW"
"*UNDERFLOW*"
);

stats_tests!(stats_min, "min", &["2", "1.1"], "1.1");
Expand Down

0 comments on commit 38c6128

Please sign in to comment.