Skip to content
Open
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
7 changes: 4 additions & 3 deletions datafusion/expr/src/test/function_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
use arrow::datatypes::{
DECIMAL32_MAX_PRECISION, DECIMAL32_MAX_SCALE, DECIMAL64_MAX_PRECISION,
DECIMAL64_MAX_SCALE, DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE,
DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE, DataType, FieldRef,
DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE, DataType, Field, FieldRef,
};
use std::sync::Arc;

use datafusion_common::plan_err;
use datafusion_common::{Result, exec_err, not_impl_err, utils::take_function_args};
Expand Down Expand Up @@ -252,8 +253,8 @@ impl AggregateUDFImpl for Count {
Ok(DataType::Int64)
}

fn is_nullable(&self) -> bool {
false
fn return_field(&self, _arg_fields: &[FieldRef]) -> Result<FieldRef> {
Ok(Arc::new(Field::new(self.name(), DataType::Int64, false)))
}

fn state_fields(&self, _args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
Expand Down
5 changes: 5 additions & 0 deletions datafusion/expr/src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ impl AggregateUDF {
self.inner.window_function_display_name(params)
}

#[deprecated(since = "56.0.0", note = "Use `AggregateUDF::return_field` instead.")]
pub fn is_nullable(&self) -> bool {
#[expect(deprecated)]
self.inner.is_nullable()
}

Expand Down Expand Up @@ -570,6 +572,7 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync + Any {
/// For example, aggregate functions like `COUNT` always return a non null value
/// but others like `MIN` will return `NULL` if there is nullable input.
/// Note that if the function is declared as *not* nullable, make sure the [`AggregateUDFImpl::default_value`] is `non-null`
#[deprecated(since = "56.0.0", note = "Use `return_field` instead.")]
fn is_nullable(&self) -> bool {
true
}
Expand Down Expand Up @@ -1514,6 +1517,7 @@ pub fn udaf_default_return_field<F: AggregateUDFImpl + ?Sized>(
Ok(Arc::new(Field::new(
func.name(),
data_type,
#[expect(deprecated)]
func.is_nullable(),
)))
}
Expand Down Expand Up @@ -1678,6 +1682,7 @@ impl AggregateUDFImpl for AliasedAggregateUDFImpl {
}

fn is_nullable(&self) -> bool {
#[expect(deprecated)]
self.inner.is_nullable()
}

Expand Down
1 change: 1 addition & 0 deletions datafusion/ffi/src/udaf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl From<Arc<AggregateUDF>> for FFI_AggregateUDF {

let name = udaf.name().into();
let aliases = udaf.aliases().iter().map(|a| a.to_owned().into()).collect();
#[expect(deprecated)]
let is_nullable = udaf.is_nullable();
let volatility = udaf.signature().volatility.into();

Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-aggregate/src/approx_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ impl AggregateUDFImpl for ApproxDistinct {
Ok(ScalarValue::UInt64(Some(0)))
}

fn is_nullable(&self) -> bool {
false
fn return_field(&self, _arg_fields: &[FieldRef]) -> Result<FieldRef> {
Ok(Arc::new(Field::new(self.name(), DataType::UInt64, false)))
}

fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
Expand Down
4 changes: 2 additions & 2 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ impl AggregateUDFImpl for Count {
Ok(DataType::Int64)
}

fn is_nullable(&self) -> bool {
false
fn return_field(&self, _arg_fields: &[FieldRef]) -> Result<FieldRef> {
Ok(Arc::new(Field::new(self.name(), DataType::Int64, false)))
}

fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<FieldRef>> {
Expand Down
10 changes: 8 additions & 2 deletions datafusion/functions-aggregate/src/regr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,14 @@ impl AggregateUDFImpl for Regr {
}
}

fn is_nullable(&self) -> bool {
self.regr_type != RegrType::Count
fn return_field(&self, arg_fields: &[FieldRef]) -> Result<FieldRef> {
let arg_types: Vec<_> =
arg_fields.iter().map(|f| f.data_type()).cloned().collect();
Ok(Arc::new(Field::new(
self.name(),
self.return_type(&arg_types)?,
self.regr_type != RegrType::Count,
)))
}

fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl AggregateExprBuilder {
if let Some(output_metadata) = output_metadata {
return_field = output_metadata.add_to_field_ref(return_field);
}
let is_nullable = fun.is_nullable();
let is_nullable = return_field.is_nullable();
let Some(name) = alias else {
return internal_err!(
"AggregateExprBuilder::alias must be provided prior to calling build"
Expand Down
22 changes: 22 additions & 0 deletions docs/source/library-user-guide/upgrading/56.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -1342,3 +1342,25 @@ without declaring one, use `FileScanConfigBuilder::with_preserve_order(true)`.
Code that reads `FileScanConfig::preserve_order` to decide whether files may be
reordered should call `FileScanConfig::preserves_file_order()` instead, which
also accounts for the output ordering.

### `AggregateUDFImpl::is_nullable` is deprecated

`AggregateUDFImpl::is_nullable` is deprecated; set the nullability in the field
returned by `AggregateUDFImpl::return_field` instead. The compiler does not
warn about existing overrides.

**Migration guide:**

```rust,ignore
// Before
fn is_nullable(&self) -> bool {
false
}

// After
fn return_field(&self, _arg_fields: &[FieldRef]) -> Result<FieldRef> {
Ok(Arc::new(Field::new(self.name(), DataType::Int64, false)))
}
```

See [issue #18882](https://github.com/apache/datafusion/issues/18882) for details.
Loading