nevi-me commented on a change in pull request #10063:
URL: https://github.com/apache/arrow/pull/10063#discussion_r614422348
##########
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:
Given that `ArrayRef` is backed by an `Arc`, how about taking it by
reference then cloning it?
Am I correct that if this errors, the underlying `ArrayRef` could get
dropped if it's not a clone in itself?
Something like:
```rust
let array = Int32Array::from(vec![1, 2, 3]);
let array_ref = Arc::new(array);
// append to existing batch
let mut batch = ...;
// assume that this fails, does array_ref get dropped as we no longer have
references to it?
batch = batch.append("ints", array_ref)?;
```
##########
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 {
Review comment:
I think it's worthwhile to maintain the property that a recordbatch is
ummutable. So, this feels a bit out of place for me.
How about we create a builder that takes an iterator of `(&str, ArrayRef)`
instead?
The below is what I mean by out of place
```rust
let mut batch = read_batch_from_somewhere()?;
batch = batch.append("field", array_ref)?;
```
There might be a benefit in having the above, so I'm open to convincing :)
This could partially address your question on the TODO about returning
`Self` on error
--
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]