crates/kleene-ballista/tests/rounds.rs
//! The split mode's round rows: a step's sends cross as one row per target part, its nodes
//! once each (combined at the sender with the query's add) and compact.
use arrow_schema::DataType;
use kleene_ballista::exec::{PART, ROUTE, SENDS, round_entries, routes_of, rows_of};
use kleene_graph::Sends;
#[test]
fn a_round_sends_one_compact_row_per_part_with_each_node_once() {
// Border edges to few nodes: node v of part p reached many times.
let mut sends: Sends<u32> = Sends::new();
for k in 0..6000u32 {
sends.push(k % 3, (k * 7) % 50, 1000 - k % 997);
}
let routes = routes_of(&[0, 1, 2], 3).unwrap();
let want = sends.clone().combine(|a, b| a.min(b), None);
let rows = rows_of(sends, &routes, |a, b| a.min(b), None).unwrap();
let schema = rows.schema();
let names: Vec<&str> = schema.fields().iter().map(|f| f.name().as_str()).collect();
assert_eq!(names, vec![ROUTE, PART, SENDS]);
assert_eq!(schema.field(2).data_type(), &DataType::Binary);
assert_eq!(rows.num_rows(), 3, "one row per target part");
for p in 0..3u32 {
let row = rows.slice(p as usize, 1);
let got = round_entries(&row, p).unwrap();
let want: Vec<(u32, u64)> = want
.for_part(p)
.into_iter()
.map(|(n, v)| (n, u64::from(v)))
.collect();
assert_eq!(got, want, "part {p}");
// A row for another part is refused: the routing is off.
assert!(round_entries(&row, (p + 1) % 3).is_err());
}
// Nothing sent: no row.
let none = rows_of(Sends::<u8>::new(), &routes, |a, b| a | b, None).unwrap();
assert_eq!(none.num_rows(), 0);
}