akar_function/graph.rs
1//! Graph data source abstraction for table functions that need graph access.
2//!
3//! `akar-function` cannot depend on `akar-graph` (the dependency graph runs
4//! `akar-graph -> akar-storage -> akar-vector -> akar-function`), so graph
5//! algorithms and table-function closures receive graph data through this
6//! trait instead. The query processor (which owns the storage `TableCatalog`)
7//! builds a concrete `GraphDataSource` from the catalog's node/rel tables.
8
9/// A directed or undirected edge in the database graph.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct GraphEdge {
12 /// Offset of the source node within its node table.
13 pub src_offset: u64,
14 /// Offset of the destination node within its node table.
15 pub dst_offset: u64,
16 /// Row index of the edge within its relationship table.
17 pub rel_id: u64,
18 /// ID of the relationship table that owns this edge.
19 pub rel_table_id: u64,
20}
21
22/// Provides the node/edge topology backing the graph for GDS table functions.
23///
24/// Implementors snapshot the graph at call time. Edges whose source or
25/// destination is `u64::MAX` (soft-deleted rows) are excluded.
26pub trait GraphDataSource {
27 /// Total number of nodes in the graph (at least `max_offset + 1`).
28 fn num_nodes(&self) -> usize;
29
30 /// All live edges of the graph.
31 fn edges(&self) -> Vec<GraphEdge>;
32}