Convert the summaries into a `RecordBatch` for display Results in a table like: ```text +-----------+----------+-----------+-----------+-----------+-----------+-----------+ | Operation | Metric | min | max | avg | sum | count | +-----------+----------+-----------+-----------+-----------+-----------+-----------+ | Get | duration | 5.000000s | 5.000000s | 5.00000
(&self)
| 594 | /// +-----------+----------+-----------+-----------+-----------+-----------+-----------+ |
| 595 | /// ``` |
| 596 | pub fn to_batch(&self) -> RecordBatch { |
| 597 | let operations: StringArray = self |
| 598 | .iter() |
| 599 | .flat_map(|s| std::iter::repeat_n(Some(s.operation.to_string()), 2)) |
| 600 | .collect(); |
| 601 | let metrics: StringArray = self |
| 602 | .iter() |
| 603 | .flat_map(|_s| [Some("duration"), Some("size")]) |
| 604 | .collect(); |
| 605 | let mins: StringArray = self |
| 606 | .stats_iter() |
| 607 | .flat_map(|(duration_stats, size_stats)| { |
| 608 | let dur_min = |
| 609 | duration_stats.map(|d| format!("{:.6}s", d.min.as_secs_f32())); |
| 610 | let size_min = size_stats.map(|s| format!("{} B", s.min)); |
| 611 | [dur_min, size_min] |
| 612 | }) |
| 613 | .collect(); |
| 614 | let maxs: StringArray = self |
| 615 | .stats_iter() |
| 616 | .flat_map(|(duration_stats, size_stats)| { |
| 617 | let dur_max = |
| 618 | duration_stats.map(|d| format!("{:.6}s", d.max.as_secs_f32())); |
| 619 | let size_max = size_stats.map(|s| format!("{} B", s.max)); |
| 620 | [dur_max, size_max] |
| 621 | }) |
| 622 | .collect(); |
| 623 | let avgs: StringArray = self |
| 624 | .iter() |
| 625 | .flat_map(|s| { |
| 626 | let count = s.count as f32; |
| 627 | let duration_stats = s.duration_stats.as_ref(); |
| 628 | let size_stats = s.size_stats.as_ref(); |
| 629 | let dur_avg = duration_stats.map(|d| { |
| 630 | let avg = d.sum.as_secs_f32() / count; |
| 631 | format!("{avg:.6}s") |
| 632 | }); |
| 633 | let size_avg = size_stats.map(|s| { |
| 634 | let avg = s.sum as f32 / count; |
| 635 | format!("{avg} B") |
| 636 | }); |
| 637 | [dur_avg, size_avg] |
| 638 | }) |
| 639 | .collect(); |
| 640 | let sums: StringArray = self |
| 641 | .stats_iter() |
| 642 | .flat_map(|(duration_stats, size_stats)| { |
| 643 | // Omit a sum stat for duration in the initial |
| 644 | // implementation because it can be a bit misleading (at least |
| 645 | // at first glance). For example, particularly large queries the |
| 646 | // sum of the durations was often larger than the total time of |
| 647 | // the query itself, can be confusing without additional |
| 648 | // explanation (e.g. that the sum is of individual requests, |
| 649 | // which may be concurrent). |
| 650 | let dur_sum = |
| 651 | duration_stats.map(|d| format!("{:.6}s", d.sum.as_secs_f32())); |
| 652 | let size_sum = size_stats.map(|s| format!("{} B", s.sum)); |
| 653 | [dur_sum, size_sum] |