Skip to content

Commit 8642e56

Browse files
committed
Make nullable more functional
1 parent 0c9ba15 commit 8642e56

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

datafusion/src/optimizer/simplify_expressions.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,21 @@ impl<'a> Simplifier<'a> {
418418

419419
/// Returns true if expr is nullable
420420
fn nullable(&self, expr: &Expr) -> Result<bool> {
421-
for schema in &self.schemas {
422-
if let Ok(res) = expr.nullable(schema.as_ref()) {
423-
return Ok(res);
424-
}
425-
// expr may be from another input, so keep trying
426-
}
427-
428-
// This means we weren't able to compule `Expr::nullable` with
429-
// any input schemas, signalling a problem
430-
Err(DataFusionError::Internal(format!(
431-
"Could not find find columns in '{}' during simplify",
432-
expr
433-
)))
421+
self.schemas
422+
.iter()
423+
.find_map(|schema| {
424+
// expr may be from another input, so ignore errors
425+
// by converting to None to keep trying
426+
expr.nullable(schema.as_ref()).ok()
427+
})
428+
.ok_or_else(|| {
429+
// This means we weren't able to compute `Expr::nullable` with
430+
// *any* input schemas, signalling a problem
431+
DataFusionError::Internal(format!(
432+
"Could not find find columns in '{}' during simplify",
433+
expr
434+
))
435+
})
434436
}
435437
}
436438

0 commit comments

Comments
 (0)