Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add num_rows when building RecordBatch #103

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/execution/datafusion/shuffle_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ impl PartitionBuffer {

// active -> staging
let active = std::mem::take(&mut self.active);
let num_rows = self.num_active_rows;
self.num_active_rows = 0;
mem_diff -= self.active_slots_mem_size as isize;

let frozen_batch = make_batch(self.schema.clone(), active)?;
let frozen_batch = make_batch(self.schema.clone(), active, num_rows)?;

let frozen_capacity_old = self.frozen.capacity();
let mut cursor = Cursor::new(&mut self.frozen);
Expand Down Expand Up @@ -1148,9 +1149,11 @@ fn make_dict_builder(datatype: &DataType, capacity: usize) -> Box<dyn ArrayBuild
fn make_batch(
schema: SchemaRef,
mut arrays: Vec<Box<dyn ArrayBuilder>>,
row_count: usize,
) -> ArrowResult<RecordBatch> {
let columns = arrays.iter_mut().map(|array| array.finish()).collect();
RecordBatch::try_new(schema, columns)
let options = RecordBatchOptions::new().with_row_count(Option::from(row_count));
RecordBatch::try_new_with_options(schema, columns, &options)
}

/// Checksum algorithms for writing IPC bytes.
Expand Down
9 changes: 5 additions & 4 deletions core/src/execution/shuffle/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use arrow_array::{
StructBuilder, TimestampMicrosecondBuilder,
},
types::Int32Type,
Array, ArrayRef, RecordBatch,
Array, ArrayRef, RecordBatch, RecordBatchOptions,
};
use arrow_schema::{DataType, Field, Schema, TimeUnit};
use jni::sys::{jint, jlong};
Expand Down Expand Up @@ -3347,7 +3347,7 @@ pub fn process_sorted_row_partition(
.zip(schema.iter())
.map(|(builder, datatype)| builder_to_array(builder, datatype, prefer_dictionary_ratio))
.collect();
let batch = make_batch(array_refs?);
let batch = make_batch(array_refs?, n);

let mut frozen: Vec<u8> = vec![];
let mut cursor = Cursor::new(&mut frozen);
Expand Down Expand Up @@ -3420,7 +3420,7 @@ fn builder_to_array(
}
}

fn make_batch(arrays: Vec<ArrayRef>) -> RecordBatch {
fn make_batch(arrays: Vec<ArrayRef>, row_count: usize) -> RecordBatch {
let mut dict_id = 0;
let fields = arrays
.iter()
Expand All @@ -3441,5 +3441,6 @@ fn make_batch(arrays: Vec<ArrayRef>) -> RecordBatch {
})
.collect::<Vec<_>>();
let schema = Arc::new(Schema::new(fields));
RecordBatch::try_new(schema, arrays).unwrap()
let options = RecordBatchOptions::new().with_row_count(Option::from(row_count));
RecordBatch::try_new_with_options(schema, arrays, &options).unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ class CometExecSuite extends CometTestBase {
withParquetDataFrame((0 until 5).map(i => (i, i + 1))) { df =>
assert(df.where("_1 IS NOT NULL").count() == 5)
checkSparkAnswerAndOperator(df)
assert(df.select().limit(2).count() === 2)
}
}

Expand Down