Skip to content

Commit

Permalink
Deprecate adjust_output_array in favor of PrimitiveArray::with_data_t…
Browse files Browse the repository at this point in the history
…ype (#13585)
  • Loading branch information
alamb authored Nov 28, 2024
1 parent 91670e2 commit 9c6c1e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
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)
.with_data_type(self.data_type.clone());
(Arc::new(arr), map_idxs)
}
}

Expand Down

0 comments on commit 9c6c1e1

Please sign in to comment.