Skip to main content

csv_join

Function csv_join 

Source
pub fn csv_join(
    left: &CsvTable,
    right: &CsvTable,
    key: &str,
) -> Result<CsvTable, Error>
Expand description

Perform an inner join of left and right on the named key column.

The key column must exist in both tables. Duplicate key values in right are matched to every occurrence in left (standard SQL inner join semantics). Columns from the right table (except the key) are appended to the result.

ยงExample

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

let left  = CsvTable::from_str("id,x\n1,10\n2,20\n3,30\n", ',').unwrap();
let right = CsvTable::from_str("id,y\n1,100\n3,300\n", ',').unwrap();
let joined = csv_join(&left, &right, "id").unwrap();
assert_eq!(joined.row_count(), 2);
let x_col = joined.column_f64("x").unwrap();
assert!((x_col[0] - 10.0).abs() < 1e-10);
assert!((x_col[1] - 30.0).abs() < 1e-10);