Skip to main content

csv_diff

Function csv_diff 

Source
pub fn csv_diff(
    left: &CsvTable,
    right: &CsvTable,
    key_col: &str,
) -> Result<CsvDiff, Error>
Expand description

Compute the diff between two CSV tables keyed by key_col.

Rows are matched by the value of key_col. For each key:

  • If it exists only in left โ†’ removed.
  • If it exists only in right โ†’ added.
  • If it exists in both but the rows differ โ†’ changed.

Both tables must have the same headers.

ยงExample

use oxiphysics_io::csv::{CsvTable, csv_diff};

let a = CsvTable::from_str("id,v\n1,10\n2,20\n3,30\n", ',').unwrap();
let b = CsvTable::from_str("id,v\n1,10\n2,99\n4,40\n", ',').unwrap();
let diff = csv_diff(&a, &b, "id").unwrap();
assert_eq!(diff.removed.len(), 1); // id=3
assert_eq!(diff.added.len(), 1);   // id=4
assert_eq!(diff.changed.len(), 1); // id=2 changed v