Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Aug 20, 2024
1 parent 3519e75 commit da30827
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
18 changes: 4 additions & 14 deletions datafusion/expr/src/expr_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,10 @@ impl ExprSchemable for Expr {
Expr::ScalarFunction(ScalarFunction { func, args }) => {
Ok(func.is_nullable(args, input_schema))
}
Expr::AggregateFunction(AggregateFunction { func, args, .. }) => {
let nullables = args
.iter()
.map(|e| e.nullable(input_schema))
.collect::<Result<Vec<_>>>()?;
Ok(func.is_nullable(&nullables))
Expr::AggregateFunction(AggregateFunction { func, .. }) => {
Ok(func.is_nullable())
}
Expr::WindowFunction(WindowFunction { fun, args, .. }) => match fun {
Expr::WindowFunction(WindowFunction { fun, .. }) => match fun {
WindowFunctionDefinition::BuiltInWindowFunction(func) => {
if func.name() == "RANK"
|| func.name() == "NTILE"
Expand All @@ -356,13 +352,7 @@ impl ExprSchemable for Expr {
Ok(true)
}
}
WindowFunctionDefinition::AggregateUDF(func) => {
let nullables = args
.iter()
.map(|e| e.nullable(input_schema))
.collect::<Result<Vec<_>>>()?;
Ok(func.is_nullable(&nullables))
}
WindowFunctionDefinition::AggregateUDF(func) => Ok(func.is_nullable()),
WindowFunctionDefinition::WindowUDF(udwf) => Ok(udwf.nullable()),
},
Expr::ScalarVariable(_, _)
Expand Down
6 changes: 3 additions & 3 deletions datafusion/expr/src/udaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ impl AggregateUDF {
self.inner.name()
}

pub fn is_nullable(&self, nullables: &[bool]) -> bool {
self.inner.is_nullable(nullables)
pub fn is_nullable(&self) -> bool {
self.inner.is_nullable()
}

/// Returns the aliases for this function.
Expand Down Expand Up @@ -356,7 +356,7 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
/// Nullable means that that the function could return `null` for any inputs.
/// For example, aggregate functions like `COUNT` always return a non null value
/// but others like `MIN` will return `NULL` if there is nullable input.
fn is_nullable(&self, _nullables: &[bool]) -> bool {
fn is_nullable(&self) -> bool {
true
}

Expand Down
3 changes: 1 addition & 2 deletions datafusion/functions-aggregate/src/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ impl AggregateUDFImpl for Count {
Ok(DataType::Int64)
}

// Count is always nullable regardless of the input nullability
fn is_nullable(&self, _nullables: &[bool]) -> bool {
fn is_nullable(&self) -> bool {
false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,14 @@ impl AggregateExprBuilder {
.map(|arg| arg.data_type(&schema))
.collect::<Result<Vec<_>>>()?;

let input_nullables = args
.iter()
.map(|arg| arg.nullable(&schema))
.collect::<Result<Vec<_>>>()?;

check_arg_count(
fun.name(),
&input_exprs_types,
&fun.signature().type_signature,
)?;

let data_type = fun.return_type(&input_exprs_types)?;
let is_nullable = fun.is_nullable(&input_nullables);
let is_nullable = fun.is_nullable();
let name = match alias {
// TODO: Ideally, we should build the name from physical expressions
None => create_function_physical_name(fun.name(), is_distinct, &[], None)?,
Expand Down

0 comments on commit da30827

Please sign in to comment.