Skip to content

Commit

Permalink
Add SchemaBuilder::remove (apache#4952) (apache#4964)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Oct 20, 2023
1 parent f4a2a88 commit 03d0505
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion arrow-schema/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::sync::Arc;
///
/// ```
/// # use std::sync::Arc;
/// # use arrow_schema::{DataType, Field, Fields};
/// # use arrow_schema::{DataType, Field, Fields, SchemaBuilder};
/// // Can be constructed from Vec<Field>
/// Fields::from(vec![Field::new("a", DataType::Boolean, false)]);
/// // Can be constructed from Vec<FieldRef>
Expand All @@ -38,6 +38,21 @@ use std::sync::Arc;
/// std::iter::once(Arc::new(Field::new("a", DataType::Boolean, false))).collect::<Fields>();
/// ```
///
/// See [`SchemaBuilder`] for mutating or updating [`Fields`]
///
/// ```
/// # use arrow_schema::{DataType, Field, SchemaBuilder};
/// let mut builder = SchemaBuilder::new();
/// builder.push(Field::new("a", DataType::Boolean, false));
/// builder.push(Field::new("b", DataType::Boolean, false));
/// let fields = builder.finish().fields;
///
/// let mut builder = SchemaBuilder::from(&fields);
/// builder.remove(0);
/// let new = builder.finish().fields;
/// ```
///
/// [`SchemaBuilder`]: crate::SchemaBuilder
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
Expand Down
9 changes: 9 additions & 0 deletions arrow-schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ impl SchemaBuilder {
self.fields.push(field.into())
}

/// Removes and returns the [`FieldRef`] as index `idx`
///
/// # Panics
///
/// Panics if index out of bounds
pub fn remove(&mut self, idx: usize) -> FieldRef {
self.fields.remove(idx)
}

/// Appends a [`FieldRef`] to this [`SchemaBuilder`] checking for collision
///
/// If an existing field exists with the same name, calls [`Field::try_merge`]
Expand Down

0 comments on commit 03d0505

Please sign in to comment.