Skip to content

Commit

Permalink
fix: encoding batch with no columns (#3724)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
wangrunji0408 and viirya authored Feb 17, 2023
1 parent 59016e5 commit ea48b95
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions arrow-flight/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea48b95

Please sign in to comment.