alamb commented on code in PR #10166:
URL: https://github.com/apache/datafusion/pull/10166#discussion_r1575275630
##########
datafusion/optimizer/src/filter_null_join_keys.rs:
##########
@@ -100,11 +105,18 @@ fn create_not_null_predicate(filters: Vec<Expr>) -> Expr {
.into_iter()
.map(|c| Expr::IsNotNull(Box::new(c)))
.collect();
- // combine the IsNotNull expressions with AND
+
+ // directly unwrap since it should always have a value
not_null_exprs
- .iter()
- .skip(1)
- .fold(not_null_exprs[0].clone(), |a, b| and(a, b.clone()))
+ .into_iter()
+ .reduce(|a, b| {
+ Expr::BinaryExpr(BinaryExpr {
+ left: Box::new(a),
+ op: Operator::And,
+ right: Box::new(b),
+ })
+ })
+ .unwrap()
Review Comment:
Nice!
I think you could make this even shorter like
```suggestion
.into_iter()
.reduce(|a, b| a.and(b))
.unwrap()
```
Or even use `conjunction`:
https://docs.rs/datafusion/latest/datafusion/logical_expr/utils/fn.conjunction.html
```suggestion
conjunction(not_null_exprs).unwrap()
```
##########
datafusion/optimizer/src/filter_null_join_keys.rs:
##########
@@ -32,24 +34,34 @@ use std::sync::Arc;
#[derive(Default)]
pub struct FilterNullJoinKeys {}
-impl FilterNullJoinKeys {
- pub const NAME: &'static str = "filter_null_join_keys";
-}
-
impl OptimizerRule for FilterNullJoinKeys {
fn try_optimize(
&self,
- plan: &LogicalPlan,
- config: &dyn OptimizerConfig,
+ _plan: &LogicalPlan,
+ _config: &dyn OptimizerConfig,
) -> Result<Option<LogicalPlan>> {
+ internal_err!("Should have called FilterNullJoinKeys::rewrite")
+ }
+
+ fn supports_rewrite(&self) -> bool {
+ true
+ }
+
+ fn apply_order(&self) -> Option<ApplyOrder> {
+ Some(ApplyOrder::BottomUp)
+ }
+
+ fn rewrite(
+ &self,
+ plan: LogicalPlan,
+ config: &dyn OptimizerConfig,
+ ) -> Result<Transformed<LogicalPlan>> {
if !config.options().optimizer.filter_null_join_keys {
- return Ok(None);
+ return Ok(Transformed::no(plan));
}
match plan {
- LogicalPlan::Join(join) if join.join_type == JoinType::Inner => {
Review Comment:
Removing the `clone()` is beautiful 😍
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]