crates/kleene-iceberg/src/lib.rs
//! Iceberg tables read as they are, as a kleene set: kleene is an in-memory sink of Knut's
//! bifröst.
//!
//! No ETL: the tables are read where they lie, nothing is written anywhere, nothing is
//! re-partitioned or copied into another format first. The mapping is bifröst's own
//! ([`knut_bifrost::MappingSpec`], RON or YAML): per table a pipeline of `vertex` steps (a
//! node label, its id column, its properties) and `edge` / `fk_edges` steps (an edge label,
//! the columns of its two ends, its properties). bifröst's Iceberg source reads each table's
//! data files, its transforms turn the rows into a graph mutation, and kleene's sink
//! ([`GraphRows`]) keeps them and fills kleene-plan's catalog, so Datalog and GQL run on it
//! unchanged.
//!
//! | Part | Here |
//! |---|---|
//! | Mapping | [`knut_bifrost::MappingSpec`] (`MappingSpec::from_ron`, `load_ron`, `from_yaml`); `custom` steps are refused (kleene registers no transform) |
//! | Where the tables are | [`knut_bifrost::delivery::IcebergLake`]: an embedded skade warehouse; with feature `s3` tables on S3 by their root, with `rest` behind an Iceberg REST catalog |
//! | A version | [`IcebergSet::snapshot`]: each table at its current snapshot, or at a snapshot id given ([`Version`]); only metadata is read to find them ([`IcebergSet::version`]) |
//! | Kept | what a table gave at a snapshot is kept per (table, snapshot id): asked again, no data file is read ([`IcebergSet::files_read`]); [`IcebergSet::keep_in`] keeps it on disk too, in kleene-index's `Store`, keyed by the snapshot id |
//! | The next version | [`IcebergSet::advance`]: from an earlier [`Snapshot`], only what each table's window changed is read (bifröst's changelog read: the data files added, and the rows equality deletes, position deletes, deletion vectors and rewrites removed, in commit order); each edge label's graph is the old one with the new edges added and the pairs no row holds now taken out ([`kleene_sparse::Csr::with_changes`]); the added rows and the lost facts come as catalogs of their own ([`Delta::added`], [`Delta::removed`], for `Engine::continue_with`); a window whose removed rows the mapping cannot name reads its table whole ([`Delta::reread`]) |
//! | A snapshot with removals in its history | read as the history up to it with the removals applied in order; a window skade cannot read as rows, as the table's live rows at the snapshot (bifröst's `IcebergSource::read_at`) |
//! | Node label `L` | the ids of `L`'s rows (an integer column, each id at least 0, one id space for every label) |
//! | Edge label `E` | the (from, to) pairs of `E`'s rows as a graph (by source and by destination), the nodes numbered by their ids |
//! | Property `L.k`, `E.k` | a column, read by its type as kleene-gar reads a set's columns ([`kleene_gar::column_type`]) |
//! | Writing (tests and benches only) | [`write::append`]: batches into a table of an embedded warehouse, a snapshot each |
//!
//! knut-bifrost is taken from Knut's branch `arrow60` by rev, built source-only (no FalkorDB,
//! redis or graphar code linked).
mod error;
mod set;
mod sink;
pub mod write;
pub use error::{Error, Result};
pub use set::{Delta, IcebergSet, Snapshot, Version};
pub use sink::GraphRows;
pub use knut_bifrost::MappingSpec;
pub use knut_bifrost::delivery::IcebergLake;
/// The mapping in the file at `path`: RON for a `.ron` file, YAML otherwise
/// ([`MappingSpec::load_ron`], [`MappingSpec::load`]).
pub fn load_mapping(path: impl AsRef<std::path::Path>) -> Result<MappingSpec> {
let path = path.as_ref();
Ok(if path.extension().is_some_and(|e| e == "ron") {
MappingSpec::load_ron(path)?
} else {
MappingSpec::load(path)?
})
}