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

viirya 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 ea48b9571 fix: encoding batch with no columns (#3724)
ea48b9571 is described below

commit ea48b9571f88bfbced60f9790ae2a7102502870e
Author: Runji Wang <[email protected]>
AuthorDate: Fri Feb 17 14:09:14 2023 +0800

    fix: encoding batch with no columns (#3724)
    
    * fix encoding batch with no column
    
    Signed-off-by: Runji Wang <[email protected]>
    
    * Update arrow-flight/src/encode.rs
    
    Co-authored-by: Liang-Chi Hsieh <[email protected]>
    
    * Update arrow-flight/src/encode.rs
    
    Co-authored-by: Liang-Chi Hsieh <[email protected]>
    
    ---------
    
    Signed-off-by: Runji Wang <[email protected]>
    Co-authored-by: Liang-Chi Hsieh <[email protected]>
---
 arrow-flight/src/encode.rs | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/arrow-flight/src/encode.rs b/arrow-flight/src/encode.rs
index 2f06ee58f..2e93acb09 100644
--- a/arrow-flight/src/encode.rs
+++ b/arrow-flight/src/encode.rs
@@ -18,7 +18,7 @@
 use std::{collections::VecDeque, fmt::Debug, pin::Pin, sync::Arc, task::Poll};
 
 use crate::{error::Result, FlightData, SchemaAsIpc};
-use arrow_array::{ArrayRef, RecordBatch};
+use arrow_array::{ArrayRef, RecordBatch, RecordBatchOptions};
 use arrow_ipc::writer::{DictionaryTracker, IpcDataGenerator, IpcWriteOptions};
 use arrow_schema::{DataType, Field, Schema, SchemaRef};
 use bytes::Bytes;
@@ -422,8 +422,11 @@ fn prepare_batch_for_flight(
         .iter()
         .map(hydrate_dictionary)
         .collect::<Result<Vec<_>>>()?;
+    let options = 
RecordBatchOptions::new().with_row_count(Some(batch.num_rows()));
 
-    Ok(RecordBatch::try_new(schema, columns)?)
+    Ok(RecordBatch::try_new_with_options(
+        schema, columns, &options,
+    )?)
 }
 
 /// Hydrates a dictionary to its underlying type
@@ -499,6 +502,18 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_encode_no_column_batch() {
+        let batch = RecordBatch::try_new_with_options(
+            Arc::new(Schema::empty()),
+            vec![],
+            &RecordBatchOptions::new().with_row_count(Some(10)),
+        )
+        .expect("cannot create record batch");
+
+        prepare_batch_for_flight(&batch, batch.schema()).expect("failed to 
optimize");
+    }
+
     pub fn make_flight_data(
         batch: &RecordBatch,
         options: &IpcWriteOptions,

Reply via email to