-
Notifications
You must be signed in to change notification settings - Fork 867
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
Improve array builder documentation (#3949) #3951
Conversation
arrow-array/src/builder/mod.rs
Outdated
//! match &row.i32_list { | ||
//! Some(list) => { | ||
//! list.iter().for_each(|v| self.i32_list.values().append_option(*v)); | ||
//! self.i32_list.append(true); | ||
//! } | ||
//! None => self.i32_list.append(false), | ||
//! } |
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.
#3954 should simplify this
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.
LGTM -- I left some suggestions I think would improve the example but this is also much better than currently exists so I think it could be merged as is.
arrow-array/src/builder/mod.rs
Outdated
//! It is common to have a statically defined row representation, and to want to convert | ||
//! this to an arrow representation. An example of this can be seen below |
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.
//! It is common to have a statically defined row representation, and to want to convert | |
//! this to an arrow representation. An example of this can be seen below | |
//! It is common to have a collection of objects that you want to | |
//! convert to Arrow arrays. An example of doing so is below |
arrow-array/src/builder/mod.rs
Outdated
//! )) | ||
//! ``` | ||
//! | ||
//! # Row Conversion |
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.
//! # Row Conversion | |
//! # Converting other objects to Arrow Arrays |
I was confused at first about the term "Row" as it is over loaded. What do you think about talking about "objects" instead?
arrow-array/src/builder/mod.rs
Outdated
//! use arrow_schema::{DataType, Field}; | ||
//! use std::sync::Arc; | ||
//! /// A representation of a row | ||
//! struct Row { |
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.
Maybe it could be called "MyRow" to emphasize it is defined in user code
arrow-array/src/builder/mod.rs
Outdated
//! use arrow_array::{ArrayRef, RecordBatch, StructArray}; | ||
//! use arrow_schema::{DataType, Field}; | ||
//! use std::sync::Arc; | ||
//! /// A representation of a row |
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.
//! /// A representation of a row | |
//! /// A representation of a row (defined in code elsewhere) |
arrow-array/src/builder/mod.rs
Outdated
//! i32_list: ListBuilder<Int32Builder>, | ||
//! } | ||
//! | ||
//! impl<'a> Extend<&'a Row> for RowBuilder { |
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 know "extend" is probably more idomatic, but I think it obscures the key use of the builders
I suggest refactoring just the "append one row" code into its own function for clarity
impl RowBuilder {
pub fn append_row(&mut self, row: &Row) {
...
}
}
//! } | ||
//! | ||
//! impl RowBuilder { | ||
//! /// Note: returns StructArray to allow nesting within another array if desired |
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.
Maybe it is also worth mentioning (or adding a function that does so) that it could return a 4 column RecordBatch as well
Which issue does this PR close?
Part of #3949
Rationale for this change
It isn't immediately clear how to use the builders to construct arrays,
I want to improve the ergonomics of building arrays using the builders, but first it is important to document the current state of play
What changes are included in this PR?
Are there any user-facing changes?