pub struct SchemaGraph {
pub schema: Schema,
pub parents: Vec<Vec<TableId>>,
pub children: Vec<Vec<TableId>>,
}Expand description
Schema dependency graph built from foreign key relationships.
The graph represents parent → child relationships where:
- A parent is a table referenced by another table’s FK
- A child is a table that has an FK referencing another table
This ordering allows processing parents before children, ensuring that when sampling/filtering children, parent data is already available.
Fields§
§schema: SchemaThe underlying schema
parents: Vec<Vec<TableId>>For each table, list of parent tables (tables this table references via FK)
children: Vec<Vec<TableId>>For each table, list of child tables (tables that reference this table via FK)
Implementations§
Source§impl SchemaGraph
impl SchemaGraph
Sourcepub fn from_schema(schema: Schema) -> Self
pub fn from_schema(schema: Schema) -> Self
Build a dependency graph from a schema
Sourcepub fn table_name(&self, id: TableId) -> Option<&str>
pub fn table_name(&self, id: TableId) -> Option<&str>
Get the table name for a table ID
Sourcepub fn has_self_reference(&self, id: TableId) -> bool
pub fn has_self_reference(&self, id: TableId) -> bool
Check if a table has a self-referential FK
Sourcepub fn self_referential_tables(&self) -> Vec<TableId>
pub fn self_referential_tables(&self) -> Vec<TableId>
Get tables that have self-referential FKs
Sourcepub fn topo_sort(&self) -> TopoSortResult
pub fn topo_sort(&self) -> TopoSortResult
Perform topological sort using Kahn’s algorithm.
Returns tables in dependency order (parents before children). Tables that are part of cycles are returned separately.
Sourcepub fn processing_order(&self) -> (Vec<TableId>, Vec<TableId>)
pub fn processing_order(&self) -> (Vec<TableId>, Vec<TableId>)
Get processing order for sampling/sharding.
Returns all tables in order: first the topologically sorted acyclic tables, then the cyclic tables (which need special handling).
Sourcepub fn is_ancestor(&self, ancestor: TableId, descendant: TableId) -> bool
pub fn is_ancestor(&self, ancestor: TableId, descendant: TableId) -> bool
Check if table A is an ancestor of table B (A is referenced by B directly or transitively)
Sourcepub fn ancestors(&self, id: TableId) -> Vec<TableId>
pub fn ancestors(&self, id: TableId) -> Vec<TableId>
Get all ancestor tables of a given table (tables it depends on, directly or transitively)
Sourcepub fn descendants(&self, id: TableId) -> Vec<TableId>
pub fn descendants(&self, id: TableId) -> Vec<TableId>
Get all descendant tables of a given table (tables that depend on it)
Sourcepub fn root_tables(&self) -> Vec<TableId>
pub fn root_tables(&self) -> Vec<TableId>
Get root tables (tables with no parents/dependencies)
Sourcepub fn leaf_tables(&self) -> Vec<TableId>
pub fn leaf_tables(&self) -> Vec<TableId>
Get leaf tables (tables with no children/dependents)