Skip to content

Commit a470f37

Browse files
author
B Vadlamani
committed
fix_tests
1 parent 31f2afc commit a470f37

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • datafusion/physical-plan/src/joins/hash_join

datafusion/physical-plan/src/joins/hash_join/stream.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use crate::{
4949
use arrow::array::{Array, ArrayRef, BooleanArray, Int32Array, UInt32Array, UInt64Array};
5050
use arrow::compute::filter_record_batch;
5151
use arrow::datatypes::{Schema, SchemaRef};
52-
use arrow::record_batch::RecordBatch;
52+
use arrow::record_batch::{RecordBatch, RecordBatchOptions};
5353
use arrow_schema::DataType;
5454
use datafusion_common::{
5555
JoinSide, JoinType, NullEquality, Result, internal_datafusion_err, internal_err,
@@ -751,7 +751,19 @@ impl HashJoinStream {
751751
return internal_err!("unsupported data type for roaring bitmap");
752752
}
753753
};
754-
let batch = filter_record_batch(&state.batch, &mask)?;
754+
let filtered_batch = filter_record_batch(&state.batch, &mask)?;
755+
// Apply column projection to match output schema
756+
let columns: Vec<ArrayRef> = self
757+
.column_indices
758+
.iter()
759+
.map(|col_idx| {
760+
// For RightSemi/RightAnti, all columns are from the right (probe) side
761+
Arc::clone(filtered_batch.column(col_idx.index))
762+
})
763+
.collect();
764+
// Use try_new_with_options to handle empty columns case (e.g., count(*))
765+
let options = RecordBatchOptions::new().with_row_count(Some(filtered_batch.num_rows()));
766+
let batch = RecordBatch::try_new_with_options(Arc::clone(&self.schema), columns, &options)?;
755767
self.output_buffer.push_batch(batch)?;
756768
self.state = HashJoinStreamState::FetchProbeBatch;
757769
return Ok(StatefulStreamResult::Continue);

0 commit comments

Comments
 (0)