gruuya commented on PR #7188:
URL: https://github.com/apache/arrow-rs/pull/7188#issuecomment-2681061340

   I've found a work-around to reconstruct an empty batch that uses 
`FlightRecordBatchStream` directly
   ```rust
   #[tokio::test]
   async fn test_empty_batch_round_trip() {
       let schema = Schema::new(vec![Field::new("data", DataType::Int32, 
false)]);
       let empty_batch = RecordBatch::new_empty(Arc::new(schema));
       let stream =
           
FlightDataEncoderBuilder::new().build(futures::stream::iter(vec![Ok(empty_batch.clone())]));
   
       let mut stream = FlightRecordBatchStream::new_from_flight_data(stream);
       let mut data: Vec<RecordBatch> = vec![];
       while let Ok(Some(batch)) = stream.try_next().await {
           data.push(batch);
       }
   
       // If no batches were decoded but a schema was, construct an empty batch 
with that schema
       if data.is_empty() && let Some(schema) = stream.schema() {
           data = vec![RecordBatch::new_empty(schema.clone())];
       }
   
       assert_eq!(data, vec![empty_batch]);
   }
   ```
   In this way the stream is not consumed after extracting batches, so I can 
check if a schema was received, and if so construct an empty batch with that 
schema. Closing, thanks!


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to