Skip to content

Commit

Permalink
Add arrow conversions for Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 13, 2025
1 parent 573b5ba commit 49d5f6d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/datatypes/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,24 @@ impl From<Vec<Field>> for Schema {
}
}
}

#[cfg(feature = "arrow")]
impl From<arrow_schema::Schema> for Schema {
fn from(schema: arrow_schema::Schema) -> Self {
let arrow_schema::Schema { fields, metadata } = schema;
Self {
fields: fields.iter().map(Into::into).collect(),
metadata: metadata.into_iter().collect(),
}
}
}

#[cfg(feature = "arrow")]
impl From<Schema> for arrow_schema::Schema {
fn from(schema: Schema) -> Self {
let Schema { fields, metadata } = schema;
let fields: arrow_schema::Fields =
fields.into_iter().map(arrow_schema::Field::from).collect();
Self::new_with_metadata(fields, metadata.into_iter().collect())
}
}

0 comments on commit 49d5f6d

Please sign in to comment.