diff --git a/datafusion/expr/src/function.rs b/datafusion/expr/src/function.rs index 169436145aae..53dfa2c460d0 100644 --- a/datafusion/expr/src/function.rs +++ b/datafusion/expr/src/function.rs @@ -83,6 +83,9 @@ pub struct AccumulatorArgs<'a> { /// The input type of the aggregate function. pub input_type: &'a DataType, + /// If the input type is nullable. + pub input_nullable: bool, + /// The logical expression of arguments the aggregate function takes. pub input_exprs: &'a [Expr], } @@ -98,6 +101,9 @@ pub struct StateFieldsArgs<'a> { /// The input type of the aggregate function. pub input_type: &'a DataType, + /// If the input type is nullable. + pub input_nullable: bool, + /// The return type of the aggregate function. pub return_type: &'a DataType, diff --git a/datafusion/functions-aggregate/src/first_last.rs b/datafusion/functions-aggregate/src/first_last.rs index dd38e3487264..066ab77eadcf 100644 --- a/datafusion/functions-aggregate/src/first_last.rs +++ b/datafusion/functions-aggregate/src/first_last.rs @@ -440,6 +440,7 @@ impl AggregateUDFImpl for LastValue { let StateFieldsArgs { name, input_type, + input_nullable: _, return_type: _, ordering_fields, is_distinct: _, diff --git a/datafusion/physical-expr-common/src/aggregate/mod.rs b/datafusion/physical-expr-common/src/aggregate/mod.rs index 432267e045b2..e82601efa58e 100644 --- a/datafusion/physical-expr-common/src/aggregate/mod.rs +++ b/datafusion/physical-expr-common/src/aggregate/mod.rs @@ -87,6 +87,7 @@ pub fn create_aggregate_expr( ordering_fields, is_distinct, input_type: input_exprs_types[0].clone(), + input_nullable: input_phy_exprs[0].nullable(&schema)?, })) } @@ -248,6 +249,7 @@ pub struct AggregateFunctionExpr { ordering_fields: Vec, is_distinct: bool, input_type: DataType, + input_nullable: bool, } impl AggregateFunctionExpr { @@ -276,6 +278,7 @@ impl AggregateExpr for AggregateFunctionExpr { let args = StateFieldsArgs { name: &self.name, input_type: &self.input_type, + input_nullable: self.input_nullable, return_type: &self.data_type, ordering_fields: &self.ordering_fields, is_distinct: self.is_distinct, @@ -296,6 +299,7 @@ impl AggregateExpr for AggregateFunctionExpr { sort_exprs: &self.sort_exprs, is_distinct: self.is_distinct, input_type: &self.input_type, + input_nullable: self.input_nullable, input_exprs: &self.logical_args, name: &self.name, }; @@ -311,6 +315,7 @@ impl AggregateExpr for AggregateFunctionExpr { sort_exprs: &self.sort_exprs, is_distinct: self.is_distinct, input_type: &self.input_type, + input_nullable: self.input_nullable, input_exprs: &self.logical_args, name: &self.name, }; @@ -381,6 +386,7 @@ impl AggregateExpr for AggregateFunctionExpr { sort_exprs: &self.sort_exprs, is_distinct: self.is_distinct, input_type: &self.input_type, + input_nullable: self.input_nullable, input_exprs: &self.logical_args, name: &self.name, }; @@ -395,6 +401,7 @@ impl AggregateExpr for AggregateFunctionExpr { sort_exprs: &self.sort_exprs, is_distinct: self.is_distinct, input_type: &self.input_type, + input_nullable: self.input_nullable, input_exprs: &self.logical_args, name: &self.name, };