This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 03d0505fc8 Add SchemaBuilder::remove (#4952) (#4964)
03d0505fc8 is described below

commit 03d0505fc864c09e6dcd208d3cdddeecefb90345
Author: Raphael Taylor-Davies <[email protected]>
AuthorDate: Fri Oct 20 18:24:25 2023 +0100

    Add SchemaBuilder::remove (#4952) (#4964)
---
 arrow-schema/src/fields.rs | 17 ++++++++++++++++-
 arrow-schema/src/schema.rs |  9 +++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/arrow-schema/src/fields.rs b/arrow-schema/src/fields.rs
index 07e9abeee5..368ecabbf3 100644
--- a/arrow-schema/src/fields.rs
+++ b/arrow-schema/src/fields.rs
@@ -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>
@@ -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))]
diff --git a/arrow-schema/src/schema.rs b/arrow-schema/src/schema.rs
index 8424ae87d5..43bbffd065 100644
--- a/arrow-schema/src/schema.rs
+++ b/arrow-schema/src/schema.rs
@@ -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`]

Reply via email to