alamb commented on a change in pull request #10063:
URL: https://github.com/apache/arrow/pull/10063#discussion_r614748391
##########
File path: rust/arrow/src/record_batch.rs
##########
@@ -103,6 +103,56 @@ impl RecordBatch {
RecordBatch { schema, columns }
}
+ /// Creates a new [`RecordBatch`] with no columns
+ ///
+ /// TODO add an code example using `append`
+ pub fn new() -> Self {
+ Self {
+ schema: Arc::new(Schema::empty()),
+ columns: Vec::new(),
+ }
+ }
+
+ /// Appends the `field_array` array to this `RecordBatch` as a
+ /// field named `field_name`.
+ ///
+ /// TODO: code example
+ ///
+ /// TODO: on error, can we return `Self` in some meaningful way?
+ pub fn append(self, field_name: &str, field_values: ArrayRef) ->
Result<Self> {
Review comment:
I guess I was thinking we would leave the "do I want to have access to
the `ArrayRef` after the call to `append` up to the caller,
So like
```
// append to existing batch
let mut batch = ...;
// We want to use array_ref later, so pass in a clone
batch = batch.append("ints", Arc::clone(array_ref))?;
```
Which I think is a common pattern in the Rust libraries (that if a function
needs to clone its argument, it takes it by value instead and thus gives the
caller a chance to avoid an extra copy if they don't need the argument again)
But in this case with an `Arc` that is cheap to clone I don't think the
difference really matters from a performance perspective
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]