Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/nornir

crates/mimir-driver/tests/fixture-tables/app/src/lib.rs

//! The callers. Each fn is one case of "touching a table"; the line of each
//! site is asserted by tests/tables_dump.rs.

use wh::tables::{TABLE_COVERAGE, TABLE_EVENTS, TABLE_RUNS};
use wh::{Handle, Store, Warehouse};

/// A re-export under another name: the SAME constant.
pub mod names {
    pub use wh::tables::TABLE_RUNS as RUNS_AGAIN;
}

/// A local const defined from another crate's const.
pub const LOCAL_ALIAS: &str = TABLE_EVENTS;

pub fn read_const(wh: &Warehouse) -> usize {
    wh::load_and_read_all(wh, TABLE_RUNS).map(|r| r.len()).unwrap_or(0)
}

pub fn read_reexported(wh: &Warehouse) -> usize {
    wh::load_and_read_all(wh, names::RUNS_AGAIN).map(|r| r.len()).unwrap_or(0)
}

pub fn write_const(wh: &Warehouse, rows: &[String]) -> wh::Result<()> {
    let ident = wh.table_ident(LOCAL_ALIAS);
    let table = iceberg_load(wh, &ident)?;
    wh::append_batch(wh.catalog(), table, rows)
}

fn iceberg_load(wh: &Warehouse, ident: &wh::Ident) -> wh::Result<wh::EngineTable> {
    use wh::CatalogExt;
    wh.catalog().load(ident)
}

pub fn read_and_write(wh: &Warehouse, rows: &[String]) -> wh::Result<usize> {
    let n = wh.scan(TABLE_COVERAGE)?.len();
    wh.append(TABLE_COVERAGE, rows)?;
    Ok(n)
}

pub fn typed_handle(wh: &Warehouse, rows: &[String]) -> wh::Result<()> {
    let mut h = Handle::open(wh, "handle_table")?;
    h.append(wh.catalog(), rows)
}

/// Opens a handle and only asks for metadata: NO read, NO write.
pub fn handle_metadata_only(wh: &Warehouse) -> wh::Result<String> {
    let h = Handle::open(wh, "never_touched")?;
    Ok(h.location())
}

pub fn read_static(wh: &Warehouse) -> usize {
    wh.scan_preview(wh::tables::TABLE_AUDIT, 10).map(|r| r.len()).unwrap_or(0)
}

pub fn read_built(wh: &Warehouse) -> usize {
    wh.scan_preview(wh::tables::TABLE_BUILT, 10).map(|r| r.len()).unwrap_or(0)
}

pub struct Request {
    pub table: String,
    pub tenant: u32,
}

/// A RUNTIME name: a field, and a computed string.
pub fn runtime_names(wh: &Warehouse, req: &Request) -> usize {
    let a = wh.scan_preview(&req.table, 10).map(|r| r.len()).unwrap_or(0);
    let computed = format!("tenant_{}", req.tenant);
    let b = wh::load_and_read_all(wh, &computed).map(|r| r.len()).unwrap_or(0);
    a + b
}

/// A conduit of its own: `table` is the caller's.
pub fn conduit(wh: &Warehouse, table: &str) -> usize {
    wh::load_and_read_all(wh, table).map(|r| r.len()).unwrap_or(0)
}

pub fn through_conduit(wh: &Warehouse) -> usize {
    conduit(wh, "conduit_table")
}

pub fn through_dyn(store: &dyn Store, rows: &[String]) -> wh::Result<usize> {
    store.append("dyn_table", rows)?;
    Ok(store.scan("dyn_table")?.len())
}

pub fn sweep(wh: &Warehouse) -> wh::Result<()> {
    wh.drop_tables(&wh::tables::SWEPT)
}

pub fn loop_over_const_list(wh: &Warehouse) -> usize {
    let mut n = 0;
    for t in wh::tables::SWEPT {
        n += wh.scan_preview(t, 1).map(|r| r.len()).unwrap_or(0);
    }
    n
}

pub fn branch(wh: &Warehouse, first: bool) -> usize {
    let table = if first { TABLE_RUNS } else { TABLE_EVENTS };
    wh.scan_preview(table, 1).map(|r| r.len()).unwrap_or(0)
}

pub fn create(wh: &Warehouse) -> wh::Result<()> {
    wh::create_table_if_missing(wh, "created_table").map(|_| ())
}

pub async fn read_in_async(wh: &Warehouse) -> wh::Result<usize> {
    let rows = wh::read_async(wh, "async_table").await?;
    Ok(rows.len())
}

/// A local helper that PICKS a name: its callers resolve through it.
fn pick(kind: u8) -> &'static str {
    match kind {
        0 => "picked_zero",
        _ => "picked_other",
    }
}

pub fn through_picker(wh: &Warehouse, kind: u8) -> usize {
    wh.scan_preview(pick(kind), 1).map(|r| r.len()).unwrap_or(0)
}

/// Calls an accessor that has its table baked in: the touch is the
/// accessor's, this fn only CALLS it. `wh` is no table handle.
pub fn calls_an_accessor(wh: &Warehouse, rows: &[String]) -> wh::Result<()> {
    wh.append_events(rows)?;
    wh.append_staged(rows)?;
    wh.ensure_layout()
}

/// Through a trait NO impl of which is in sight: the trait's own annotation
/// says which parameter is a table, and how.
pub fn through_annotated_seam(sink: &dyn seam::Sink, rows: &[String]) -> usize {
    sink.push("annotated_table", rows);
    sink.note("not_a_table");
    sink.pull("annotated_table").len() + seam::forward(sink, "forwarded_table")
}

/// An annotation the driver does not understand gives no edge (and is counted).
pub fn calls_misannotated() -> usize {
    seam::misannotated("no_such_access")
}

/// Strings that are NOT tables: no edge.
pub fn not_a_table(wh: &Warehouse) -> usize {
    wh::log_line(TABLE_RUNS) + wh.label("runs").len()
}