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

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


The following commit(s) were added to refs/heads/filter_empty_record_batch by 
this push:
     new e1e1197454 Support `concat_batches` for 0 columns
e1e1197454 is described below

commit e1e119745423cc3065ba664cd3b5adb291507c37
Author: DaniĆ«l Heres <[email protected]>
AuthorDate: Mon Aug 7 22:24:58 2023 +0200

    Support `concat_batches` for 0 columns
---
 arrow-select/src/concat.rs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/arrow-select/src/concat.rs b/arrow-select/src/concat.rs
index 0bf4c97ff8..ac0405a156 100644
--- a/arrow-select/src/concat.rs
+++ b/arrow-select/src/concat.rs
@@ -97,6 +97,13 @@ pub fn concat_batches<'a>(
     schema: &SchemaRef,
     input_batches: impl IntoIterator<Item = &'a RecordBatch>,
 ) -> Result<RecordBatch, ArrowError> {
+    if schema.fields().is_empty() {
+        let num_rows: usize = 
input_batches.into_iter().map(RecordBatch::num_rows).sum();
+        let mut options = RecordBatchOptions::default();
+        options.row_count = Some(num_rows);
+        return RecordBatch::try_new_with_options(schema.clone(), vec![], 
&options);
+    }
+
     let batches: Vec<&RecordBatch> = input_batches.into_iter().collect();
     if batches.is_empty() {
         return Ok(RecordBatch::new_empty(schema.clone()));
@@ -142,6 +149,21 @@ mod tests {
         assert!(re.is_err());
     }
 
+    #[test]
+    fn test_concat_batches_no_columns() {
+        // Test concat using empty schema / batches without columns
+        let schema = Arc::new(Schema::empty());
+
+        let mut options = RecordBatchOptions::default();
+        options.row_count = Some(100);
+        let batch =
+            RecordBatch::try_new_with_options(schema.clone(), vec![], 
&options).unwrap();
+        // put in 2 batches of 100 rows each
+        let re = concat_batches(&schema, &[batch.clone(), batch]).unwrap();
+
+        assert_eq!(re.num_rows(), 200);
+    }
+
     #[test]
     fn test_concat_one_element_vec() {
         let arr = Arc::new(PrimitiveArray::<Int64Type>::from(vec![

Reply via email to