Skip to content
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

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

tustvold
Copy link
Contributor

@tustvold tustvold commented Mar 26, 2023

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?

Comment on lines 113 to 119
//! 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),
//! }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3954 should simplify this

@alamb alamb self-requested a review March 27, 2023 10:45
Copy link
Contributor

@alamb alamb left a 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.

Comment on lines 83 to 84
//! 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! 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

//! ))
//! ```
//!
//! # Row Conversion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! # 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?

//! use arrow_schema::{DataType, Field};
//! use std::sync::Arc;
//! /// A representation of a row
//! struct Row {
Copy link
Contributor

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

//! use arrow_array::{ArrayRef, RecordBatch, StructArray};
//! use arrow_schema::{DataType, Field};
//! use std::sync::Arc;
//! /// A representation of a row
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! /// A representation of a row
//! /// A representation of a row (defined in code elsewhere)

//! i32_list: ListBuilder<Int32Builder>,
//! }
//!
//! impl<'a> Extend<&'a Row> for RowBuilder {
Copy link
Contributor

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
Copy link
Contributor

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

@tustvold tustvold merged commit 5620612 into apache:master Mar 28, 2023
alamb pushed a commit that referenced this pull request Apr 1, 2023
…ch - (#3951) (#3953)

* Don't discard nulls converting StructArray to RecordBatch (#3951)

* Add more docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants