You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ceil and floor panic on a decimal scalar when number_rows is 0 #26950
ceil and floor turn a decimal scalar argument into an array of number_rows rows and then read row 0 of the result. With number_rows = 0 that array is empty, and the read panics:
Trying to access an element at index 0 from a PrimitiveArray of length 0
The comment above the scalar path says decimals are converted "to array of size 1", but the conversion uses args.number_rows:
use std::sync::Arc;use arrow::datatypes::Field;use datafusion_common::ScalarValue;use datafusion_common::config::ConfigOptions;use datafusion_expr::{ColumnarValue,ReturnFieldArgs,ScalarFunctionArgs};use datafusion_functions::math::ceil;let udf = ceil();let arg = ScalarValue::Decimal32(Some(150),9,2);let arg_fields = vec![Arc::new(Field::new("a", arg.data_type(),true))];let return_field = udf
.return_field_from_args(ReturnFieldArgs{arg_fields:&arg_fields,scalar_arguments:&[Some(&arg)],}).unwrap();let result = udf.invoke_with_args(ScalarFunctionArgs{args:vec![ColumnarValue::Scalar(arg)],
arg_fields,number_rows:0,// with 1: Ok(Scalar(Decimal32(2, 8, 0)))
return_field,config_options:Arc::new(ConfigOptions::default()),});// panics: Trying to access an element at index 0 from a PrimitiveArray of length 0
floor panics the same way. With number_rows: 1, ceil returns Decimal32(2, 8, 0) and floor returns Decimal32(1, 8, 0).
Expected behavior
The same scalar as with number_rows: 1, as the comment describes. A scalar result doesn't depend on the number of rows.
Additional context
Found by property-based tests that call each function directly with generated arguments, including scalar arguments with zero rows.
Willingness to contribute
I cannot contribute a fix for this bug at this time
Activity
aruadecarvalho commentedon Oct 30, 2026
take