This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ccf73ea5 Add support for empty projection in RecordBatch::project 
(#2691)
5ccf73ea5 is described below

commit 5ccf73ea596e25f601aeabc10029254cc18a55e8
Author: DaniĆ«l Heres <[email protected]>
AuthorDate: Fri Sep 9 04:50:22 2022 +0200

    Add support for empty projection in RecordBatch::project (#2691)
    
    * Add support for empty projection in RecordBatch::project
    
    * Simplify
---
 arrow/src/record_batch.rs | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/arrow/src/record_batch.rs b/arrow/src/record_batch.rs
index d1db1f1a4..4b0d36a43 100644
--- a/arrow/src/record_batch.rs
+++ b/arrow/src/record_batch.rs
@@ -212,7 +212,14 @@ impl RecordBatch {
             })
             .collect::<Result<Vec<_>>>()?;
 
-        RecordBatch::try_new(SchemaRef::new(projected_schema), batch_fields)
+        RecordBatch::try_new_with_options(
+            SchemaRef::new(projected_schema),
+            batch_fields,
+            &RecordBatchOptions {
+                match_field_names: true,
+                row_count: Some(self.row_count),
+            },
+        )
     }
 
     /// Returns the number of columns in the record batch.
@@ -865,6 +872,26 @@ mod tests {
         assert_eq!(expected, record_batch.project(&[0, 2]).unwrap());
     }
 
+    #[test]
+    fn project_empty() {
+        let c: ArrayRef = Arc::new(StringArray::from(vec!["d", "e", "f"]));
+
+        let record_batch =
+            RecordBatch::try_from_iter(vec![("c", c.clone())]).expect("valid 
conversion");
+
+        let expected = RecordBatch::try_new_with_options(
+            Arc::new(Schema::empty()),
+            vec![],
+            &RecordBatchOptions {
+                match_field_names: true,
+                row_count: Some(3),
+            },
+        )
+        .expect("valid conversion");
+
+        assert_eq!(expected, record_batch.project(&[]).unwrap());
+    }
+
     #[test]
     fn test_no_column_record_batch() {
         let schema = Arc::new(Schema::new(vec![]));

Reply via email to