alamb commented on code in PR #6576:
URL: https://github.com/apache/arrow-rs/pull/6576#discussion_r1803814923
##########
arrow-schema/src/schema.rs:
##########
@@ -25,6 +25,32 @@ use crate::field::Field;
use crate::{FieldRef, Fields};
/// A builder to facilitate building a [`Schema`] from iteratively from
[`FieldRef`]
+///
+/// # Example
+/// Create an entirely new Schema
+/// ```
+/// # use arrow_schema::*;
+/// let schema = Schema::builder()
+/// .with_field(Field::new("c1", DataType::Int64, false))
+/// .with_field(Field::new("c2", DataType::Utf8, false))
+/// .build();
+/// ```
+/// Create a new schema with a subset of fields from an existing schema
+/// ```
+/// # use arrow_schema::*;
+/// let schema = Schema::new(vec![
+/// Field::new("c1", DataType::Int64, false),
+/// Field::new("c2", DataType::Utf8, false),
+/// ]);
+///
+/// // Create a new schema with the same metdata, but only the second field
+/// let projected_schema = SchemaBuilder::from(&schema)
+/// .clear_fields()
+/// .with_field(schema.field(1).clone())
+/// .build();
Review Comment:
I agree -- will give it a try
##########
arrow-schema/src/schema.rs:
##########
@@ -45,6 +71,18 @@ impl SchemaBuilder {
}
}
+ /// Clears any fields currently in this builder.
+ pub fn clear_fields(mut self) -> Self {
+ self.fields.clear();
+ self
+ }
+
+ /// Appends a new field to this [`SchemaBuilder`] and returns self
+ pub fn with_field(mut self, field: impl Into<FieldRef>) -> Self {
Review Comment:
yes, will add
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]