Skip to content

Commit 4ec0a12

Browse files
committed
Deprecate adjust_output_array in favor of PrimitiveArray::with_data_type
1 parent acc2c7d commit 4ec0a12

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

datafusion/functions-aggregate-common/src/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub fn get_accum_scalar_values_as_arrays(
4848
/// Since `Decimal128Arrays` created from `Vec<NativeType>` have
4949
/// default precision and scale, this function adjusts the output to
5050
/// match `data_type`, if necessary
51+
#[deprecated(since = "44.0.0", note = "use PrimitiveArray::with_datatype")]
5152
pub fn adjust_output_array(data_type: &DataType, array: ArrayRef) -> Result<ArrayRef> {
5253
let array = match data_type {
5354
DataType::Decimal128(p, s) => Arc::new(

datafusion/physical-expr/src/aggregate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ pub(crate) mod stats {
2828
pub use datafusion_functions_aggregate_common::stats::StatsType;
2929
}
3030
pub mod utils {
31+
#[allow(deprecated)] // allow adjust_output_array
3132
pub use datafusion_functions_aggregate_common::utils::{
32-
adjust_output_array, get_accum_scalar_values_as_arrays, get_sort_options,
33+
adjust_output_array,
34+
get_accum_scalar_values_as_arrays, get_sort_options,
3335
ordering_fields, DecimalAverager, Hashable,
3436
};
3537
}

datafusion/physical-plan/src/aggregates/topk/heap.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
use arrow::datatypes::i256;
2121
use arrow_array::cast::AsArray;
2222
use arrow_array::{downcast_primitive, ArrayRef, ArrowPrimitiveType, PrimitiveArray};
23-
use arrow_buffer::{IntervalDayTime, IntervalMonthDayNano};
23+
use arrow_buffer::{IntervalDayTime, IntervalMonthDayNano, ScalarBuffer};
2424
use arrow_schema::DataType;
2525
use datafusion_common::DataFusionError;
2626
use datafusion_common::Result;
27-
use datafusion_physical_expr::aggregate::utils::adjust_output_array;
27+
2828
use half::f16;
2929
use std::cmp::Ordering;
3030
use std::fmt::{Debug, Display, Formatter};
@@ -151,10 +151,11 @@ where
151151
}
152152

153153
fn drain(&mut self) -> (ArrayRef, Vec<usize>) {
154+
let nulls = None;
154155
let (vals, map_idxs) = self.heap.drain();
155-
let vals = Arc::new(PrimitiveArray::<VAL>::from_iter_values(vals));
156-
let vals = adjust_output_array(&self.data_type, vals).expect("Type is incorrect");
157-
(vals, map_idxs)
156+
let arr = PrimitiveArray::<VAL>::new(ScalarBuffer::from(vals), nulls)
157+
.with_data_type(self.data_type.clone());
158+
(Arc::new(arr), map_idxs)
158159
}
159160
}
160161

0 commit comments

Comments
 (0)