tustvold commented on code in PR #6576:
URL: https://github.com/apache/arrow-rs/pull/6576#discussion_r1803797876
##########
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:
Should there be a with_metadata as well?
##########
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 {
Review Comment:
```suggestion
pub fn clear(mut self) -> Self {
```
I can see the desire to distinguish this from metadata, but given the other
fields aren't `push_field`, etc... Maybe this is more consistent?
##########
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:
```suggestion
/// let projected_schema = SchemaBuilder::from(schema.metadata())
/// .with_field(schema.field(1).clone())
/// .build();
```
I wonder if we could make this work, it might be a bit cleaner?
##########
arrow-schema/src/schema.rs:
##########
@@ -120,6 +158,13 @@ impl SchemaBuilder {
metadata: self.metadata,
}
}
+
+ /// consume the builder and return the final [`Schema`]
+ ///
+ /// (synonym for [`Self::finish`]
Review Comment:
```suggestion
/// Consume this [`SchemaBuilder`] yielding the final [`Schema`]
///
/// Synonym for [`Self::finish`]
```
--
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]