Skip to content

Commit ac407a1

Browse files
committed
Use get_slice_memory_size() instead of get_array_memory_size() for measuring array_agg accumulator size
1 parent d4d5bfd commit ac407a1

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

datafusion/functions-aggregate/src/array_agg.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ use std::mem::{size_of, size_of_val};
2323
use std::sync::Arc;
2424

2525
use arrow::array::{
26-
make_array, new_empty_array, Array, ArrayRef, AsArray, BooleanArray, ListArray,
27-
StructArray,
26+
new_empty_array, Array, ArrayRef, AsArray, BooleanArray, ListArray, StructArray,
2827
};
2928
use arrow::compute::{filter, SortOptions};
3029
use arrow::datatypes::{DataType, Field, FieldRef, Fields};
3130

3231
use datafusion_common::cast::as_list_array;
33-
use datafusion_common::scalar::copy_array_data;
3432
use datafusion_common::utils::{get_row_at_idx, SingleRowListArrayBuilder};
3533
use datafusion_common::{exec_err, internal_err, Result, ScalarValue};
3634
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
@@ -315,11 +313,7 @@ impl Accumulator for ArrayAggAccumulator {
315313
};
316314

317315
if !val.is_empty() {
318-
// The ArrayRef might be holding a reference to its original input buffer, so
319-
// storing it here directly copied/compacted avoids over accounting memory
320-
// not used here.
321-
self.values
322-
.push(make_array(copy_array_data(&val.to_data())));
316+
self.values.push(val)
323317
}
324318

325319
Ok(())
@@ -378,7 +372,7 @@ impl Accumulator for ArrayAggAccumulator {
378372
+ self
379373
.values
380374
.iter()
381-
.map(|arr| arr.get_array_memory_size())
375+
.map(|arr| arr.to_data().get_slice_memory_size().unwrap_or_default())
382376
.sum::<usize>()
383377
+ self.datatype.size()
384378
- size_of_val(&self.datatype)
@@ -1008,8 +1002,7 @@ mod tests {
10081002
acc2.update_batch(&[data(["b", "c", "a"])])?;
10091003
acc1 = merge(acc1, acc2)?;
10101004

1011-
// without compaction, the size is 2652.
1012-
assert_eq!(acc1.size(), 732);
1005+
assert_eq!(acc1.size(), 266);
10131006

10141007
Ok(())
10151008
}

0 commit comments

Comments
 (0)