Skip to content

Commit 471f730

Browse files
committed
Ensure the row count is preserved when coalescing over empty records
1 parent 4d22076 commit 471f730

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

datafusion/core/src/physical_plan/coalesce_batches.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::execution::context::TaskContext;
3333
use arrow::compute::kernels::concat::concat;
3434
use arrow::datatypes::SchemaRef;
3535
use arrow::error::Result as ArrowResult;
36-
use arrow::record_batch::RecordBatch;
36+
use arrow::record_batch::{RecordBatch, RecordBatchOptions};
3737
use futures::stream::{Stream, StreamExt};
3838
use log::trace;
3939

@@ -291,7 +291,11 @@ pub fn concat_batches(
291291
batches.len(),
292292
row_count
293293
);
294-
RecordBatch::try_new(schema.clone(), arrays)
294+
295+
let mut options = RecordBatchOptions::default();
296+
options.row_count = Some(row_count);
297+
298+
RecordBatch::try_new_with_options(schema.clone(), arrays, &options)
295299
}
296300

297301
#[cfg(test)]

datafusion/core/tests/sql/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,13 @@ async fn execute_to_batches(ctx: &SessionContext, sql: &str) -> Vec<RecordBatch>
766766
let logical_schema = plan.schema();
767767

768768
let msg = format!("Optimizing logical plan for '{}': {:?}", sql, plan);
769-
let plan = ctx
769+
let optimized_logical_plan = ctx
770770
.optimize(&plan)
771771
.map_err(|e| format!("{:?} at {}", e, msg))
772772
.unwrap();
773-
let optimized_logical_schema = plan.schema();
773+
let optimized_logical_schema = optimized_logical_plan.schema();
774774

775-
let msg = format!("Creating physical plan for '{}': {:?}", sql, plan);
775+
let msg = format!("Creating physical plan for '{}': {:?}", sql, optimized_logical_plan);
776776
let plan = ctx
777777
.create_physical_plan(&plan)
778778
.await

0 commit comments

Comments
 (0)