Skip to content

Commit

Permalink
return error when try from failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachelint committed Jan 29, 2025
1 parent e963d50 commit 5fd9d8e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions datafusion/functions-aggregate/src/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ use arrow::array::Array;
use arrow::array::ArrowNativeTypeOp;
use arrow::datatypes::{ArrowNativeType, ArrowPrimitiveType};

use datafusion_common::{internal_err, DataFusionError, HashSet, Result, ScalarValue};
use datafusion_common::{
internal_datafusion_err, internal_err, DataFusionError, HashSet, Result, ScalarValue,
};
use datafusion_expr::function::StateFieldsArgs;
use datafusion_expr::{
function::AccumulatorArgs, utils::format_state_name, Accumulator, AggregateUDFImpl,
Expand Down Expand Up @@ -450,7 +452,11 @@ impl<T: ArrowNumericType + Send> GroupsAccumulator for MedianGroupsAccumulator<T
.with_data_type(self.data_type.clone());

// `offsets` in `ListArray`, each row as a list element
let offset_end = i32::try_from(input_array.len()).unwrap();
let offset_end = i32::try_from(input_array.len()).map_err(|e| {
internal_datafusion_err!(
"cast array_len to i32 failed in convert_to_state of group median, err:{e:?}"
)
})?;
let offsets = (0..=offset_end).collect::<Vec<_>>();
// Safety: all checks in `OffsetBuffer::new` are ensured to pass
let offsets = unsafe { OffsetBuffer::new_unchecked(ScalarBuffer::from(offsets)) };
Expand Down

0 comments on commit 5fd9d8e

Please sign in to comment.