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

Deprecate adjust_output_array in favor of PrimitiveArray::with_data_type #13585

Merged
merged 1 commit into from
Nov 28, 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
1 change: 1 addition & 0 deletions datafusion/functions-aggregate-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn get_accum_scalar_values_as_arrays(
/// Since `Decimal128Arrays` created from `Vec<NativeType>` have
/// default precision and scale, this function adjusts the output to
/// match `data_type`, if necessary
#[deprecated(since = "44.0.0", note = "use PrimitiveArray::with_datatype")]
pub fn adjust_output_array(data_type: &DataType, array: ArrayRef) -> Result<ArrayRef> {
let array = match data_type {
DataType::Decimal128(p, s) => Arc::new(
Expand Down
1 change: 1 addition & 0 deletions datafusion/physical-expr/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) mod stats {
pub use datafusion_functions_aggregate_common::stats::StatsType;
}
pub mod utils {
#[allow(deprecated)] // allow adjust_output_array
pub use datafusion_functions_aggregate_common::utils::{
adjust_output_array, get_accum_scalar_values_as_arrays, get_sort_options,
ordering_fields, DecimalAverager, Hashable,
Expand Down
11 changes: 6 additions & 5 deletions datafusion/physical-plan/src/aggregates/topk/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
use arrow::datatypes::i256;
use arrow_array::cast::AsArray;
use arrow_array::{downcast_primitive, ArrayRef, ArrowPrimitiveType, PrimitiveArray};
use arrow_buffer::{IntervalDayTime, IntervalMonthDayNano};
use arrow_buffer::{IntervalDayTime, IntervalMonthDayNano, ScalarBuffer};
use arrow_schema::DataType;
use datafusion_common::DataFusionError;
use datafusion_common::Result;
use datafusion_physical_expr::aggregate::utils::adjust_output_array;

use half::f16;
use std::cmp::Ordering;
use std::fmt::{Debug, Display, Formatter};
Expand Down Expand Up @@ -151,10 +151,11 @@ where
}

fn drain(&mut self) -> (ArrayRef, Vec<usize>) {
let nulls = None;
let (vals, map_idxs) = self.heap.drain();
let vals = Arc::new(PrimitiveArray::<VAL>::from_iter_values(vals));
let vals = adjust_output_array(&self.data_type, vals).expect("Type is incorrect");
(vals, map_idxs)
let arr = PrimitiveArray::<VAL>::new(ScalarBuffer::from(vals), nulls)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will also be slightly faster as the ScalarBuffer::from avoids copying the values into the Vec: https://docs.rs/arrow/latest/arrow/buffer/struct.ScalarBuffer.html#impl-From%3CVec%3CT%3E%3E-for-ScalarBuffer%3CT%3E

.with_data_type(self.data_type.clone());
(Arc::new(arr), map_idxs)
}
}

Expand Down