Skip to content

Commit 10ba583

Browse files
committed
feat: check edge references
1 parent 5f4906e commit 10ba583

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/graph.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use polars::frame::row::Row;
22
use regex::Regex;
33
use serde::{Deserialize, Serialize};
4-
use std::collections::HashMap;
4+
use std::collections::{HashMap, HashSet};
5+
use tracing::error;
56

6-
#[derive(Serialize, Deserialize, Clone, Debug)]
7-
#[derive(Default)]
7+
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
88
pub struct Graph {
99
pub nodes: Vec<Node>,
1010
pub edges: Vec<Edge>,
1111
pub layers: Vec<Layer>,
1212
}
1313

14-
1514
impl Graph {
1615
pub fn get_layer_map(&self) -> HashMap<String, Layer> {
1716
self.layers
@@ -114,6 +113,26 @@ impl Graph {
114113
}
115114
serde_json::json!(tree)
116115
}
116+
117+
pub fn verify_graph_integrity(&self) -> Result<(), String> {
118+
// TODO verify that all nodes in edges are present in nodes
119+
// TODO verify graph integrity
120+
//
121+
let node_ids: HashSet<String> = self.nodes.iter().map(|n| n.id.clone()).collect();
122+
123+
for edge in &self.edges {
124+
if !node_ids.contains(&edge.source) {
125+
let err = format!("Edge source {:?} not found in nodes", edge.source);
126+
error!(err);
127+
}
128+
if !node_ids.contains(&edge.target) {
129+
let err = format!("Target source {:?} not found in nodes", edge.target);
130+
error!(err);
131+
}
132+
}
133+
134+
Ok(())
135+
}
117136
}
118137

119138
#[derive(Serialize, Deserialize, Clone, Debug)]

src/plan_execution.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ fn run_plan(plan: Plan, plan_file_path: &std::path::Path) -> Result<()> {
9696
graph.layers.len()
9797
);
9898

99+
match graph.verify_graph_integrity() {
100+
Ok(_) => {
101+
info!("Graph integrity verified");
102+
}
103+
Err(e) => {
104+
error!("Error: {}", e);
105+
// return Err(e.into());
106+
}
107+
}
108+
99109
plan.export.profiles.iter().for_each(|profile| {
100110
info!(
101111
"Exporting file: {} using exporter {:?}",

0 commit comments

Comments
 (0)