-
Notifications
You must be signed in to change notification settings - Fork 934
Proposal: improve SchemaBuilder for "update fields" usecase #6576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
/// consume the builder and return the final [`Schema`] | ||
/// | ||
/// (synonym for [`Self::finish`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// consume the builder and return the final [`Schema`] | |
/// | |
/// (synonym for [`Self::finish`] | |
/// Consume this [`SchemaBuilder`] yielding the final [`Schema`] | |
/// | |
/// Synonym for [`Self::finish`] |
@@ -45,6 +71,18 @@ impl SchemaBuilder { | |||
} | |||
} | |||
|
|||
/// Clears any fields currently in this builder. | |||
pub fn clear_fields(mut self) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn clear_fields(mut self) -> Self { | |
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?
} | ||
|
||
/// Appends a new field to this [`SchemaBuilder`] and returns self | ||
pub fn with_field(mut self, field: impl Into<FieldRef>) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a with_metadata as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will add
/// let projected_schema = SchemaBuilder::from(&schema) | ||
/// .clear_fields() | ||
/// .with_field(schema.field(1).clone()) | ||
/// .build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// let projected_schema = SchemaBuilder::from(&schema) | |
/// .clear_fields() | |
/// .with_field(schema.field(1).clone()) | |
/// .build(); | |
/// 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree -- will give it a try
FYI @wiedld |
I plan to return to this PR later in this week |
Which issue does this PR close?
Closes #6575
Rationale for this change
See #6575 -- tldr is that it is very easy to forget to copy schema metadata when creating new schemas
What changes are included in this PR?
SchemaBuilder
SchemaBuilder
clear_fields
andwith_field
andbuild
for a more builder like experienceAre there any user-facing changes?
Yes new APIs and docs