martin-g commented on code in PR #18734:
URL: https://github.com/apache/datafusion/pull/18734#discussion_r2531959859
##########
datafusion/execution/src/memory_pool/mod.rs:
##########
@@ -503,6 +503,56 @@ pub fn human_readable_size(size: usize) -> String {
format!("{value:.1} {unit}")
}
+/// Present count in human-readable form with K, M, B, T suffixes
+pub fn human_readable_count(count: usize) -> String {
+ let count = count as u64;
+ let (value, unit) = {
+ if count >= 1_000_000_000_000 {
+ (count as f64 / 1_000_000_000_000.0, " T")
+ } else if count >= 1_000_000_000 {
+ (count as f64 / 1_000_000_000.0, " B")
+ } else if count >= 1_000_000 {
+ (count as f64 / 1_000_000.0, " M")
+ } else if count >= 1_000 {
+ (count as f64 / 1_000.0, " K")
+ } else {
+ return count.to_string();
+ }
+ };
+
+ // Format with appropriate precision
+ // For values >= 100, show 1 decimal place (e.g., 123.4 K)
+ // For values < 100, show 2 decimal places (e.g., 10.12 K)
+ if value >= 100.0 {
Review Comment:
You need to round it first to make it consistent (i.e. `99999` -> `100.0 K`):
```suggestion
let rounded = (value * 100.0).round() / 100.0;
if rounded >= 100.0 {
```
##########
datafusion/execution/src/memory_pool/mod.rs:
##########
@@ -599,4 +649,57 @@ mod tests {
assert_eq!(r2.size(), 25);
assert_eq!(pool.reserved(), 28);
}
+
+ #[test]
+ fn test_human_readable_count() {
+ // Test small numbers (< 1000) - should display as-is
+ assert_eq!(human_readable_count(0), "0");
+ assert_eq!(human_readable_count(1), "1");
+ assert_eq!(human_readable_count(999), "999");
+
+ // Test thousands (K)
+ assert_eq!(human_readable_count(1_000), "1.00 K");
+ assert_eq!(human_readable_count(10_100), "10.10 K");
+ assert_eq!(human_readable_count(1_532), "1.53 K");
+ assert_eq!(human_readable_count(99_999), "100.00 K");
Review Comment:
Shouldn't this be displayed as `100.0 K` ? With one decimal place ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]