Skip to main content

diff

Function diff 

Source
pub fn diff(old: &Schema, new: &Schema) -> SchemaDiff
Expand description

What changed between two Arrow schemas: fields added and removed, type changes, fields that became (or stopped being) nullable, and metadata, with breaking changes marked.

use arrow_schema::{DataType, Field, Schema};

let old = Schema::new(vec![Field::new("id", DataType::Int32, true)]);
let new = Schema::new(vec![
    Field::new("id", DataType::Int64, false),
    Field::new("name", DataType::Utf8, true),
]);
let diff = rich_data::arrow::diff(&old, &new);
let lines: Vec<String> = diff
    .changes()
    .iter()
    .map(|c| format!("{} {} {}{}", c.kind.marker(), c.path, c.detail, if c.breaking { " !" } else { "" }))
    .collect();
assert_eq!(
    lines,
    ["~ id became required !", "~ id type Int32 → Int64 !", "+ name field added (Utf8)"]
);